JFLib

netio/tls/kx.rs#

Source: lib/netio/tls/kx.rs

kx -- the key exchange groups of TLS: X25519, P-256 and P-384 (ECDHE: RFC 8446 4.2.8.2, RFC
8422 5.4) and the hybrids of an ECDHE share and ML-KEM (draft-ietf-tls-ecdhe-mlkem): each
side's share is the two halves concatenated, the shared secret both secrets

  group                 client share                server share                secret
  X25519MLKEM768        ML-KEM-768 ek || X25519     ciphertext || X25519        ML-KEM || X25519
  SecP256r1MLKEM768     P-256 point || ek           P-256 point || ciphertext   ECDH || ML-KEM
  SecP384r1MLKEM1024    P-384 point || ek (1024)    P-384 point || ciphertext   ECDH || ML-KEM

  Share::new(group) -> our key share (client, TLS 1.2 client: ECDHE only), its secrets
  share.finish(peer) -> the shared secret from the peer's share
  respond(group, client_share) -> (our share, the shared secret) for a TLS 1.3 server

Every length is exact; an ECDHE point off the curve, an X25519 result of zeros or an
encapsulation key that fails FIPS 203's modulus check gives None (illegal_parameter).
SECP256R1: u16 = 0x0017
SECP384R1: u16 = 0x0018
X25519: u16 = 0x001d
SECP256R1_MLKEM768: u16 = 0x11eb
X25519_MLKEM768: u16 = 0x11ec
SECP384R1_MLKEM1024: u16 = 0x11ed
/// every group here.  The order is no preference: a server goes by the client's list and takes
/// the first group here that the client sent a share of; without one it asks for the first
/// group here the client lists (HelloRetryRequest)
GROUPS: [u16; 6] = [X25519_MLKEM768, X25519, SECP256R1, SECP384R1, SECP256R1 ...
  • fn known(group: u16) -> bool whether this is a group here

  • struct Share a key share we made, with its secrets (wiped when dropped)

    • group: u16
    • public: Vec<u8>

impl Share

  • fn new(group: u16) -> Option<Share> a new share of group (None: not a group here)

  • fn finish(&self, peer: &[u8]) -> Option<Vec<u8>> the shared secret from the peer's share (None: of the wrong length or not valid)

  • fn respond(group: u16, client: &[u8]) -> Option<(Vec<u8>, Vec<u8>)> a TLS 1.3 server's answer to the client's share of group: (our share, the shared secret)

Source: docs/API.md in the JFLib repository.