Skip to main content

Crate tc_chacha_aead

Crate tc_chacha_aead 

Source
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#.

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§

ChaCha20Poly1305Engine
Incremental ChaCha20-Poly1305 engine from RFC 8439.
XChaCha20Poly1305Engine
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_size either engine accepts.
XNONCE_BYTES
XChaCha20-Poly1305 nonce length in bytes.