mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Overwrite secret key material with zeroes on drop.
This commit is contained in:
parent
494c4628c2
commit
d896886691
1 changed files with 15 additions and 0 deletions
|
|
@ -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`.
|
||||
|
|
|
|||
Loading…
Reference in a new issue