Class: Noise::Functions::DH::ED448
- Inherits:
-
Object
- Object
- Noise::Functions::DH::ED448
- Defined in:
- lib/noise/functions/dh/ed448.rb
Overview
The 448 DH function of the Noise specification, which is X448 as defined by RFC 7748 and not the Ed448 signature scheme the class name suggests. The name is kept because it is what Protocol::DH maps '448' to and what callers reference.
OpenSSL implements X448 and exposes it through the raw key interface, so this function needs no gem and no system library beyond the OpenSSL that AesGcm and the HMAC helpers already use.
Constant Summary collapse
- DHLEN =
56- ALGORITHM =
The name OpenSSL knows the curve by. Ed448 is a different algorithm, and asking for it here would produce a signing key rather than one that can derive a shared secret.
'X448'
Class Method Summary collapse
Instance Method Summary collapse
-
#dh(private_key, public_key) ⇒ Object
Computes the X448 shared secret for the given remote public key.
- #dhlen ⇒ Object
- #generate_keypair ⇒ Object
Class Method Details
Instance Method Details
#dh(private_key, public_key) ⇒ Object
Computes the X448 shared secret for the given remote public key.
OpenSSL reports a public key it cannot use as OpenSSL::PKey::PKeyError, both when the key is not DHLEN bytes and when the derivation would produce the all-zero output that RFC 7748 requires be rejected. Both are translated to InvalidPublicKeyError so that a caller handling a peer-supplied key rescues the same class for every DH function. The local key is built outside the rescue so that a malformed private key keeps propagating as PKeyError instead of being reported as the peer's fault.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/noise/functions/dh/ed448.rb', line 32 def dh(private_key, public_key) raise Noise::Exceptions::InvalidPublicKeyError, public_key unless public_key.bytesize == DHLEN local = OpenSSL::PKey.new_raw_private_key(ALGORITHM, private_key) begin local.derive(OpenSSL::PKey.new_raw_public_key(ALGORITHM, public_key)) rescue OpenSSL::PKey::PKeyError raise Noise::Exceptions::InvalidPublicKeyError, public_key end end |
#dhlen ⇒ Object
43 44 45 |
# File 'lib/noise/functions/dh/ed448.rb', line 43 def dhlen DHLEN end |