Skip to content

fix(aes): wipe AES round keys when the cipher is dropped - #1204

Merged
Pr0methean merged 1 commit into
zip-rs:masterfrom
Slurp9187:aes-round-key-zeroize
Oct 27, 2026
Merged

Pr0methean merged 1 commit into
zip-rs:masterfrom
Slurp9187:aes-round-key-zeroize

Conversation

@Slurp9187

@Slurp9187 Slurp9187 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

The aes crate zeroizes its expanded key on drop only when its zeroize feature is enabled. zip doesn't enable it, so the round keys of every AES entry stay in freed memory. The key stream's own buffer and counter have been wiped since #1196.

This enables the feature and adds a ZeroizeOnDrop bound on AesKind::Cipher. In aes 0.9.2 that marker trait and the wiping Drop are behind the same feature, so removing the feature later is a compile error rather than a silent regression. A runtime test would have to read the dropped cipher's memory, including padding, which isn't sound.

In release builds the wipe stays: the LLVM IR on x86-64 has a volatile zero over the whole cipher (704, 832 and 960 bytes for AES-128, -192 and -256).

It also raises zip's own zeroize requirement from 1.8 to 1.9, which the aes feature depends on; zeroize 1.9 needs Rust 1.85, so the MSRV is unaffected, and aes 0.9.2 with zeroize 1.9.1 resolves on it.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

The aes crate wipes its expanded key on drop only with its optional
zeroize feature, which was not enabled, so the round keys stayed in
freed memory after each AES entry. Enable the feature, and require
ZeroizeOnDrop on AesKind::Cipher so that dropping the feature again
fails to compile. Raise zeroize to 1.9, which that feature needs.
@Pr0methean
Pr0methean enabled auto-merge October 27, 2026 18:09
@Pr0methean
Pr0methean added this pull request to the merge queue Oct 27, 2026
Merged via the queue into zip-rs:master with commit 9865299 Oct 27, 2026
135 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants