Repository navigation
fix(aes): wipe AES round keys when the cipher is dropped - #1204
Merged
Merged
Conversation
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
approved these changes
Oct 27, 2026
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.
The
aescrate zeroizes its expanded key on drop only when itszeroizefeature is enabled. zip doesn't enable it, so the round keys of every AES entry stay in freed memory. The key stream's ownbufferandcounterhave been wiped since #1196.This enables the feature and adds a
ZeroizeOnDropbound onAesKind::Cipher. In aes 0.9.2 that marker trait and the wipingDropare 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
zeroizerequirement from 1.8 to 1.9, which theaesfeature 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.Need help on this PR? Tag
@codesmith-botwith what you need.