Repository navigation
Conversation
|
Thanks for making the hash-state guarantee checkable. Could the docs clarify which features clear the HMAC block buffer and the underlying hash state, for example with A short note linking to the stack-zeroization discussion would also help readers understand the scope for the ipad/opad scratch block, the inner digest, and the long-key digest in 0.13.0. Compiler-generated copies and spills are outside scope. |
This branch has not been deployed
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.
With the
zeroizefeature enabled, droppingHmac<D>/HmacReset<D>already clears their state when the hash core does: the innerD::Coreinstances zeroize on drop (e.g.sha2with itszeroizefeature) and theBlockBufferis zeroized viadigest/zeroize. However, no HMAC type implements theZeroizeOnDropmarker, so downstream code cannot assert this at compile time.This adds
ZeroizeOnDropforHmacCore,HmacResetCore,HmacandHmacResetbehind thezeroizefeature, bounded onD::Core: ZeroizeOnDrop, following the pattern used by the other crates in this repo. TheZeroizeOnDroparm ofbuffer_fixed!is not used because it emits an unconditional impl, which would be incorrect for hash cores that do not zeroize.As suggested by @tarcieri in #255. Stack temporaries remain out of scope.
Motivation
Without the marker, downstream code has two options, both visible in the wild:
<Sha512 as CoreProxy>::CoreandBuffer<Core<Sha512>>, which silently stops coveringHmacif its layout changes.hmacentirely for secret keys. krusty-kms reimplements HMAC on top ofsha2and requiresD: ZeroizeOnDrop, so that dropping thezeroizefeature fails the build.It also makes a missing feature detectable. Some projects derive keys from seeds through
Hmac<Sha512>(e.g. BIP-32 / SLIP-10) while zeroizing their own key types, but buildhmacandsha2withoutzeroize, leaving the HMAC state in memory. With this change, a singleassert_zeroize_on_drop::<Hmac<Sha512>>()catches that at compile time.