Class: RbNaCl::GroupElements::Curve25519
- Inherits:
-
Object
- Object
- RbNaCl::GroupElements::Curve25519
- Extended by:
- Sodium
- Includes:
- KeyComparator, Serializable
- Defined in:
- lib/rbnacl/group_elements/curve25519.rb
Overview
Points provide the interface to NaCl's Curve25519 high-speed elliptic curve cryptography, which can be used for implementing Diffie-Hellman and other forms of public key cryptography (e.g. RbNaCl::Box)
Objects of the Point class represent points on Edwards curves. NaCl defines a base point (the "standard group element") which we can multiply by an arbitrary integer. This is how NaCl computes public keys from private keys.
Constant Summary collapse
- STANDARD_GROUP_ELEMENT =
NaCl's Curve25519 base point (a.k.a. standard group element), serialized as hex
["0900000000000000000000000000000000000000000000000000000000000000"].pack("H*").freeze
- STANDARD_GROUP_ORDER =
Order of the standard group
2**252 + 27742317777372353535851937790883648493
- SCALARBYTES =
Number of bytes in a scalar on this curve
32
- BYTES =
32
Class Method Summary collapse
-
.base ⇒ RbNaCl::Point
NaCl's standard base point for all Curve25519 public keys.
- .base_point ⇒ Object
Instance Method Summary collapse
-
#initialize(point) ⇒ RbNaCl::Point
constructor
Creates a new Point from the given serialization.
-
#mult(integer) ⇒ RbNaCl::Point
Multiply the given integer by this point This ordering is a bit confusing because traditionally the point would be the right-hand operand.
-
#to_bytes ⇒ String
Return the point serialized as bytes.
Methods included from Sodium
primitive, sodium_constant, sodium_function, sodium_primitive, sodium_type
Methods included from Serializable
Methods included from KeyComparator
Constructor Details
#initialize(point) ⇒ RbNaCl::Point
Creates a new Point from the given serialization
42 43 44 45 46 47 48 |
# File 'lib/rbnacl/group_elements/curve25519.rb', line 42 def initialize(point) @point = point.to_str # FIXME: really should have a separate constant here for group element size # Group elements and scalars are both 32-bits, but that's for convenience Util.check_length(@point, SCALARBYTES, "group element") end |
Class Method Details
.base ⇒ RbNaCl::Point
NaCl's standard base point for all Curve25519 public keys
77 |
# File 'lib/rbnacl/group_elements/curve25519.rb', line 77 def self.base; @base_point; end |
.base_point ⇒ Object
78 |
# File 'lib/rbnacl/group_elements/curve25519.rb', line 78 def self.base_point; @base_point; end |
Instance Method Details
#mult(integer) ⇒ RbNaCl::Point
Multiply the given integer by this point This ordering is a bit confusing because traditionally the point would be the right-hand operand.
57 58 59 60 61 62 63 64 65 |
# File 'lib/rbnacl/group_elements/curve25519.rb', line 57 def mult(integer) integer = integer.to_str Util.check_length(integer, SCALARBYTES, "integer") result = Util.zeros(SCALARBYTES) self.class.scalarmult_curve25519(result, integer, @point) self.class.new(result) end |
#to_bytes ⇒ String
Return the point serialized as bytes
70 |
# File 'lib/rbnacl/group_elements/curve25519.rb', line 70 def to_bytes; @point; end |