Skip to content

hmac: Key<H> / Mac state does not implement Zeroize or ZeroizeOnDrop #255

@BeeFlea

Description

@BeeFlea

Summary

hmac::Hmac<H> (via the Mac trait) copies key material into internal state via new_from_slice(). When the Mac value is dropped after finalize(), the key copy persists in memory because neither Key<H> nor the HMAC internal state implements Zeroize or ZeroizeOnDrop.

Impact

Applications using HMAC for authentication (e.g. JWT signing) cannot zeroize the key material held inside the Mac state after use. The key copy is typically stack-local and short-lived, but for defense-in-depth this should be zeroizable.

CWE Reference

CWE-244 (Improper Clearing of Heap Data Before Release)

Suggestion

Add Zeroize and/or ZeroizeOnDrop implementations (possibly behind a zeroize feature flag, consistent with how other RustCrypto crates handle this) to the HMAC state types.

Version

Observed on hmac 0.12.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions