ChaCha20-Poly1305
ARX stream cipher with a one-time Poly1305 MAC; fast and constant-time in software
About ChaCha20-Poly1305
ChaCha20-Poly1305 is an authenticated encryption (AEAD) scheme. It uses a 32-byte (256-bit) key, a 12-byte nonce and a 16-byte (128-bit) authentication tag. Its registry entry cites RFC 8439. It is also known as chacha20-poly1305-ietf. NextSSL lists it in the standard tier and exposes it through the safe API.
Overview
ChaCha20-Poly1305 pairs the ChaCha20 stream cipher with the Poly1305 one-time authenticator, as specified in RFC 8439. XChaCha20-Poly1305 extends the nonce to 192 bits so random nonces can be used safely.
ChaCha20 is a 20-round add-rotate-XOR stream cipher derived from Salsa20; it uses only 32-bit additions, rotations and XORs, so it runs quickly and in constant time on processors without AES hardware. For each message, the first ChaCha20 block under the key and nonce yields a one-time Poly1305 key, and the remaining keystream encrypts the plaintext. Poly1305 then authenticates the associated data and ciphertext.
The construction is used in TLS 1.3, QUIC, SSH, WireGuard and many messaging protocols. XChaCha20-Poly1305 first applies HChaCha20 to the key and the first 128 bits of a 192-bit nonce to derive a subkey, then runs the standard construction with the remaining nonce bits. NextSSL provides both variants.
History
2015–2018ChaCha20-Poly1305 published
Specified in RFC 8439
How it works
- Generate the Poly1305 one-time key from ChaCha20 block 0 under the key and nonce.
- Encrypt the plaintext by XOR with ChaCha20 keystream from block 1 onward.
- Compute Poly1305 over the padded associated data, padded ciphertext and their lengths.
- For XChaCha20, first derive a subkey with HChaCha20 from the key and the first 16 nonce bytes.
Security notes
Nonce reuse leaks plaintext XORs and the Poly1305 key, enabling forgeries. The 96-bit nonce of the IETF variant should be a counter or otherwise unique; XChaCha20's 192-bit nonce makes random nonces safe in practice.
Typical uses
Sizes
| Field | Bytes | Meaning |
|---|---|---|
| key | 32 | Secret key |
| nonce | 12 | Nonce / IV |
| tag | 16 | Authentication tag |
Use it
from nextssl_demo import NextSSL
ns = NextSSL() # safe API: safe and standard tiers
key, nonce = ns.random(32), ns.random(12)
ct = ns.call("aead_seal", "chacha20-poly1305", None, key, nonce, b"header", b"secret")[0] # ct || tag
pt = ns.call("aead_open", "chacha20-poly1305", None, key, nonce, b"header", ct)[0]
nextssl_aead_seal("chacha20-poly1305", NULL, key, nonce, aad, pt, out); /* writes ct || tag */
nextssl_aead_open("chacha20-poly1305", NULL, key, nonce, aad, ct, out);
use nextssl_core::Params;
use nextssl_registry::{self as reg, Policy};
let alg = reg::new_aead_in(reg::all(), Policy::Safe, "chacha20-poly1305", &Params::new())?;
let ct = alg.seal(&key, &nonce, b"header", b"secret")?;
let pt = alg.open(&key, &nonce, b"header", &ct)?;
Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.
Other ChaCha20-Poly1305 variants
1Similar names
Looking for something else?More authenticated encryption
All 392Frequently asked questions
What is ChaCha20-Poly1305?
ChaCha20-Poly1305 is an AEAD in the ChaCha20-Poly1305 family. ChaCha20-Poly1305 pairs the ChaCha20 stream cipher with the Poly1305 one-time authenticator, as specified in RFC 8439. It is also known as chacha20-poly1305-ietf.
What are the ChaCha20-Poly1305 sizes?
In NextSSL, ChaCha20-Poly1305 uses: key 32 bytes, nonce 12 bytes, tag 16 bytes.
Who designed ChaCha20-Poly1305 and when?
ChaCha20-Poly1305 belongs to the ChaCha20-Poly1305 family, first published in 2015 by Daniel J. Bernstein (ChaCha20, Poly1305); construction by Adam Langley and Yoav Nir (RFC). Its origin: RFC 8439 (obsoletes RFC 7539); draft-irtf-cfrg-xchacha.
Which standards define ChaCha20-Poly1305?
ChaCha20-Poly1305 is referenced by RFC 8439.
Is ChaCha20-Poly1305 safe to use?
ChaCha20-Poly1305 is in the standard tier. Standardised and sound. Reachable from the safe API. It can be called from the safe API.
What other ChaCha20-Poly1305 variants are there?
NextSSL also registers xchacha20-poly1305 in the ChaCha20-Poly1305 family.