Skip to content

Commit

Permalink
Adding zeroize on drop for VRFExpandedPrivateKey (facebook#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlewi authored Sep 21, 2023
1 parent ce9f951 commit a53939d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions akd_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ed25519-dalek = { version = "2", features = [
"legacy_compatibility",
], optional = true }
hex = "0.4"
zeroize = "1"

## Optional dependencies ##
blake3 = { version = "1", optional = true, default-features = false }
Expand Down
10 changes: 10 additions & 0 deletions akd_core/src/ecvrf/ecvrf_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use curve25519_dalek::{
edwards::{CompressedEdwardsY, EdwardsPoint},
scalar::Scalar as ed25519_Scalar,
};
use zeroize::{Zeroize, ZeroizeOnDrop};

/// The length of a node-label's value field in bytes.
/// This is used for truncation of the hash to this many bytes
Expand Down Expand Up @@ -90,6 +91,15 @@ pub struct VRFExpandedPrivateKey {
pub(super) nonce: [u8; 32],
}

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

impl ZeroizeOnDrop for VRFExpandedPrivateKey {}

impl VRFPrivateKey {
/// Produces a proof for an input (using the private key)
pub fn prove(&self, alpha: &[u8]) -> Proof {
Expand Down

0 comments on commit a53939d

Please sign in to comment.