Skip to content

Commit

Permalink
Speed up compilation by avoiding zeroize_derive
Browse files Browse the repository at this point in the history
  • Loading branch information
spacejam authored and mkj committed May 28, 2022
1 parent 4194e36 commit 6c039ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -30,7 +30,7 @@ rand_core = { version = "0.6", default-features = false, optional = true }
serde_crate = { package = "serde", version = "1.0", default-features = false, optional = true }
serde_bytes = { version = "0.11", default-features = false, optional = true }
sha2 = { version = "0.10", default-features = false }
zeroize = { version = "1", default-features = false, features = ["zeroize_derive"] }
zeroize = { version = "1", default-features = false }

[dev-dependencies]
hex = "^0.4"
Expand Down
17 changes: 13 additions & 4 deletions src/secret.rs
Expand Up @@ -40,10 +40,14 @@ use crate::signature::*;
///
/// Instances of this secret are automatically overwritten with zeroes when they
/// fall out of scope.
#[derive(Zeroize)]
#[zeroize(drop)] // Overwrite secret key material with null bytes when it goes out of scope.
pub struct SecretKey(pub(crate) [u8; SECRET_KEY_LENGTH]);

impl Drop for SecretKey {
fn drop(&mut self) {
self.0.zeroize()
}
}

impl Debug for SecretKey {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write!(f, "SecretKey: {:?}", &self.0[..])
Expand Down Expand Up @@ -235,13 +239,18 @@ impl<'d> Deserialize<'d> for SecretKey {
// same signature scheme, and which both fail in exactly the same way. For a
// better-designed, Schnorr-based signature scheme, see Trevor Perrin's work on
// "generalised EdDSA" and "VXEdDSA".
#[derive(Zeroize)]
#[zeroize(drop)] // Overwrite secret key material with null bytes when it goes out of scope.
pub struct ExpandedSecretKey {
pub(crate) key: Scalar,
pub(crate) nonce: [u8; 32],
}

impl Drop for ExpandedSecretKey {
fn drop(&mut self) {
self.key.zeroize();
self.nonce.zeroize()
}
}

impl<'a> From<&'a SecretKey> for ExpandedSecretKey {
/// Construct an `ExpandedSecretKey` from a `SecretKey`.
///
Expand Down

0 comments on commit 6c039ec

Please sign in to comment.