ChaCha20-Poly1305

On this page 6

ChaCha20-Poly1305 is an authenticated encryption with associated data (AEAD) algorithm that combines the ChaCha20 stream cipher for confidentiality with the Poly1305 message authenticator for integrity. In cryptography it is the main standardized alternative to AES-GCM, and it protects traffic in TLS 1.3, QUIC, WireGuard and OpenSSH.

Both components were designed by Daniel J. Bernstein, and the combined construction is specified for internet protocols in RFC 8439. Its key advantage is fast, constant-time performance in pure software, which matters on devices without hardware acceleration for AES.

How ChaCha20-Poly1305 encrypts and authenticates

ChaCha20-Poly1305 takes a 256-bit key, a 96-bit nonce, the plaintext and optional associated data, and produces ciphertext plus a 128-bit authentication tag. Decryption recomputes the tag and releases plaintext only when the tags match, so tampered messages are rejected as a whole.

ChaCha20 builds a 512-bit state from constants, the key, a 32-bit block counter and the nonce, then applies 20 rounds of add-rotate-XOR (ARX) operations. The output is a 64-byte keystream block that is XORed with the plaintext. Because it uses only additions, rotations and XORs, the cipher runs in constant time and avoids the cache-timing leaks that affect table-based AES implementations.

The combined construction follows a fixed sequence of steps, shown in the table below.

StepOperationPurpose
1Run ChaCha20 with counter 0 and keep 32 bytesDerive a one-time Poly1305 key
2Run ChaCha20 from counter 1 and XOR with the plaintextProduce the ciphertext
3Pad associated data and ciphertext, append their lengthsBuild an unambiguous authenticator input
4Compute Poly1305 over that inputProduce the 16-byte tag
Steps of the AEAD construction

Poly1305 evaluates a polynomial over the prime field modulo 2^130 – 5. It is secure only when each key authenticates exactly one message, which is why the construction derives a fresh Poly1305 key from every key and nonce pair.

Key parameters and variants

The parameters of ChaCha20-Poly1305 are fixed by the specification, and each one sets a concrete operational limit. The table below lists them with their practical consequences.

ParameterValuePractical consequence
Key size256 bitsNo practical brute-force risk
Nonce size96 bitsCounters are safe; random nonces need care
Block counter32 bitsAbout 256 GiB per message
Tag size128 bitsForgery probability is negligible per attempt
Rounds20Large margin over the best known attacks
Parameters of the IETF construction

Several variants exist, and they are not interchangeable on the wire. XChaCha20-Poly1305 extends the nonce to 192 bits, which makes randomly generated nonces safe for very large message counts. The original construction used a 64-bit nonce and a 64-bit counter, and OpenSSH uses its own packet-length encryption scheme built from the same primitives.

VariantNonce lengthTypical use
IETF ChaCha20-Poly130596 bitsTLS 1.3, QUIC, WireGuard
XChaCha20-Poly1305192 bitsFile and message encryption with random nonces
Original construction64 bitsEarly libraries and legacy protocols
OpenSSH variant64-bit sequence numberSSH transport encryption
Main ChaCha20-Poly1305 variants

ChaCha20-Poly1305 compared with AES-GCM

ChaCha20-Poly1305 and AES-GCM offer equivalent security goals, and the practical choice depends mostly on hardware support. On processors with AES instructions, AES-GCM is usually faster; on processors without them, ChaCha20-Poly1305 is typically several times faster and safer against side channels.

The following comparison summarizes how the two AEAD algorithms differ in practice.

PropertyChaCha20-Poly1305AES-GCM
Underlying cipherStream cipher based on ARXBlock cipher in counter mode
Software speed without accelerationHigh and constant-timeSlow or timing-sensitive
Speed with hardware accelerationGoodUsually faster
Nonce misuse impactCatastrophicCatastrophic
FIPS 140 approvalNot approvedApproved
ChaCha20-Poly1305 versus AES-GCM

For this reason, TLS servers often honor the client preference: a phone without AES instructions requests ChaCha20-Poly1305, while a modern laptop chooses AES-GCM. Compliance matters too, because environments bound to FIPS-validated modules generally cannot use ChaCha20-Poly1305.

In TLS 1.3 the algorithm appears as the cipher suite TLS_CHACHA20_POLY1305_SHA256, and QUIC uses the same AEAD for packet protection together with ChaCha20 alone for header protection. WireGuard offers no cipher negotiation at all: every peer uses ChaCha20-Poly1305, which removes downgrade attacks by design. Libraries such as libsodium, BoringSSL and the standard libraries of Go and Rust provide audited implementations, so developers should call a vetted library instead of assembling the two primitives by hand. A homemade composition easily gets padding, length encoding or key derivation wrong.

Nonce reuse and other limitations

The most serious limitation is sensitivity to nonce reuse. Encrypting two messages with the same key and nonce produces the same keystream, which reveals the XOR of the plaintexts, and it reuses the one-time Poly1305 key, which lets an attacker forge valid tags.

The table below lists the typical mistakes and how experienced implementers avoid them.

MistakeConsequenceRemedy
Random 96-bit nonces at high volumeGrowing collision probabilityUse counters or XChaCha20-Poly1305
Releasing plaintext before tag checkAttackers exploit unverified dataVerify the tag first, then decrypt
Non-constant-time tag comparisonTiming leak enables forgeryUse the library comparison routine
Assuming key commitmentPartitioning attacks in some protocolsAdd a key-committing step where needed
Common mistakes and remedies

ChaCha20-Poly1305 is not key-committing: a ciphertext can be crafted to decrypt validly under two different keys. This rarely matters for transport encryption but becomes relevant in multi-recipient or password-based designs. Like every symmetric scheme, it also depends on sound key exchange and key management.

In everyday language

ChaCha20-Poly1305 does two jobs at once. It scrambles a message so outsiders cannot read it. It also attaches a tamper seal that breaks if anyone changes even one letter.

Picture a locked envelope with a wax seal. The lock keeps the letter private, and the seal shows whether someone opened it. The key point is the seal: a damaged seal means the receiver throws the letter away. The method is popular because it works quickly on cheap phones and small devices.

Seen in the real world

A logistics company connects 400 delivery scanners to its warehouse servers over a WireGuard VPN. The scanners use low-cost ARM processors without AES instructions, and earlier tests with an AES-based VPN drained batteries noticeably during long shifts.

WireGuard uses ChaCha20-Poly1305 for every packet, with a 64-bit counter as the nonce, so nonces never repeat within a session. Keys rotate automatically about every two minutes. Any packet altered in transit fails the Poly1305 check and is dropped silently.

After the rollout, the IT team measured lower CPU load on the scanners and stable throughput for inventory uploads. Penetration testers who replayed and modified captured packets saw every attempt rejected, which confirmed integrity protection end to end.