Blog / A02:2021 Cryptographic Failures
A02:2021 · Cryptographic Failures

Letting the caller pass the nonce invites reuse

The encryptor took the nonce from its caller and used it as-is, twice, with no uniqueness or randomness check. For AEAD, a repeated nonce is a broken cipher.

the callersupplies…the value is usedunchangedthe same noncegoes to…the nonce repeatsacross calls…keystream reuseleaks plaintextATTACKER INPUTIMPACToutput is predictable
Attack path · the caller supplies nonce bytes → the value is used unchanged → the same nonce goes to two cipher instances → the nonce repeats across calls or directions → keystream reuse leaks plaintext

The encryptor took the nonce from its caller and used it as-is, twice, with no uniqueness or randomness check. For AEAD, a repeated nonce is a broken cipher.

What goes wrong

AES-GCM and the other common AEAD modes have one rule you cannot bend. Never use the same nonce twice under the same key. Break it once and the keystream repeats, so XOR the two ciphertexts and the plaintext leaks. The same slip can expose the authentication key, which lets an attacker forge messages that verify.

This code took the nonce straight from the caller with no check on length, uniqueness, or randomness, then handed that same value to both cipher instances. If the two instances share a key, which a related flaw here allows, the reuse is immediate. Even when they don't, you are one careless caller away from repeating a nonce across encryptions. Nonce generation is the library's job. Produce it inside the cipher layer, from a counter or a CSPRNG, and don't accept it as input for a fresh encryption.

The pattern

Vulnerable
Package seal(byte[] key1, byte[] key2, byte[] nonce, byte[] msg) {
  // nonce comes straight from the caller, unchecked
  var boxA = new Aead(key1, nonce);
  var boxB = new Aead(key2, nonce);  // same nonce, two boxes
  return new Package(boxA.encrypt(msg),
                     boxB.encrypt(msg));
}
Hardened
Package seal(byte[] key1, byte[] key2, byte[] msg) {
  byte[] n1 = random(12);  // fresh and unique per encryption
  byte[] n2 = random(12);
  var boxA = new Aead(key1, n1);
  var boxB = new Aead(key2, n2);
  return new Package(boxA.encrypt(msg), boxB.encrypt(msg));
}
How the pipeline adjudicated itHELD
ABCDEFGH

Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.

Ed25519 · per-tenant signing key · gate ledger A–H · verify offline against the published payload hash

Why it matters to you

Nonce reuse is one of the few crypto bugs that is both easy to trigger and total in its effect. An attacker who can replay a nonce, or who just watches two messages that shared one, reads your traffic and forges new messages under your key.

Accepting the nonce from outside makes the bad case something an attacker can choose, not something you accidentally hit. Own the nonce inside the cipher and the whole class of bug goes away.

Check your own code