Class: X25519::MontgomeryU
- Inherits:
-
Object
- Object
- X25519::MontgomeryU
- Defined in:
- lib/x25519/montgomery_u.rb
Overview
X25519 public keys and shared secrets
Montgomery-u coordinates of points on the elliptic curve used by X25519 (a.k.a. Curve25519)
Instance Method Summary collapse
-
#initialize(bytes) ⇒ MontgomeryU
constructor
Create an object representing a Montgomery-u coordinate from a bytestring.
-
#inspect ⇒ Object
Show hex representation of serialized coordinate in string inspection.
-
#to_bytes ⇒ String
Return a compressed Montgomery-u coordinate serialized as a bytestring.
Constructor Details
#initialize(bytes) ⇒ MontgomeryU
Create an object representing a Montgomery-u coordinate from a bytestring
12 13 14 15 16 17 18 19 20 |
# File 'lib/x25519/montgomery_u.rb', line 12 def initialize(bytes) X25519.validate_key_bytes(bytes) # The point located at a Montgomery-u coordinate of zero always returns # the point at zero regardless of which scalar it's multiplied with raise InvalidKeyError, "degenerate public key" if bytes == ("\0" * KEY_SIZE) @bytes = bytes end |
Instance Method Details
#inspect ⇒ Object
Show hex representation of serialized coordinate in string inspection
30 31 32 |
# File 'lib/x25519/montgomery_u.rb', line 30 def inspect "#<#{self.class}:#{@bytes.unpack1('H*')}>" end |
#to_bytes ⇒ String
Return a compressed Montgomery-u coordinate serialized as a bytestring
25 26 27 |
# File 'lib/x25519/montgomery_u.rb', line 25 def to_bytes @bytes end |