Skip to content

Commit

Permalink
No panic when new_random generates invalid value (#114)
Browse files Browse the repository at this point in the history
* No panic when new_random generates invalid value

* Using SecretKey::new to randomize Secp256k1Scalar
  • Loading branch information
jimmyyip-crypto authored May 9, 2021
1 parent 7b70e98 commit fece92f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/elliptic/curves/secp256_k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crypto::digest::Digest;
use crypto::sha3::Sha3;
#[cfg(feature = "merkle")]
use merkle::Hashable;
use rand::{thread_rng, Rng};
use rand::thread_rng;
use secp256k1::constants::{
CURVE_ORDER, GENERATOR_X, GENERATOR_Y, SECRET_KEY_SIZE, UNCOMPRESSED_PUBLIC_KEY_SIZE,
};
Expand Down Expand Up @@ -94,11 +94,9 @@ impl ECScalar for Secp256k1Scalar {
type SecretKey = SK;

fn new_random() -> Secp256k1Scalar {
let mut arr = [0u8; 32];
thread_rng().fill(&mut arr[..]);
Secp256k1Scalar {
purpose: "random",
fe: SK::from_slice(&arr[0..arr.len()]).unwrap(),
fe: SecretKey::new(&mut thread_rng()),
}
}

Expand Down

0 comments on commit fece92f

Please sign in to comment.