Skip to content

feat(aes-gcm): detached AES-256-GCM seal/open primitive (hazmat-explicit-nonce) - #32

Merged
jgowdy merged 1 commit into
mainfrom
feat/aes-gcm-detached-primitive
Jun 20, 2026
Merged

jgowdy merged 1 commit into
mainfrom
feat/aes-gcm-detached-primitive

Conversation

@jgowdy

@jgowdy jgowdy commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a protocol-neutral detached AEAD primitive to HardwareAes256GcmKeyState, behind the existing hazmat-explicit-nonce feature (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:

seal_detached(nonce, aad, plaintext)        -> (ciphertext, tag)
seal_in_place_detached(nonce, aad, &mut b)  -> tag
open_detached(nonce, aad, ciphertext, tag)  -> plaintext
open_in_place_detached(nonce, aad, &mut b, tag) -> ()

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

  • New KeyState helpers (seal_detached / seal_in_place_detached / open_detached / open_in_place_detached) built on the existing seal / seal_in_place / open / open_in_place paths, reusing the same constant_time_eq tag comparison and zeroize-on-failure behavior as decrypt.
  • Thin #[doc(hidden)], feature-gated public wrappers on HardwareAes256GcmKeyState, mirroring how encrypt_nonce_appended is exposed.

Tests

Run under the test cfg:

  • detached seal/open round-trip with AAD;
  • in-place vs allocating equivalence (ciphertext + tag byte-identical);
  • byte-for-byte agreement with the validated nonce-appended path (detached ct||tag == envelope minus its trailing nonce);
  • exact reproduction of a NIST CAVP AES-256-GCM vector through the detached explicit-nonce seal (the core reason the primitive exists);
  • rejection of wrong tag, wrong AAD, wrong tag length, and bad nonce length.

Notes

  • Default build and cargo clippy --workspace --all-targets -- -D warnings (the CI lint invocation, which does not enable hazmat-explicit-nonce) stay green; the lib is also clippy-clean under --features hazmat-explicit-nonce.
  • Pre-existing cast/try_from clippy lints in tests/openssl_interop.rs surface only under clippy --features hazmat-explicit-nonce --all-targets (a combination CI does not run; confirmed present on main before this change). Untouched here.

…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
jgowdy merged commit 98eee7a into main Jun 20, 2026
23 checks passed
jgowdy added a commit that referenced this pull request Jun 20, 2026
Detached AES-256-GCM seal/open primitive (#32) and robust CPU feature
detection under -Zbuild-std / sanitizers (#33).

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
Detached AES-256-GCM seal/open primitive (#32) and robust CPU feature
detection under -Zbuild-std / sanitizers (#33).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jgowdy
jgowdy deleted the feat/aes-gcm-detached-primitive branch June 20, 2026 22:42
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
Detached AES-256-GCM seal/open primitive (#32) and robust CPU feature
detection under -Zbuild-std / sanitizers (#33).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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