feat(ml-kem): add zeroize support and tests#1332
Open
rainmitch wants to merge 1 commit intocryspen:mainfrom
Open
feat(ml-kem): add zeroize support and tests#1332rainmitch wants to merge 1 commit intocryspen:mainfrom
rainmitch wants to merge 1 commit intocryspen:mainfrom
Conversation
d2bb7f8 to
b99428c
Compare
Author
|
Just a heads-up. I've also successfully applied this same hardening pattern to the ML-DSA module locally. I'll open a separate PR for that one if these changes are wanted and once I have feedback on this PR and on your preferences. |
Collaborator
|
Thank you for the effort on this! |
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.
Description:
This PR introduces memory hardening for ML-KEM secret keys by implementing the Zeroize and ZeroizeOnDrop traits. The goal is to ensure sensitive key material is securely wiped from memory when it goes out of scope. This facilitates FIPS 140-3 compliance (AS05.10) regarding the zeroization of plaintext secret keys.
Scope:
This implementation focuses on the secret-holding structs and their underlying vector types. It does not modify the underlying core logic or seed inputs (which very likely needs more work to fully implement zeroize). I believe this covers all primary secret-holding structs in a non-intrusive way required for memory hardening.
This is implemented as an optional feature that requires being enabled.
Changes:
I have implemented Zeroize for the following types:
I have implemented ZeroizeOnDrop for the following types:
Technical Verification:
To ensure the security features are not optimized away by the compiler, I performed the following checks:
Assembly Audit:
Performance:
Benchmarks show a negligible performance impact (performed on a Ryzen 5 7430u):
Closing Notes:
Note: I am not a security programmer or researcher. I have tried to implement this to the best of my abilities, verifying the assembly output to ensure the compiler respects the zeroing instructions. I really like libcrux and wanted to use it for a project, but also need zeroize functionality, so I worked to try to implement it. I have tried to do my due diligence in checking and design. I would very much appreciate someone double checking my work, especially as this is my first contribution to a project. But I believe that this works.
I would greatly appreciate feedback and comments on anything that needs to be changed.