diff options
Diffstat (limited to 'oxish-proto/src')
| -rw-r--r-- | oxish-proto/src/key_exchange.rs | 11 | ||||
| -rw-r--r-- | oxish-proto/src/named.rs | 6 |
2 files changed, 15 insertions, 2 deletions
diff --git a/oxish-proto/src/key_exchange.rs b/oxish-proto/src/key_exchange.rs index cbb8e2e..898fb46 100644 --- a/oxish-proto/src/key_exchange.rs +++ b/oxish-proto/src/key_exchange.rs @@ -614,8 +614,15 @@ impl KeyExchangeOutput { // Write the server's reply public value (`Q_S` / `S_REPLY`) to the exchange hash exchange.prefixed(&completed.public_key); let secret_bytes = completed.shared_secret.secret_bytes(); - let mut shared_secret = Vec::with_capacity(secret_bytes.len() + 4); - secret_bytes.encode(&mut shared_secret); + let mut shared_secret = Vec::with_capacity(secret_bytes.len() + 5); + match negotiated.key_exchange { + // RFC 8731 section 3: `K` is the raw X25519 output encoded as an mpint + KeyExchangeAlgorithm::Curve25519Sha256 => { + encode_mpint(secret_bytes, &mut shared_secret) + } + // The PQ hybrid draft encodes `K` (a fixed-length hash output) as a string + _ => secret_bytes.encode(&mut shared_secret), + } exchange.update(&shared_secret); let exchange_hash = exchange.finish(); diff --git a/oxish-proto/src/named.rs b/oxish-proto/src/named.rs index bc6dbea..4b24417 100644 --- a/oxish-proto/src/named.rs +++ b/oxish-proto/src/named.rs @@ -180,6 +180,10 @@ pub enum KeyExchangeAlgorithm<'a> { /// /// As defined in <https://datatracker.ietf.org/doc/draft-kampanakis-curdle-ssh-pq-ke/>. MlKem768X25519Sha256, + /// `curve25519-sha256` key exchange algorithm: ECDH using X25519 + /// + /// As defined in <https://www.rfc-editor.org/rfc/rfc8731>. + Curve25519Sha256, /// A key exchange algorithm not known to this implementation Unknown(&'a str), } @@ -188,6 +192,7 @@ impl<'a> Named<'a> for KeyExchangeAlgorithm<'a> { fn typed(name: &'a str) -> Self { match name { "mlkem768x25519-sha256" => Self::MlKem768X25519Sha256, + "curve25519-sha256" => Self::Curve25519Sha256, _ => Self::Unknown(name), } } @@ -195,6 +200,7 @@ impl<'a> Named<'a> for KeyExchangeAlgorithm<'a> { fn name(&self) -> &str { match self { Self::MlKem768X25519Sha256 => "mlkem768x25519-sha256", + Self::Curve25519Sha256 => "curve25519-sha256", Self::Unknown(name) => name, } } |
