Skip to content

Commit

Permalink
Zeroing secret keys on drop operations
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jun 19, 2021
1 parent 2694a35 commit e551795
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions secp256k1-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ pub struct KeyPair([c_uchar; 96]);
impl_array_newtype!(KeyPair, c_uchar, 96);
impl_raw_debug!(KeyPair);

impl Drop for KeyPair {
fn drop(&mut self) {
self.0.copy_from_slice(&[0u8; 96]);
}
}

impl KeyPair {
/// Creates an "uninitialized" FFI keypair which is zeroed out
///
Expand Down
6 changes: 6 additions & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ pub struct SecretKey(pub(crate) [u8; constants::SECRET_KEY_SIZE]);
impl_ptr_newtype!(SecretKey, u8);
impl_safe_debug!(SecretKey);

impl Drop for SecretKey {
fn drop(&mut self) {
self.0.copy_from_slice(&[0u8; constants::SECRET_KEY_SIZE]);
}
}

impl str::FromStr for SecretKey {
type Err = Error;
fn from_str(s: &str) -> Result<SecretKey, Error> {
Expand Down

0 comments on commit e551795

Please sign in to comment.