Skip to content

fix(aes-gcm): reject empty nonces - #885

Open
thevilledev wants to merge 1 commit into
RustCrypto:masterfrom
thevilledev:fix/aes-gcm-empty-nonce
Open

fix(aes-gcm): reject empty nonces#885
thevilledev wants to merge 1 commit into
RustCrypto:masterfrom
thevilledev:fix/aes-gcm-empty-nonce

Conversation

@thevilledev

Copy link
Copy Markdown

Summary

Running the Wycheproof AES-GCM vectors exposed failures for the ZeroLengthIv cases. A zero-length nonce violates NIST SP 800-38D and can disclose the GHASH authentication key.

Changes

  • Add a sealed NonceSize bound requiring non-zero nonce sizes.
  • Apply the bound to every AesGcm implementation, preventing bypasses.
  • Make invalid zero-length configurations unrepresentable at compile time.
  • Add a compile-fail regression for AesGcm<Aes128, U0>.

Tests

Tests pass.

Zero-length nonces violate NIST SP 800-38D and expose the GHASH
authentication key when encrypting an empty message. Reject them at the
type level and cover the invariant with a compile-fail example.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
@tarcieri

tarcieri commented Sep 5, 2026

Copy link
Copy Markdown
Member

This is probably a good idea in general but it's also imposing a new bound on a generic parameter, which is a breaking change: anyone using it in a generic context will need to propagate this bound.

@newpavlov

Copy link
Copy Markdown
Member

As a temporary solution we could panic on empty nonces. I doubt that anyone uses the crate with them, so it should not affect anyone while serving as a guard against misuse.

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.

3 participants