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

@thevilledev thevilledev commented Sep 5, 2026

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 an inline const assertion requiring non-zero nonce sizes.
  • Enforce the assertion in the counter initialization shared by encryption and decryption.
  • Add a compile-fail regression for AesGcm<Aes128, U0>.

Tests

Tests pass.

@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.

@tarcieri

tarcieri commented Sep 8, 2026

Copy link
Copy Markdown
Member

Hmm, would a const assert work, or would it complain about the outer generic parameter?

@thevilledev

Copy link
Copy Markdown
Author

Hmm, would a const assert work, or would it complain about the outer generic parameter?

Good idea. I'll think the only caveat is that cargo check doesn't detect it? I'll try this out

Zero-length nonces violate NIST SP 800-38D and can expose the GHASH
key. Prevent encryption and decryption with them from compiling.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
@thevilledev
thevilledev force-pushed the fix/aes-gcm-empty-nonce branch from 82ddead to 4ce9015 Compare September 8, 2026 17:32
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