Course contentsShow
← Security
Lesson 126 of 3,0523. Symmetric Cryptography Deep DiveFree lesson

AES-GCM Implementation Considerations

Nonce reuse catastrophic failures, tag truncation risks, and constant-time verification requirements.

AES-GCM Implementation Considerations

You'll learn: The critical implementation pitfalls that can completely break AES-GCM's security, even when used correctly at the API level.

The Three Deadly Implementation Sins

Even though AES-GCM is theoretically secure (as you learned in lesson 125), real-world implementations can fail catastrophically if you violate certain rules.

Nonce Reuse: The Fatal Mistake

Nonce reuse in AES-GCM is absolutely catastrophic. Unlike CBC mode where nonce reuse "only" leaks plaintext patterns, reusing a nonce in GCM allows attackers to:

  • Recover the authentication key
  • Forge valid authentication tags for arbitrary messages
  • Decrypt all messages encrypted with that nonce

Think of the nonce as a lock combination — once an attacker sees the same combination twice, they can reverse-engineer the entire system. Never reuse a nonce with the same key, ever.

Tag Truncation: Weakening the Shield

AES-GCM produces a 128-bit authentication tag by default, but some implementations allow truncation to 96, 64, or even 32 bits to save bandwidth. Each bit you remove halves the security: a 64-bit tag gives an attacker a 1-in-2⁶⁴ chance of forging a valid message — feasible with enough attempts.

Best practice: Use the full 128-bit tag unless you have extraordinary constraints and understand the risk.

Constant-Time Verification: Preventing Timing Leaks

When verifying the authentication tag, you must compare all bytes in constant time. A naive byte-by-byte comparison that exits early on mismatch leaks information through timing, potentially allowing attackers to forge valid tags through millions of carefully timed attempts.

Key Takeaway: AES-GCM's security depends entirely on never reusing nonces, using full-length tags, and implementing constant-time tag verification — get any of these wrong and encryption becomes worthless.