Skip to content

xaes-256-gcm: add zeroize feature (#863) - #863

Merged
tarcieri merged 1 commit into
RustCrypto:masterfrom
eligrubb:zeroize-xaes-256-gcm
Aug 11, 2026
Merged

xaes-256-gcm: add zeroize feature (#863)#863
tarcieri merged 1 commit into
RustCrypto:masterfrom
eligrubb:zeroize-xaes-256-gcm

Conversation

@eligrubb

Copy link
Copy Markdown
Contributor

Fixes #862, adding optional zeroize feature to xaes-256-gcm crate.

Follows pattern of other crates, using marker trait ZeroizeOnDrop to cascade trait to underlying Aes256. Zeroizes k1 block on drop. When feature is enabled, zeroizes local variable k that contains raw key material.

As part of this PR, the helper method derive_key's signature was changed to avoid cloning sensitive key material on the stack. Instead, the helper now accepts a pointer to the key material and modifies it in place. This avoids the helper method copying key material into its local stack, which is not zeroized when derive_key returns.

Comment thread xaes-256-gcm/src/lib.rs
// Kₘ = AES-256ₖ(M1 ⊕ K1)
// Kₙ = AES-256ₖ(M2 ⊕ K1)
// Kₓ = Kₘ || Kₙ = AES-256ₖ(M1 ⊕ K1) || AES-256ₖ(M2 ⊕ K1)
let mut key: Key<Aes256Gcm> = Array::default();

@eligrubb eligrubb Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it was, this helper method would allocate key on the local stack, and then copy raw key material into it. Then, it would copy the result into the return buffer, never clearing the stack-allocated key material. This PR instead allocated the key buffer first, before calling derive_key, and passes in a reference.

@tarcieri tarcieri changed the title Add zeroize feature to xaes-256-gcm crate xaes-256-gcm: add zeroize feature (#863) Aug 11, 2026
@tarcieri
tarcieri merged commit 9621863 into RustCrypto:master Aug 11, 2026
126 checks passed
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.

xaes-256-gcm: zeroize feature is not implemented for crate

2 participants