Expand description
ChaCha20-Poly1305 AEAD (RFC 8439) — the symmetric seal that closes the post-quantum channel:
an ML-KEM-768 handshake establishes the shared secret, HKDF derives this 32-byte key, and every
wire message is sealed here. ChaCha20 is a pure Word32 ARX cipher (the same primitive the
assets/std/crypto.lg chacha20Block ships in Logos); Poly1305 is the one-time authenticator in
constant-time 5×26-bit limbs (no bignum). Verified against the RFC 8439 §2.4.2 / §2.5.2 / §2.8.2
known-answer vectors. The tag compare is constant-time.
Constants§
- BOX_
BYTES_ LABEL - The associated data a box of bytes is sealed under.
- BOX_
OVERHEAD - What a box adds to what it seals: its 24-byte nonce in front and its 16-byte tag behind.
- BOX_
VALUE_ LABEL - The associated data a box of a wire-encoded value is sealed under: a box of one kind never opens as the other.
- MAX_
PLAINTEXT - The longest plaintext one (key, nonce) seals (RFC 8439 §2.8): the payload’s blocks start at counter 1 and must not wrap the 32-bit counter back onto the one-time key’s keystream.
Functions§
- chacha20_
encrypt_ seq chacha20Encrypt(key, nonce, counter, data)→data ⊕ keystream(RFC 8439 §2.4): a 32-byte key, a 12-byte nonce, and a block counter the data’s blocks stay inside of.- chacha20_
xor - ChaCha20 keystream XOR (RFC 8439 §2.4):
data ⊕ ChaCha20(key, counter‖nonce). AVX2 (8 blocks at a time) when available, else scalar — bit-identical. - chacha20poly1305_
open - AEAD open: verifies the tag (constant-time) and decrypts, or
Noneon tamper/truncation. - chacha20poly1305_
seal - AEAD seal: returns
ciphertext ‖ tag[16]. - hchacha20
- HChaCha20 (draft-irtf-cfrg-xchacha §2.2): the ChaCha20 rounds over
keyand a 128-bitnoncein the counter-and-nonce words, without the final addition, returning the first and last rows — a subkey as uniform as the key, one per nonce. - open_
box - The plaintext of a box sealed under
keyandlabel, orNonewhen it is shorter than a box or does not authenticate. - poly1305
- Poly1305 one-time authenticator:
tag = ((Σ blockᵢ·r^(n−i)) mod (2¹³⁰−5)) + s mod 2¹²⁸. AVX2 (4 blocks/group via precomputed r¹..r⁴) for long messages, else scalar — bit-identical. - poly1305_
seq poly1305Mac(key, msg)→ 16-byte tag. The MAC primitive (constant-time 5×26-bit limbs).- seal_
box - The box of
plaintextunderkey, its nonce drawn from the system’s entropy: 192 random bits, so one key seals any number of boxes without two sharing a nonce. - seal_
box_ under - The box of
plaintextunderkeyandnonce:nonce ‖ XChaCha20-Poly1305(key, nonce, label, plaintext). - xchacha20poly1305_
open - XChaCha20-Poly1305 open: verifies the tag (constant-time) and decrypts, or
Noneon tamper/truncation. - xchacha20poly1305_
seal - XChaCha20-Poly1305 seal:
ciphertext ‖ tag[16]. Its 192-bit nonce is wide enough to draw at random for every message under one key, which a 96-bit nonce is not.