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 connection’s suite

The spec seals with the AEAD of the connection’s negotiated cipher suite, so every function here takes a Suite: 25519_ChaChaPoly_SHA256 seals with ChaCha20-Poly1305 and 25519_AESGCM_SHA256 with AES-256-GCM. Both are 32-byte-key, 12-byte-nonce, 16-byte-tag ciphers, so K_wrap and the sealed length are the same under either; only the ciphertext differs, and a value sealed under one suite does not open under the other.

The ciphers come from the same resolver snow uses for the handshake, which is where the dependency already sits. A build whose resolver lacks the suite’s cipher returns an error and never falls back to the other suite.

The module is behind the pairing-code feature with pake: wrapping exists only for the code flows.

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 with the AEAD of suite, returning the value.
wrap
Seals a 32-byte value under K_wrap with the AEAD of suite, returning ciphertext and tag.