Repository navigation
feat(aes-gcm): detached AES-256-GCM seal/open primitive (hazmat-explicit-nonce) - #32
Merged
Merged
Conversation
…nce) Add a protocol-neutral detached AEAD primitive to HardwareAes256GcmKeyState, gated behind `hazmat-explicit-nonce` (off by default): - seal_detached(nonce, aad, plaintext) -> (ciphertext, tag) - seal_in_place_detached(nonce, aad, &mut buf) -> tag - open_detached(nonce, aad, ciphertext, tag) -> plaintext - open_in_place_detached(nonce, aad, &mut buf, tag) -> () These take a caller-supplied nonce and AAD, return the tag separately, and do NOT append the nonce — the caller owns nonce construction, AAD, and framing. This is the honest primitive a record layer (e.g. a rustls AEAD provider) or a standards known-answer test needs; it is not protocol-specific. For general use callers should still prefer `encrypt`, which generates a proven non-repeating nonce internally. Implemented in terms of the existing seal/seal_in_place/ open/open_in_place building blocks with the same constant-time tag comparison and zeroize-on-failure behavior as `decrypt`. Tests (run under the test cfg): detached seal/open round-trip with AAD, in-place vs allocating equivalence, byte-for-byte agreement with the nonce-appended path, exact reproduction of a NIST CAVP AES-256-GCM vector through the detached explicit-nonce seal, and rejection of wrong tag / wrong AAD / bad nonce length. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jgowdy
added a commit
that referenced
this pull request
Jun 20, 2026
…nce) (#32) Add a protocol-neutral detached AEAD primitive to HardwareAes256GcmKeyState, gated behind `hazmat-explicit-nonce` (off by default): - seal_detached(nonce, aad, plaintext) -> (ciphertext, tag) - seal_in_place_detached(nonce, aad, &mut buf) -> tag - open_detached(nonce, aad, ciphertext, tag) -> plaintext - open_in_place_detached(nonce, aad, &mut buf, tag) -> () These take a caller-supplied nonce and AAD, return the tag separately, and do NOT append the nonce — the caller owns nonce construction, AAD, and framing. This is the honest primitive a record layer (e.g. a rustls AEAD provider) or a standards known-answer test needs; it is not protocol-specific. For general use callers should still prefer `encrypt`, which generates a proven non-repeating nonce internally. Implemented in terms of the existing seal/seal_in_place/ open/open_in_place building blocks with the same constant-time tag comparison and zeroize-on-failure behavior as `decrypt`. Tests (run under the test cfg): detached seal/open round-trip with AAD, in-place vs allocating equivalence, byte-for-byte agreement with the nonce-appended path, exact reproduction of a NIST CAVP AES-256-GCM vector through the detached explicit-nonce seal, and rejection of wrong tag / wrong AAD / bad nonce length. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jgowdy
added a commit
that referenced
this pull request
Jun 20, 2026
…nce) (#32) Add a protocol-neutral detached AEAD primitive to HardwareAes256GcmKeyState, gated behind `hazmat-explicit-nonce` (off by default): - seal_detached(nonce, aad, plaintext) -> (ciphertext, tag) - seal_in_place_detached(nonce, aad, &mut buf) -> tag - open_detached(nonce, aad, ciphertext, tag) -> plaintext - open_in_place_detached(nonce, aad, &mut buf, tag) -> () These take a caller-supplied nonce and AAD, return the tag separately, and do NOT append the nonce — the caller owns nonce construction, AAD, and framing. This is the honest primitive a record layer (e.g. a rustls AEAD provider) or a standards known-answer test needs; it is not protocol-specific. For general use callers should still prefer `encrypt`, which generates a proven non-repeating nonce internally. Implemented in terms of the existing seal/seal_in_place/ open/open_in_place building blocks with the same constant-time tag comparison and zeroize-on-failure behavior as `decrypt`. Tests (run under the test cfg): detached seal/open round-trip with AAD, in-place vs allocating equivalence, byte-for-byte agreement with the nonce-appended path, exact reproduction of a NIST CAVP AES-256-GCM vector through the detached explicit-nonce seal, and rejection of wrong tag / wrong AAD / bad nonce length. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a protocol-neutral detached AEAD primitive to
HardwareAes256GcmKeyState, behind the existinghazmat-explicit-noncefeature (off by default). This is the honest building block a record layer (a future rustls AEAD provider) or a standards known-answer test needs — caller supplies the nonce and AAD, gets the tag back separately, and no nonce is appended:It is deliberately not TLS- (or any-protocol-) specific: the protocol layer owns nonce construction, AAD, and framing; this crate owns only the AEAD math. For general use callers should still prefer
encrypt, which generates a proven non-repeating nonce internally — these explicit-nonce entry points exist solely for the cases that genuinely need to reproduce an externally-fixed nonce (test vectors, a protocol-mandated construction).Implementation
KeyStatehelpers (seal_detached/seal_in_place_detached/open_detached/open_in_place_detached) built on the existingseal/seal_in_place/open/open_in_placepaths, reusing the sameconstant_time_eqtag comparison and zeroize-on-failure behavior asdecrypt.#[doc(hidden)], feature-gated public wrappers onHardwareAes256GcmKeyState, mirroring howencrypt_nonce_appendedis exposed.Tests
Run under the test cfg:
ct||tag== envelope minus its trailing nonce);Notes
cargo clippy --workspace --all-targets -- -D warnings(the CI lint invocation, which does not enablehazmat-explicit-nonce) stay green; the lib is also clippy-clean under--features hazmat-explicit-nonce.cast/try_fromclippy lints intests/openssl_interop.rssurface only underclippy --features hazmat-explicit-nonce --all-targets(a combination CI does not run; confirmed present onmainbefore this change). Untouched here.