Skip to content

Commit

Permalink
Merge pull request #12 from dusk-network/mocello/improve_zeroize
Browse files Browse the repository at this point in the history
Add safety comment for `SecretKey`
  • Loading branch information
moCello authored Apr 23, 2024
2 parents 2d78f2e + d43f221 commit 0009b20
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ license = "MPL-2.0"
dusk-bls12_381 = { version = "0.13", default-features = false, features = ["alloc", "pairings", "zeroize"] }
dusk-bytes = "0.1"
rand_core = { version = "0.6", default-features = false }
ff = { version = "0.13", default-features = false }
zeroize = { version = "1", default-features = false, features = ["derive"] }
rkyv = { version = "0.7", optional = true, default-features = false }
bytecheck = { version = "0.6", optional = true, default-features = false }
ff = { version = "0.13", default-features = false }
rayon = { version = "1.8", optional = true }
zeroize = { version = "1", features = ["zeroize_derive"] }

[dev-dependencies]
rand = { version = "0.8", default-features = false, features = ["std_rng"] }
Expand Down
23 changes: 23 additions & 0 deletions src/keys/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ use rkyv::{Archive, Deserialize, Serialize};

/// A BLS secret key, holding a BLS12-381 scalar inside.
/// Can be used for signing messages.
///
/// ## Safety
///
/// To ensure that no secret information lingers in memory after the variable
/// goes out of scope, we advice calling `zeroize` before the variable goes out
/// of scope.
///
/// ## Examples
///
/// Generate a random `SecretKey`:
/// ```
/// use bls12_381_bls::SecretKey;
/// use rand::rngs::StdRng;
/// use rand::SeedableRng;
/// use zeroize::Zeroize;
///
/// let mut rng = StdRng::seed_from_u64(12345);
/// let mut sk = SecretKey::random(&mut rng);
///
/// // do something with the sk
///
/// sk.zeroize();
/// ```
#[derive(Default, Clone, Debug, Eq, PartialEq, Zeroize)]
#[cfg_attr(
feature = "rkyv-impl",
Expand Down

0 comments on commit 0009b20

Please sign in to comment.