Skip to Content
oxcrypto

ChaCha20-Poly1305

Encrypt with ChaCha20-Poly1305, XChaCha20-Poly1305 or their reduced-round forms.

import os

from oxcrypto.aead.chacha20poly1305 import CHACHA20_POLY1305

key = CHACHA20_POLY1305.XCHACHA20.generate()
nonce = os.urandom(24)
sealed = key.encrypt(nonce, b"message", associated_data=b"header")
plaintext = key.decrypt(nonce, sealed, associated_data=b"header")

Variants: CHACHA20, CHACHA12, CHACHA8, XCHACHA20, XCHACHA12, XCHACHA8.

ChaCha variants use a 12-byte nonce. XChaCha variants use a 24-byte nonce, which is large enough to pick at random. All keys are 32 bytes.

StandardRFC 8439 (Informational, IRTF CFRG) for ChaCha20-Poly1305. XChaCha20-Poly1305 follows draft-irtf-cfrg-xchacha (expired draft). The 8- and 12-round forms are not standardized.
Cratechacha20poly1305 0.11.0
MaturityStable release. No published audit of 0.11; NCC Group published an audit of chacha20poly1305 0.7 in 2020.
MSRVBuilds with Rust 1.88.
Zeroizationchacha20poly1305, chacha20 and poly1305 with zeroize are written to wipe the stored key, the ChaCha state and the one-time Poly1305 key and state. oxcrypto has not verified this independently.
ExperimentalReduced-round variants (CHACHA8, CHACHA12, XCHACHA8, XCHACHA12)
Test vectorsWycheproof chacha20_poly1305_test.json and xchacha20_poly1305_test.json; reduced-round variants are round-trip tested only