Skip to main content

Module aead

Module aead 

Source
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 None on tamper/truncation.
chacha20poly1305_seal
AEAD seal: returns ciphertext ‖ tag[16].
hchacha20
HChaCha20 (draft-irtf-cfrg-xchacha §2.2): the ChaCha20 rounds over key and a 128-bit nonce in 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 key and label, or None when 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 plaintext under key, 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 plaintext under key and nonce: nonce ‖ XChaCha20-Poly1305(key, nonce, label, plaintext).
xchacha20poly1305_open
XChaCha20-Poly1305 open: verifies the tag (constant-time) and decrypts, or None on 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.