Skip to content

aead: require &mut self for seal/open and add TLS AEAD variants#514

Open
janrueth wants to merge 1 commit into
cloudflare:masterfrom
janrueth:aead-mut-self-tls-variants
Open

aead: require &mut self for seal/open and add TLS AEAD variants#514
janrueth wants to merge 1 commit into
cloudflare:masterfrom
janrueth:aead-mut-self-tls-variants

Conversation

@janrueth

Copy link
Copy Markdown
Contributor

Change all seal/open methods on AeadCtxRef from &self to &mut self.

The TLS-specific AEADs (aes_gcm_tls12, aes_gcm_tls13) are stateful and internally mutate the EVP_AEAD_CTX during seal operations (nonce counter tracking). Using &self allows LLVM to optimize under the assumption that the context is read-only, which can corrupt nonce state and cause cryptographic failures. This was the root cause of cloudflare/quiche#2383.

Using &mut self universally (for both generic and TLS AEADs) is the simplest fix and prevents this class of bug entirely.

Also adds Algorithm constructors for the four TLS GCM variants:

  • aes_128_gcm_tls12 / aes_256_gcm_tls12
  • aes_128_gcm_tls13 / aes_256_gcm_tls13

These enforce strictly monotonic nonces at the AEAD level, matching the TLS 1.2 and TLS 1.3 nonce construction requirements.

Tests cover:

  • Round-trip seal/open for all TLS variants
  • TLS nonce monotonicity enforcement (reuse and backwards rejected)
  • Contrast: generic GCM accepts non-monotonic nonces

Change all seal/open methods on AeadCtxRef from &self to &mut self.

The TLS-specific AEADs (aes_*_gcm_tls12, aes_*_gcm_tls13) are stateful
and internally mutate the EVP_AEAD_CTX during seal operations (nonce
counter tracking). Using &self allows LLVM to optimize under the
assumption that the context is read-only, which can corrupt nonce state
and cause cryptographic failures. This was the root cause of
cloudflare/quiche#2383.

Using &mut self universally (for both generic and TLS AEADs) is the
simplest fix and prevents this class of bug entirely.

Also adds Algorithm constructors for the four TLS GCM variants:
- aes_128_gcm_tls12 / aes_256_gcm_tls12
- aes_128_gcm_tls13 / aes_256_gcm_tls13

These enforce strictly monotonic nonces at the AEAD level, matching the
TLS 1.2 and TLS 1.3 nonce construction requirements.

Tests cover:
- Round-trip seal/open for all TLS variants
- TLS nonce monotonicity enforcement (reuse and backwards rejected)
- Contrast: generic GCM accepts non-monotonic nonces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant