Class: X25519::MontgomeryU

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(bytes) ⇒ MontgomeryU

Create an object representing a Montgomery-u coordinate from a bytestring

Parameters:

  • bytes (String)

    32-byte compressed Montgomery-u coordinate

Raises:



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

#inspectObject

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.unpack('H*').first}>"
end

#to_bytesString

Return a compressed Montgomery-u coordinate serialized as a bytestring

Returns:

  • (String)

    bytestring serialization of a Montgomery-u coordinate



25
26
27
# File 'lib/x25519/montgomery_u.rb', line 25

def to_bytes
  @bytes
end