Skip to content

Conversation

@chiro-hiro
Copy link

Motivation

  1. Remove Copy from Entropy to make sure that this value won't be copied without notice, since anyone can reconstruct private key from this entropy
  2. Implement Drop for Entropy make sure entropy will be cleaned up as soon as we leave the block

@chiro-hiro
Copy link
Author

May related to #15

@prestwich
Copy link
Member

Remove Copy from Entropy to make sure that this value won't be copied without notice, since anyone can reconstruct private key from this entropy

unforunately, given rust's move semantics and optimization, removing copy does not ensure that the value won't be copied. data moves (e.g. between scopes or between bindings) are generally memcpy and invalidation of the old version, even for types that are !Copy

consider this code:

use std::sync::atomic::{AtomicU8, Ordering};

pub fn increment_me(cell: AtomicU8) -> AtomicU8 {
    cell.fetch_add(1, Ordering::Relaxed);
    cell
}

fn my_func() {
    let my_cell = AtomicU8::new(3);
    let my_cell_2 = increment_me(my_cell);

    drop(my_cell_2)
}

Despite having no clones, it is up to the compiler's discretion whether shallow copies of the atomic get re-produced in memory or in registers during the call to increment_me. the move semantics invalidate old memory locations but do not cause Drop code to be run on those locations

@chiro-hiro
Copy link
Author

Hi @prestwich, would love to work on #15.

@prestwich
Copy link
Member

you're welcome to contribute, the first thing to work on would be a well-researched plan. I would love to see some discussion of how secrets/zeroize handle this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants