class RbNaCl::GroupElements::Curve25519
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.
Constants
- BYTES
- DEGENERATE_KEY
Degenerate key (all-zeroes, results in an all-zero shared secret)
- SCALARBYTES
Number of bytes in a scalar on this curve
- STANDARD_GROUP_ELEMENT
NaCl's
Curve25519
base point (a.k.a. standard group element), serialized as hex- STANDARD_GROUP_ORDER
Order of the standard group
Attributes
Public Class Methods
NaCl's standard base point for all Curve25519
public keys
@return [RbNaCl::Point] standard base point (a.k.a. standard group element)
# File lib/rbnacl/group_elements/curve25519.rb, line 86 def self.base # TODO: better support fixed-based scalar multiplication (this glosses over native support) @base_point end
Creates a new Point from the given serialization
@param [String] point location of a group element (32-bytes)
@return [RbNaCl::Point] the Point at this location
# File lib/rbnacl/group_elements/curve25519.rb, line 47 def initialize(point) @point = point.to_str raise CryptoError, "degenerate key detected" if @point == DEGENERATE_KEY # 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
Public Instance Methods
Multiply the given integer by this point This ordering is a bit confusing because traditionally the point would be the right-hand operand.
@param [String] integer value to multiply with this Point (32-bytes)
@return [RbNaCl::Point] result as a Point object
# File lib/rbnacl/group_elements/curve25519.rb, line 64 def mult(integer) integer = integer.to_str Util.check_length(integer, SCALARBYTES, "integer") result = Util.zeros(SCALARBYTES) raise CryptoError, "degenerate key detected" unless self.class.scalarmult_curve25519(result, integer, @point) self.class.new(result) end
Return the point serialized as bytes
@return [String] 32-byte string representing this point
# File lib/rbnacl/group_elements/curve25519.rb, line 77 def to_bytes @point end