GCM: nonce reuse
AES-GCM is the most widely used mode today (TLS, VPN, disk encryption). It provides confidentiality (CTR mode) and integrity (GHASH authentication tag) at the same time. But it has one unforgiving condition: you can use a single nonce with a single key only once.
If the nonce is repeated, not only are the plaintexts exposed (as in CTR), but the attacker can also recover the authentication key H and forge a valid tag for any message. This is called the "forbidden attack" (Joux, 2004).
Required formulas
For a single 16-byte block and no AAD (our case), GHASH has a very simple form. Here * is multiplication in GF(2^128), and + is XOR:
H = AES-ECB(K, 16 ta nol bayt) <- autentifikatsiya kaliti
L = 00000000000000000000000000000080 <- uzunliklar bloki
GHASH(C) = ((C * H) + L) * H
TEG(C) = GHASH(C) + E(J0) <- E(J0) faqat nonce ga bog'liq
Attack
Two messages are encrypted with the same key and the same nonce, which means E(J0) is the same in both. If we XOR the tags, it cancels out:
T1 + T2 = ((C1 * H) + L) * H + ((C2 * H) + L) * H
= (C1 + C2) * H^2
=> H^2 = (T1 + T2) * (C1 + C2)^(-1)
=> H = (H^2)^(2^127) <- GF(2^128) da kvadrat ildiz yagona
Once H is found: E(J0) = T1 + GHASH(C1). Now you can calculate a valid tag for any ciphertext.
Given data
nonce = f301895fc7e3d44d2df4b7fa (ikkala xabarda bir xil!)
P1 = salom_dunyo_2026
C1 = b2db49dd66374de60d0a5109eb674977
T1 = adbfeab583f83ea7d2cdd4ff7cf1341e
C2 = a8d14edb650b41fa3c0b5f34b8252470
T2 = 306b9d610a405cef52c3600dd7d7286e
Task: calculate a valid GCM tag for the following message (with the same key and the same nonce):
P* = "admin=true_hozir"
To do this, first find the keystream (KS = C1 + P1), then C* = P* + KS, and finally T* = GHASH(C*) + E(J0). Write the 16 bytes of the tag in lowercase hex format:
BAYROQ{A3S_gcm_forge_<teg hex>}
GF(2^128) arithmetic is provided ready-to-use in the attached gf128.py file (gf_mul, gf_pow, gf_inv). You can run it to ensure the functions work correctly.
Check: if you found H correctly, the equation T2 = GHASH(C2) + E(J0) must also hold true. This will show you an error immediately.