AES-GCM vs ChaCha20-Poly1305: choosing an AEAD for real systems

AES-GCM vs ChaCha20-Poly1305: speed with and without AES hardware, nonce limits, FIPS status and how to pick an AEAD you will not misuse.

Short answer

Both are sound AEADs with 128-bit tags, and both fail catastrophically on nonce reuse. Use AES-GCM when the hardware has AES instructions (almost every modern server and phone) or when you need FIPS 140 validation. Use ChaCha20-Poly1305 on hardware without AES acceleration, or when you want constant-time software without relying on CPU features. If you cannot guarantee unique nonces, the real choice is XChaCha20-Poly1305 or AES-GCM-SIV, not either of these.

AES-GCMChaCha20-Poly1305
SpecNIST SP 800-38DRFC 8439
Key size128 or 256 bits256 bits
Nonce96 bits recommended96 bits (192 in XChaCha20 variant)
Tag128 bits (do not truncate)128 bits
Max messageAbout 64 GiBAbout 256 GiB
Random nonces per keyStay under 2^32 messagesSame 96-bit limit; XChaCha20 removes it
Fast whenCPU has AES-NI, ARMv8 crypto or similarNo AES hardware; pure software
Side channelsTable-based software AES leaks timingAdd, rotate, XOR: constant time by design
FIPS 140-3ApprovedNot approved
TLS 1.3TLS_AES_128_GCM_SHA256 is mandatoryTLS_CHACHA20_POLY1305_SHA256, widely supported
Nonce reuseLeaks plaintext XOR and the GHASH key: forgeriesLeaks plaintext XOR and allows forgeries

01How each one works

AES-GCM runs AES in counter mode to produce a keystream, XORs it with the plaintext, and authenticates ciphertext and associated data with GHASH, a polynomial hash over GF(2^128) keyed by H, the encryption of a zero block. Speed depends on hardware AES and carry-less multiply instructions.

ChaCha20-Poly1305 uses the ChaCha20 stream cipher (20 rounds of 32-bit add, rotate and XOR) for the keystream, and Poly1305, a one-time authenticator keyed per message from the first ChaCha20 block. It is fast and constant time on any CPU because it needs no lookup tables or special instructions.

iShared shape

Both are stream-cipher-plus-MAC constructions with a 96-bit nonce and a 128-bit tag. That is why both share the same failure: the same key and nonce twice means the same keystream twice.

02The same encryption in both

Python, pyca/cryptographypython
import os
from cryptography.hazmat.primitives.ciphers.aead import AESGCM, ChaCha20Poly1305

aad = b"tenant=42;record=invoice-981"   # bound to the ciphertext, not encrypted

# AES-256-GCM
key = AESGCM.generate_key(bit_length=256)
aes = AESGCM(key)
nonce = os.urandom(12)                  # 96 bits, never reused with this key
ct = aes.encrypt(nonce, b"payload", aad)  # returns ciphertext || 16-byte tag
pt = aes.decrypt(nonce, ct, aad)          # raises InvalidTag on any change

# ChaCha20-Poly1305
key2 = ChaCha20Poly1305.generate_key()  # always 256 bits
chacha = ChaCha20Poly1305(key2)
nonce2 = os.urandom(12)
ct2 = chacha.encrypt(nonce2, b"payload", aad)
pt2 = chacha.decrypt(nonce2, ct2, aad)

# Store nonce alongside ciphertext: nonce || ct

The APIs are interchangeable on purpose. That makes the choice an operational one (hardware, compliance, nonce strategy), not a code one, and it is a good argument for wrapping the AEAD behind one interface with a version byte so you can switch later.

03When to pick which

  • Servers, laptops and modern phones with AES instructions: AES-GCM is usually faster, and AES-128-GCM is a fine default.
  • Low-end ARM, microcontrollers or older devices without AES hardware: ChaCha20-Poly1305 is faster and avoids timing leaks from software AES.
  • FIPS 140-3 or FedRAMP scope: AES-GCM, through a validated module.
  • Random nonces at high volume, or many writers sharing a key: XChaCha20-Poly1305 (192-bit nonce) or AES-GCM-SIV (RFC 8452), which degrades gracefully on reuse.
  • Protocols: follow the protocol. TLS 1.3 negotiates either; WireGuard fixes ChaCha20-Poly1305.

04Common mistakes

  • Reusing a nonce, usually from a counter that resets on restart or a random nonce past the safe volume. Rotate keys well before 2^32 random-nonce messages.
  • Truncating the GCM tag to save bytes. Short tags weaken forgery resistance far more than the length suggests; keep 128 bits.
  • Releasing plaintext before the tag is verified in a streaming decrypt. Buffer, or use a chunked construction such as STREAM with per-chunk tags.
  • Assuming either AEAD commits to its key. Neither does, so a ciphertext can decrypt validly under two keys. Add key commitment if attackers can choose keys.
  • Hand-rolling nonce handling. Prefer a library construction such as Tink or libsodium secretstream that manages nonces for you.
!Nonce reuse is not a small leak

With AES-GCM, two messages under the same key and nonce let an attacker recover the GHASH key and forge tags for any message under that key. Treat it as a key compromise and rotate.

05How to say it in an interview

“How to say it in the room

"Both are good AEADs with the same weakness: nonce reuse breaks confidentiality and integrity. I default to AES-GCM where there is AES hardware or a FIPS requirement, ChaCha20-Poly1305 where there is not, and if I can't guarantee unique nonces I switch to XChaCha20 or GCM-SIV rather than hoping. I wrap it behind a versioned interface so changing later is a key rotation, not a rewrite."

Questions people ask

Q1Is ChaCha20-Poly1305 more secure than AES-GCM?+

Not meaningfully in theory. ChaCha20-Poly1305 is easier to implement in constant time and has a 256-bit key only, but both are considered secure when nonces are unique.

Q2Is AES-256-GCM better than AES-128-GCM?+

AES-128 is not at practical risk. AES-256 adds margin, including against Grover's algorithm, and is often required by policy. The performance cost is small with hardware AES.

Q3Why does TLS 1.3 prefer one over the other?+

It does not prefer either; the client advertises its order. Clients without AES hardware typically put ChaCha20-Poly1305 first so servers can pick the faster option for them.

Q4What is XChaCha20-Poly1305?+

A variant with a 192-bit nonce, large enough to generate randomly without collision worries. It is in libsodium and others, and was specified in an IRTF draft that never became an RFC.

Q5Is ChaCha20-Poly1305 FIPS approved?+

No. If you need FIPS 140-3 validated cryptography, use AES-GCM from a validated module.

Go deeper

Terms on this page