Expand description
ChaCha authenticated encryption: ChaCha20-Poly1305 from RFC 8439 and
XChaCha20-Poly1305, its 24-byte-nonce extension. Both engines implement the
AeadCipher and AeadCipherInit contracts of tc_aead_cipher, over the
ChaCha engines of tc_chacha and the Poly1305 MAC of tc_poly1305. Ported
from Bouncy Castle C#.
ChaCha20Poly1305Engine— ChaCha20-Poly1305, with 12-byte nonces.XChaCha20Poly1305Engine— XChaCha20-Poly1305, with 24-byte nonces that can be drawn at random.
Both take 32-byte keys and produce 16-byte tags. The crate is no_std,
needs no allocator and contains no unsafe code.
ChaCha20 runs on the portable engines of tc_chacha. The default-off
rustcrypto feature enables tc_chacha/rustcrypto, which moves it to
RustCrypto’s chacha20, with SIMD where the processor has it; the output
is the same, and Poly1305 stays on tc_poly1305. The feature pulls in
chacha20 and cipher and follows their minimum Rust version.
Both engines are constant time on either backend: ChaCha20 is built from additions, rotations and XORs, RustCrypto picks its SIMD code from public processor features, Poly1305 reduces without branches, and tags are compared in fixed time. Lengths are public.
Decryption may write unauthenticated plaintext before do_final
verifies the tag, so discard the output when do_final fails. Each
engine’s documentation carries a usage example.
Structs§
- ChaCha20
Poly1305 Engine - Incremental ChaCha20-Poly1305 engine from RFC 8439.
- XCha
Cha20 Poly1305 Engine - Incremental XChaCha20-Poly1305 engine with a 24-byte nonce, from the XChaCha draft (draft-irtf-cfrg-xchacha).
Constants§
- KEY_
BYTES - Secret-key length in bytes, for both engines.
- NONCE_
BYTES - ChaCha20-Poly1305 nonce length in bytes.
- TAG_
BYTES - Authentication-tag length in bytes, the only
mac_sizeeither engine accepts. - XNONCE_
BYTES - XChaCha20-Poly1305 nonce length in bytes.