Skip to content

Nonce Collision

Mode-specific IV/nonce rules Β· NIST SP 800-38A/38D Β· RFC 8439

Reuse a counter block or nonce in AES-CTR, AES-GCM, and ChaCha20-Poly1305; reuse a CBC IV and then try a distinct but predictable one. Compare the different results against real encryption.

What is a nonce, and why does reuse matter?

A nonce β€” "number used once" β€” and an initialization vector (IV) are public inputs used differently by different constructions. They travel with the ciphertext; the encryption interface does not check whether your choice meets the mode's security requirement.

Requirements depend on the mode. AES-CTR must never repeat a counter block under one key; AES-GCM and ChaCha20-Poly1305 require their nonces to be unique under one key. AES-CBC instead needs an IV the attacker cannot predict before choosing the plaintext; using a different but predictable IV each time is insufficient. Reusing a CBC IV has its own prefix leak. The four constructions do not fail the same way.

No theory required to start. Go to The XOR reveal, reuse a nonce yourself, and drag out a hidden message. Then the rest of the page explains what you just did.

TEACHING DEMO β€” NOT PRODUCTION

Every cipher operation on this page is real: AES runs in your browser's WebCrypto engine; ChaCha20 and Poly1305 are hand-rolled to the RFC 8439 test vectors so their internals are inspectable. The attacks recover real keys from real ciphertexts and are accepted by the real verifiers. It is still a teaching demo β€” keys live only in memory for the session, and nothing here is hardened for production use.

The XOR reveal β€” recover a message you were never given

This is the headline mechanism. Two messages, one AES-CTR key, one nonce. Because a stream cipher just XORs plaintext with a keystream that depends only on (key, nonce), reusing the nonce makes both messages share the same keystream β€” and XORing the two ciphertexts cancels it, leaving P₁ βŠ• Pβ‚‚ with no key involved. Drag a guessed piece of one message across it and the other message falls out. This runs against real AES-CTR ciphertext.

Same mistake, four outcomes

Reusing a counter block, nonce, or CBC IV under the same key lands differently on each construction. Flip a card from fresh to reused, run it, and read two separate indicators: what the cipher's own function returned, and the security verdict. They are not the same thing. A tag can verify as VALID and still be a forgery β€” that reads as an ALARM, never a success. The separate CBC exhibit below also tests predictable, distinct IVs.

Two indicators, on purpose. Cryptographic result is the raw return value of the primitive (did it decrypt? did the tag check out?). Security verdict tracks whether the system's guarantee still holds. Colour follows the verdict, not the return value β€” because a forgery the verifier accepts is the most dangerous outcome of all.

One click breaks (or spares) all four at once, then read the running tally below and the per-card detail underneath. This is the whole thesis in one motion: one mistake, four different failures.

AES-CTR SP 800-38A

Pure stream cipher. Reuse collapses to C₁ βŠ• Cβ‚‚ = P₁ βŠ• Pβ‚‚ β€” keystream reuse, exactly the XOR reveal. There is no integrity tag here to lose.

AES-GCM SP 800-38D

Keystream reuse plus a worse break: two ciphertexts under one nonce let Joux's "forbidden attack" recover the GHASH authentication subkey H, enabling tag forgery. This is authentication-key recovery β€” not AES key recovery.

ChaCha20-Poly1305 RFC 8439

Keystream reuse plus recovery of the per-message Poly1305 one-time key (r, s), which is fixed by (key, nonce) β€” enabling forgery for that nonce. The ChaCha20 key itself is not recovered.

AES-CBC SP 800-38A

IV reuse makes CBC deterministic on shared prefixes: equal leading plaintext blocks produce equal leading ciphertext blocks. CBC also requires an unpredictable IV; the separate experiment below shows why distinct IVs alone do not suffice.

CBC: different IVs can still leak

Imagine an attacker can choose the next plaintext after learning the next IV. With the same key, choose Pβ‚‚ = P₁ βŠ• IV₁ βŠ• IVβ‚‚ for the first block. CBC then feeds AES the same block twice: Pβ‚‚ βŠ• IVβ‚‚ = P₁ βŠ• IV₁. The IVs differ, but their first ciphertext blocks match. This is a controlled chosen-plaintext example; it does not recover the AES key or unknown plaintext.

Control: the attacker commits to Pβ‚‚ before the browser draws a fresh random IV, so the compensating choice cannot target that IV. This single run tests the first-block relation, not CBC integrity or an entire application's security. Sources: NIST SP 800-38A, Β§5.3 and Appendix C; NIST IR 8459 (September 2024), Β§4.1.

The consequence table β€” precise, and precisely different

What reuse of a counter block, nonce, or CBC IV does in each construction, and which key (if any) is recovered
Construction Spec What IV/nonce reuse breaks Precise consequence Enc./AES key recovered?
AES-CTR SP 800-38A Confidentiality Keystream reuse β†’ Cβ‚βŠ•Cβ‚‚ = Pβ‚βŠ•Pβ‚‚; plaintext recovery by crib-dragging. No integrity claim to lose. No
AES-GCM SP 800-38D Confidentiality and integrity Keystream reuse, plus GHASH authentication subkey H recovery (forbidden attack) β†’ existential forgery under that key. No β€” auth key only
ChaCha20-Poly1305 RFC 8439 Confidentiality and integrity Keystream reuse, plus Poly1305 one-time key (r, s) recovery β†’ forgery for that nonce. No β€” MAC key only
AES-CBC SP 800-38A Confidentiality (partial) IV reuse leaks equality of message prefixes. Even distinct but predictable IVs permit the chosen-first-block equality experiment below; neither is keystream collapse. No

The precision is the point. "Key recovery" is a phrase that hides a huge range. GCM and ChaCha20-Poly1305 leak the authentication key and let you forge; neither leaks the encryption key, so neither hands an attacker the ability to decrypt future messages under a fresh nonce. Overstating that would be a lie the math doesn't support.

Why the forgeries work β€” one cancellation, twice

Both authenticated modes fall to the same shape of mistake: a secret pad that depends only on (key, nonce) sits inside the tag, and when the nonce repeats, XORing two tags cancels that pad and exposes a clean equation in the one unknown you want. Press each button to watch the cancellation happen β€” nothing here moves on its own.

AES-GCM: the mask cancels, leaving a polynomial in H

The GCM tag is a keyed checksum GHASHH over the ciphertext, with a per-nonce mask EK(Jβ‚€) XORed on top. H = EK(0¹²⁸) is fixed by the key; the mask is fixed by (key, nonce).

The same mask sits in both tags. Press to encrypt two probes under a fresh key and one reused nonce, then re-derive the mask from each tag.

For two equal-length single blocks this collapses to tag₁ βŠ• tagβ‚‚ = (C₁ βŠ• Cβ‚‚)Β·HΒ², solved directly as H = √((tagβ‚βŠ•tagβ‚‚)Β·(Cβ‚βŠ•Cβ‚‚)⁻¹) over GF(2¹²⁸). Recover H and the mask, and you can forge a tag for any ciphertext under that nonce. This is exactly what the GCM card runs β€” the recovered H is checked byte-for-byte against the true EK(0¹²⁸), and the forged blob is handed to WebCrypto's own verifier.

ChaCha20-Poly1305: the one-time key is reused, so (r, s) leaks

Poly1305 is a one-time authenticator: for a key (r, s) the tag is (polyr(msg) + s) mod 2¹²⁸. "One-time" means (r, s) may authenticate exactly one message. In the AEAD, (r, s) is ChaCha20(key, nonce, 0)[0:32] β€” fixed by (key, nonce).

The same s sits in both tags. Press to MAC two probes under a fresh key and one reused nonce, then re-derive s from each tag.

With s gone, a linear (single-block) relation in r remains over the field GF(2ΒΉΒ³β°βˆ’5); invert (nβ‚βˆ’nβ‚‚), resolve the small carry from the final mod 2¹²⁸, and r β€” then s β€” fall out. The ChaCha card recovers (r, s) from public tags only, checks them against the true one-time key, and the real Poly1305 verifier accepts the forged tag. The ChaCha20 encryption key never appears in any of this.

Where a nonce actually repeats

Reuse is not exotic. It comes from two ordinary places: random nonces colliding by the birthday bound, and counters that silently rewind.

Random 96-bit nonces and the birthday bound

Pick nonces at random from a 2bits space and a collision becomes likely far sooner than intuition says β€” around √(2Β·2bits) draws, not 2bits. Slide the message count and watch the probability of at least one repeat climb (computed live from the exact birthday formula).

Nonce size
2⁴⁰ messages
Collision probabilityβ€”
50% chance at aboutβ€”

This is why SP 800-38D limits a single key to 2Β³Β² invocations when 96-bit IVs are generated randomly: past that, the birthday probability of an IV collision β€” and the total break you just saw β€” stops being negligible.

Counters that rewind

A monotonic counter never repeats β€” until the machine does. Restore a VM snapshot, fork a process, or roll back a container and the counter resumes from an old value, re-emitting nonces already used under the same long-lived key. The counter looks perfect; the environment betrayed it.

The deeper question β€” how randomness and state themselves collapse β€” is its own subject. See the Entropy Collapse lab in the Crypto Lab catalog. This lab stops at the nonce and what breaks downstream of it.

Fixes, and what this lab is not

The mitigation: make reuse survivable (or impossible)

For CTR and the AEADs here, guarantee uniqueness under each key β€” a persistent counter can work only if it cannot rewind. For CBC, generate a fresh unpredictable IV before each encryption. Another direction for AEADs is a misuse-resistant construction: AES-GCM-SIV (RFC 8452) derives the IV from the plaintext, so reuse leaks only whether two plaintexts were identical β€” no keystream collapse, no key recovery.

The same reused nonce under AES-GCM versus the misuse-resistant AES-GCM-SIV
Under one reused nonceAES-GCM (this lab)AES-GCM-SIV (RFC 8452)
ConfidentialityKeystream reuse β†’ Cβ‚βŠ•Cβ‚‚ = Pβ‚βŠ•Pβ‚‚Leaks only whether two plaintexts are identical
IntegrityGHASH subkey H recovered β†’ tag forgeryNo key recovery; the tag still binds
CostSingle pass, onlineTwo passes; must buffer the full plaintext

Described, not run here. The AES-GCM-SIV column is the RFC 8452 behaviour, not a live computation β€” this lab deliberately does not implement SIV. To break both side by side against real crypto, see Nonce Guard.

Honest scope β€” what this is not

  • No AES key recovery, anywhere. The GCM and ChaCha20-Poly1305 breaks recover authentication keys and enable forgery. The AES/ChaCha encryption key is never learned. The whole lab is built around that distinction.
  • Not a misuse-resistant-AEAD build. AES-GCM-SIV is named as the fix and linked, not implemented here β€” see Nonce Guard.
  • Not an entropy-source lab. How randomness and counters fail upstream is Entropy Collapse, in the catalog.
  • No CBC padding oracle. The CBC exhibits show reused-IV prefix equality and a predictable-IV chosen-plaintext relation; the separate padding-oracle decryption attack is Padding Oracle.
  • What it does not prove: that these ciphers are weak. They have mode-specific requirements: unique counter blocks/nonces for CTR and the AEADs here; unpredictable IVs for CBC. CBC/CTR also lack built-in authentication. These exhibits demonstrate only the stated failure models, not general security.

Related demos

Under consideration: wider-block GCM

NIST’s second pre-draft consultation (1 June 2026) proposes wGCM using a 256-bit-block cipher. Comments closed 31 July; this is a proposal, not a finalized replacement for GCM.

AES-128 and AES-256 both have 128-bit blocks. Changing the AES key length does not implement wGCM. This demo runs its existing AES modes, not Rijndael-256/wGCM. The nonce-reuse experiments and current tag guidance remain applicable to the constructions actually executed here. Reviewed 12 October 2026.