RustCrypto / RustCrypto/traits

Making sure SecretKey is zeroized on drop

Open
#671 3 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.