Beryl::Crypto::V1::DiffieHellmanOverCurve25519
X25519 key agreement (RFC 7748 §5 and §6.1).
mine = Beryl::Crypto::V1::X25519::PrivateKey.generate
send(mine.public_key.to_slice) # 32 bytes
shared = mine.shared_secret(X25519::PublicKey.new(received_bytes))
# => 32 bytes, or nil when the peer sent a point of small order
The scalar multiplication is a Montgomery ladder of 255 steps whose conditional swap is a mask, on field arithmetic generated from fiat-crypto. Its running time does not depend on the private key.
Constants
BASE_POINT_U = Bytes.new(KEY_BYTESIZE) do |index| index == 0 ? 9_u8 : 0_u8 end
The u-coordinate of the base point, 9 (RFC 7748 §4.1).
KEY_BYTESIZE = 32
Class methods
Returns X25519(scalar, 9), the public key of scalar, the same
bytes scalar_multiply(scalar, BASE_POINT_U) gives, in about a third
of the time: the base point u = 9 is the image of the edwards25519
base point B under the birational map u = (1 + y) / (1 - y) (RFC 7748
§4.1), so the key is [k]B, computed with the precomputed tables of
Edwards25519Group.multiply_base and mapped across. Constant time.