AES-GCM Forbidden Attack (Nonce Reuse Tag Forgery)
- •
What it is
- •
GCM authenticates ciphertext by evaluating GHASH — a polynomial in a secret authentication key over — at the point , using the associated data and ciphertext blocks as coefficients, then masking the result with an AES-encrypted nonce. If the SAME (key, nonce) pair is ever reused to authenticate two different ciphertexts, the encrypted-nonce mask cancels out when the two tag equations are XORed together, leaving a polynomial equation in that can be solved directly — recovering (or itself, given field square roots) without ever touching the AES key. Once is known, an attacker can forge a valid tag for any chosen ciphertext, completely defeating GCM's authentication guarantee. This is the real "GCM forbidden attack," and nonce reuse is precisely the bug class behind the vulnerability this challenge's flag references.
- •
- •
When to apply
- •
A service lets you obtain multiple (ciphertext, tag) pairs authenticated under the same nonce (and same associated-data structure), and you want to forge a valid tag for ciphertext you didn't get to legitimately authenticate.
- •
- •
Math
- •
For one-block ciphertexts with identical nonce, AAD, and lengths, in . Recover by field division, take the unique field square root , then recover the common mask from one complete tag equation. equals the nonce only through GCM’s specified IV processing; write , not .
- •
- •
Worked example
- •
Encrypting two different 16-byte plaintexts under the same reused nonce gave two (ciphertext, tag) pairs. Computing in , then , let the actual solve forge a valid tag for a third, never-legitimately-authenticated ciphertext (an encryption of the forbidden phrase
give me the flag), which the server decrypted, verified, and returned the real flag for.
- •
- •
SageMath
- •
BF.<X> = GF(2)[] FF.<A> = GF(2^128, modulus=X^128 + X^7 + X^2 + X + 1) h_squared = (t1 - t2) / (c1 - c2) # field division, trivial in Sage h = sqrt(h_squared) # Sage takes square roots in GF(2^128) directly
- •
- •
Related
- •
Cards
- •
What single server-side mistake makes the GCM forbidden attack possible?
- •
Reusing the same (key, nonce) pair to authenticate two different ciphertexts.
- •
- •
What does recovering H² let an attacker do, even without the underlying AES key?
- •
Forge a valid authentication tag for any ciphertext of their choosing.
- •
- •