Skip to main content

Module wrap

Module wrap 

Source
Expand description

Wrapping a pairing payload under the CPace output.

The code-based flows never send two values in clear: the new long-term PSK and, in the Dynamic Pairing Code Flow, the commitment opening nonce_B. Each is sealed under the PAKE’s intermediate session key with a key derived per field:

K_wrap = SHA-256(label || sid || ISK)
sealed = AEAD(K_wrap, nonce = 12 zero bytes, aad = empty, value)

The concatenation is raw - no separator, no length prefix, no NUL terminator - and ISK is the 64-byte CPace intermediate session key. The label separates the two fields, so a wrapped_nonce_B cannot be replayed as a wrapped_psk; the sid binds the seal to one CPace session, so a man in the middle that relays between two handshakes, whose differing h gives each leg a different sid, derives a key on neither leg.

A value is 32 bytes and its sealed form 48: the ciphertext plus a 16-byte authentication tag. A payload that fails to authenticate is an error, never a zero or partially decrypted value, and neither Debug output nor an error string ever carries the key, the value or the seal.

§The AEAD is the suite’s

The spec seals with the AEAD of the connection’s negotiated cipher suite. Sendspin defines two suites - 25519_ChaChaPoly_SHA256 and 25519_AESGCM_SHA256 - and this crate offers the first only (NOISE_SUITE), so the AEAD here is ChaCha20-Poly1305. Offering 25519_AESGCM_SHA256 would mean selecting the AEAD from the suite rather than fixing it in this module.

The module is behind the pairing-code feature with pake: wrapping exists only for the code flows, and the default build keeps no AEAD of its own.

Constants§

NONCE_LABEL
The label that derives the key for wrapped_nonce_B.
PSK_LABEL
The label that derives the key for wrapped_psk.

Functions§

k_wrap
Derives K_wrap = SHA-256(label || sid || ISK).
unwrap
Opens a 48-byte sealed value under K_wrap, returning the 32-byte value.
wrap
Seals a 32-byte value under K_wrap, returning the 48-byte ciphertext and tag.