Skip to content

Commit 6991356

Browse files
committed
encryption/aead: document why XChaCha20-Poly1305 stays on RustCrypto
Record the security decision so no future session naively "wires the AEAD hot path through ndarray::simd::chacha20_keystream" and ends up hand- composing HChaCha20 + Poly1305 + the AEAD framing (the roll-your-own-AEAD footgun). The accelerated keystream primitive is trusted and available for raw-stream use sites that already own a vetted MAC; this authenticated AEAD is not one of them and keeps the vetted RustCrypto XChaCha20Poly1305. Doc-only; encryption crate 23/23 green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K6pT32kk6pnuAAqR3JiYqu
1 parent 22c16de commit 6991356

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

crates/encryption/src/aead.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
//! is no counter state to persist or synchronise between a browser tab
66
//! and a server. Callers normally use [`crate::envelope`], which manages
77
//! nonce generation and layout; this module is the raw primitive.
8+
//!
9+
//! ## Deliberately NOT hand-composed from `ndarray::simd::chacha20_keystream`
10+
//!
11+
//! `ndarray` now ships a hardware-accelerated ChaCha20 keystream
12+
//! (`ndarray::simd::chacha20_keystream`, AVX-512 / wasm128, byte-parity-proven
13+
//! against RustCrypto). It is tempting to swap this AEAD's keystream to that
14+
//! primitive for speed — **do not.** XChaCha20-Poly1305 is not just a keystream:
15+
//! it is HChaCha20 subkey derivation + the Poly1305 one-time-key + MAC framing +
16+
//! the AAD/length encoding. Re-wiring only the keystream means re-implementing
17+
//! that authenticated composition by hand, which is exactly the "roll your own
18+
//! AEAD" footgun the stack forbids. The vetted RustCrypto `XChaCha20Poly1305`
19+
//! construction stays here. The accelerated primitive is for *raw-stream* use
20+
//! sites whose caller already owns a vetted MAC/framing — not this module.
821
922
use chacha20poly1305::aead::{Aead, KeyInit, Payload};
1023
use chacha20poly1305::{Key, XChaCha20Poly1305, XNonce};

0 commit comments

Comments
 (0)