Skip to content

Commit e551795

Browse files
committed
Zeroing secret keys on drop operations
1 parent 2694a35 commit e551795

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

secp256k1-sys/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ pub struct KeyPair([c_uchar; 96]);
224224
impl_array_newtype!(KeyPair, c_uchar, 96);
225225
impl_raw_debug!(KeyPair);
226226

227+
impl Drop for KeyPair {
228+
fn drop(&mut self) {
229+
self.0.copy_from_slice(&[0u8; 96]);
230+
}
231+
}
232+
227233
impl KeyPair {
228234
/// Creates an "uninitialized" FFI keypair which is zeroed out
229235
///

src/key.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ pub struct SecretKey(pub(crate) [u8; constants::SECRET_KEY_SIZE]);
3232
impl_ptr_newtype!(SecretKey, u8);
3333
impl_safe_debug!(SecretKey);
3434

35+
impl Drop for SecretKey {
36+
fn drop(&mut self) {
37+
self.0.copy_from_slice(&[0u8; constants::SECRET_KEY_SIZE]);
38+
}
39+
}
40+
3541
impl str::FromStr for SecretKey {
3642
type Err = Error;
3743
fn from_str(s: &str) -> Result<SecretKey, Error> {

0 commit comments

Comments
 (0)