Overwrite secret key material with zeroes on drop.

This commit is contained in:
Isis Lovecruft 2018-07-20 20:20:40 +00:00
parent 494c4628c2
commit d896886691
Failed to extract signature

View file

@ -173,6 +173,13 @@ impl Debug for SecretKey {
}
}
/// Overwrite secret key material with null bytes when it goes out of scope.
impl Drop for SecretKey {
fn drop(&mut self) {
self.0 = [0u8; SECRET_KEY_LENGTH];
}
}
impl SecretKey {
/// Expand this `SecretKey` into an `ExpandedSecretKey`.
pub fn expand<D>(&self) -> ExpandedSecretKey where D: Digest<OutputSize = U64> + Default {
@ -375,6 +382,14 @@ pub struct ExpandedSecretKey {
pub (crate) nonce: [u8; 32],
}
/// Overwrite secret key material with null bytes when it goes out of scope.
impl Drop for ExpandedSecretKey {
fn drop(&mut self) {
self.key = Scalar::zero();
self.nonce = [0u8; 32];
}
}
#[cfg(feature = "sha2")]
impl<'a> From<&'a SecretKey> for ExpandedSecretKey {
/// Construct an `ExpandedSecretKey` from a `SecretKey`.