class X25519::MontgomeryU

X25519 public keys and shared secrets

Montgomery-u coordinates of points on the elliptic curve used by X25519 (a.k.a. Curve25519)

Public Class Methods

new(bytes) click to toggle source

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

@param bytes [String] 32-byte compressed Montgomery-u coordinate

# File lib/x25519-termux/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

Public Instance Methods

inspect() click to toggle source

Show hex representation of serialized coordinate in string inspection

# File lib/x25519-termux/montgomery_u.rb, line 30
def inspect
  "#<#{self.class}:#{@bytes.unpack('H*').first}>"
end
to_bytes() click to toggle source

Return a compressed Montgomery-u coordinate serialized as a bytestring

@return [String] bytestring serialization of a Montgomery-u coordinate

# File lib/x25519-termux/montgomery_u.rb, line 25
def to_bytes
  @bytes
end