Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update secp256k1 dependency, remove rand_legacy. #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ num-traits = "0.2"
num-integer = "0.1"
pairing-plus = "0.19"
rand = "0.7"
rand_legacy = { package = "rand", version = "0.6" }
serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.11"
serde_derive = "1.0"
Expand All @@ -43,7 +42,7 @@ rust-gmp-kzen = { version = "0.5", features = ["serde_support"], optional = true
num-bigint = { version = "0.4", features = ["serde"], optional = true }

[dependencies.secp256k1]
version = "0.20"
version = "0.24"
features = ["serde", "rand-std", "global-context"]

[dependencies.p256]
Expand Down
13 changes: 8 additions & 5 deletions src/elliptic/curves/secp256_k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use generic_array::GenericArray;
use secp256k1::constants::{
self, GENERATOR_X, GENERATOR_Y, SECRET_KEY_SIZE, UNCOMPRESSED_PUBLIC_KEY_SIZE,
};
use secp256k1::{PublicKey, SecretKey, SECP256K1};
use secp256k1::{scalar::Scalar, PublicKey, SecretKey, SECP256K1};
use serde::{Deserialize, Serialize};
use zeroize::{Zeroize, Zeroizing};

Expand Down Expand Up @@ -161,7 +161,7 @@ impl ECScalar for Secp256k1Scalar {
type ScalarLength = typenum::U32;

fn random() -> Secp256k1Scalar {
let sk = SK(SecretKey::new(&mut rand_legacy::thread_rng()));
let sk = SK(SecretKey::new(&mut secp256k1::rand::thread_rng()));
Secp256k1Scalar {
purpose: "random",
fe: Zeroizing::new(Some(sk)),
Expand Down Expand Up @@ -233,7 +233,8 @@ impl ECScalar for Secp256k1Scalar {
(left, None) => left.clone(),
(Some(left), Some(right)) => {
let mut res = left.clone();
res.add_assign(&right.0[..]).ok().map(|_| res) // right might be the negation of left.
let scalar = Scalar::from_be_bytes(*right.0.as_ref()).unwrap();
res.add_assign(&scalar).ok().map(|_| res) // right might be the negation of left.
}
};

Expand All @@ -248,8 +249,9 @@ impl ECScalar for Secp256k1Scalar {
(None, _) | (_, None) => None,
(Some(left), Some(right)) => {
let mut res = left.clone();
let scalar = Scalar::from_be_bytes(*right.0.as_ref()).unwrap();
res.0
.mul_assign(&right.0[..])
.mul_assign(&scalar)
.expect("Can't fail as it's a valid secret");
Some(res)
}
Expand Down Expand Up @@ -483,7 +485,8 @@ impl ECPoint for Secp256k1Point {
self.ge = None;
}
(Some(ge), Some(fe)) => {
ge.0.mul_assign(SECP256K1, &fe.0[..])
let scalar = Scalar::from_be_bytes(*fe.0.as_ref()).unwrap();
ge.0.mul_assign(SECP256K1, &scalar)
.expect("Can't fail as it's a valid secret");
}
};
Expand Down