RustCrypto / RustCrypto/traits
Making sure SecretKey is zeroized on drop
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 755
- Forks
- 256
- Avg merge
- 1h 27m
- Merged PRs (30d)
- 2
Description
I was trying to make my newtype of SecretKey zeroize properly, and realized I can't even trigger zeroization for SecretKey itself. Consider the code:
use k256::SecretKey;
use rand_core::OsRng;
fn main() {
let sk = SecretKey::random(&mut OsRng);
let ptr = &sk as *const SecretKey;
let ptr_u8 = ptr as *const u8;
println!("Pointer: {:p}", ptr);
drop(sk);
println!("Memory: {:?}", unsafe {
core::slice::from_raw_parts(ptr_u8, 4)
});
}
k256 has zeroize feature enabled in Cargo.toml. This still gives a non-zero output after SecretKey was dropped, despite there being a Drop implementation in secret_key.rs that calls zeroize(). Am I misunderstanding something?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied example with the zeroize feature enabled, then inspect the Drop implementation in secret_key.rs and the feature configuration in Cargo.toml. Determine whether the observed memory contents match the intended zeroization behavior and document or correct the behavior, with a focused regression test if the repository’s existing tests provide a suitable location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cryptography
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100