GCM Implementation Pitfalls
You'll learn: Why GCM mode can fail catastrophically if you make seemingly small implementation mistakes.
The Danger of "Easy to Use Wrong"
GCM (Galois/Counter Mode) is the gold standard for authenticated encryption, but it's surprisingly fragile. Unlike simpler modes where mistakes cause isolated failures, GCM has absolute requirements that, if violated, destroy all security guarantees — often silently.
Three Critical Pitfalls
1. Nonce Reuse Is Catastrophic
You learned about CTR mode nonce reuse attacks — GCM is worse. Reusing the same nonce with the same key:
- Leaks plaintext through XOR operations (like CTR)
- Completely breaks authentication, allowing attackers to forge valid tags for arbitrary messages
Analogy: It's like using the same one-time pad twice and giving away your signature stamp.
2. Tag Truncation Weakens Authentication
GCM produces a 128-bit authentication tag by default. Some implementations allow truncating it to 96, 64, or even 32 bits to save bandwidth. Each bit lost exponentially increases forgery risk:
- 32-bit tag: 1-in-4-billion forgery chance (trivial to brute force)
- 96-bit tag: Acceptable for some use cases
- Never go below 96 bits in practice
3. Implementation Complexity
GCM requires:
- Random or counter-based nonce generation (never repeated)
- Correct ordering of operations (encrypt-then-authenticate)
- Proper handling of additional authenticated data (AAD)
- Constant-time operations to prevent timing attacks
A single mistake in any step can silently compromise security without obvious failures.
Key Takeaway: GCM requires perfect implementation discipline — nonce reuse destroys confidentiality and authentication, tag truncation enables forgery, and implementation errors often fail silently. Always use battle-tested libraries, never roll your own GCM.