Skip to content

Commit

Permalink
fix rand/random feature use in secp256k1_ecdsa & tests (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
semenov-vladyslav authored Jul 11, 2023
1 parent 85d6938 commit 51491f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/secp256k1-features-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"iota-crypto": patch
---

Fixed "rand"/"random" feature inconsistencies.
4 changes: 2 additions & 2 deletions src/signatures/secp256k1_ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub struct SecretKey(k256::ecdsa::SigningKey);
impl SecretKey {
pub const LENGTH: usize = 32;

#[cfg(feature = "random")]
#[cfg_attr(docsrs, doc(cfg(feature = "random")))]
#[cfg(all(feature = "rand", feature = "random"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "rand", feature = "random"))))]
pub fn generate() -> Self {
let mut rng = rand::rngs::OsRng;
Self(k256::ecdsa::SigningKey::random(&mut rng))
Expand Down
4 changes: 2 additions & 2 deletions tests/secp256k1_ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn run_secp256k1_sha256(sk: SecretKey, pk: PublicKey) {
assert_eq!(pk, sig.recover_sha256(&msg).unwrap());

assert!(pk.verify_sha256(sig2.as_ref(), &msg));
#[cfg(feature = "rand")]
#[cfg(all(feature = "rand", feature = "random"))]
assert!(!SecretKey::generate().public_key().verify_sha256(
&Signature::try_from_slice(&sig_bytes[..Signature::LENGTH]).unwrap(),
&msg
Expand Down Expand Up @@ -95,7 +95,7 @@ fn test_secp256k1_sign_verify() {
run_secp256k1_keccak256(sk, pk);
}

#[cfg(feature = "rand")]
#[cfg(all(feature = "rand", feature = "random"))]
#[test]
fn test_secp256k1_sign_verify_random() {
let sk = SecretKey::generate();
Expand Down

0 comments on commit 51491f0

Please sign in to comment.