Skip to content

Commit

Permalink
dev-dependencies: replace the rust libsecp256k1 with the C bindings s…
Browse files Browse the repository at this point in the history
…ecp256k1 lib (#171)
  • Loading branch information
elichai authored May 18, 2022
1 parent 02c1328 commit 9193fb7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ cclst = ["class_group"]
subtle = { version = "2" }
serde = { version = "1.0", features = ["derive"] }
zeroize = "1"
libsecp256k1 = "0.3.2"
curv-kzen = { version = "0.9", default-features = false }
centipede = { version = "0.3", default-features = false }
zk-paillier = { version = "0.4.3", default-features = false }
Expand Down Expand Up @@ -67,6 +66,7 @@ surf = "2"
async-sse = "5"
anyhow = "1"
structopt = "0.3"
secp256k1 = { version = "0.20", features = ["global-context"]}

thiserror = "1.0.23"
round-based = { version = "0.1.4", features = ["dev"] }
Expand Down
11 changes: 5 additions & 6 deletions examples/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,25 @@ pub fn poll_for_p2p(
ans_vec
}

#[allow(dead_code)]
pub fn check_sig(
r: &Scalar<Secp256k1>,
s: &Scalar<Secp256k1>,
msg: &BigInt,
pk: &Point<Secp256k1>,
) {
use secp256k1::{verify, Message, PublicKey, PublicKeyFormat, Signature};
use secp256k1::{Message, PublicKey, Signature, SECP256K1};

let raw_msg = BigInt::to_bytes(msg);
let mut msg: Vec<u8> = Vec::new(); // padding
msg.extend(vec![0u8; 32 - raw_msg.len()]);
msg.extend(raw_msg.iter());

let msg = Message::parse_slice(msg.as_slice()).unwrap();
let msg = Message::from_slice(msg.as_slice()).unwrap();
let mut raw_pk = pk.to_bytes(false).to_vec();
if raw_pk.len() == 64 {
raw_pk.insert(0, 4u8);
}
let pk = PublicKey::parse_slice(&raw_pk, Some(PublicKeyFormat::Full)).unwrap();
let pk = PublicKey::from_slice(&raw_pk).unwrap();

let mut compact: Vec<u8> = Vec::new();
let bytes_r = &r.to_bytes().to_vec();
Expand All @@ -219,8 +218,8 @@ pub fn check_sig(
compact.extend(vec![0u8; 32 - bytes_s.len()]);
compact.extend(bytes_s.iter());

let secp_sig = Signature::parse_slice(compact.as_slice()).unwrap();
let secp_sig = Signature::from_compact(compact.as_slice()).unwrap();

let is_correct = verify(&msg, &secp_sig, &pk);
let is_correct = SECP256K1.verify(&msg, &secp_sig, &pk).is_ok();
assert!(is_correct);
}
10 changes: 5 additions & 5 deletions src/protocols/multi_party_ecdsa/gg_2018/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,14 @@ fn sign(t: u16, n: u16, ttag: u16, s: Vec<u16>) {
}

fn check_sig(r: &Scalar<Secp256k1>, s: &Scalar<Secp256k1>, msg: &BigInt, pk: &Point<Secp256k1>) {
use secp256k1::{verify, Message, PublicKey, PublicKeyFormat, Signature};
use secp256k1::{Message, PublicKey, Signature, SECP256K1};

let raw_msg = BigInt::to_bytes(msg);
let mut msg: Vec<u8> = Vec::new(); // padding
msg.extend(vec![0u8; 32 - raw_msg.len()]);
msg.extend(raw_msg.iter());

let msg = Message::parse_slice(msg.as_slice()).unwrap();
let msg = Message::from_slice(msg.as_slice()).unwrap();
let slice = pk.to_bytes(false);
let mut raw_pk = Vec::new();
if slice.len() != 65 {
Expand All @@ -425,7 +425,7 @@ fn check_sig(r: &Scalar<Secp256k1>, s: &Scalar<Secp256k1>, msg: &BigInt, pk: &Po

assert_eq!(raw_pk.len(), 65);

let pk = PublicKey::parse_slice(&raw_pk, Some(PublicKeyFormat::Full)).unwrap();
let pk = PublicKey::from_slice(&raw_pk).unwrap();

let mut compact: Vec<u8> = Vec::new();
let bytes_r = &r.to_bytes()[..];
Expand All @@ -436,9 +436,9 @@ fn check_sig(r: &Scalar<Secp256k1>, s: &Scalar<Secp256k1>, msg: &BigInt, pk: &Po
compact.extend(vec![0u8; 32 - bytes_s.len()]);
compact.extend(bytes_s.iter());

let secp_sig = Signature::parse_slice(compact.as_slice()).unwrap();
let secp_sig = Signature::from_compact(compact.as_slice()).unwrap();

let is_correct = verify(&msg, &secp_sig, &pk);
let is_correct = SECP256K1.verify(&msg, &secp_sig, &pk).is_ok();
assert!(is_correct);
}

Expand Down
17 changes: 6 additions & 11 deletions src/protocols/multi_party_ecdsa/gg_2020/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,20 +708,15 @@ fn sign(
Ok(sig)
}

pub fn check_sig(
r: &Scalar<Secp256k1>,
s: &Scalar<Secp256k1>,
msg: &BigInt,
pk: &Point<Secp256k1>,
) {
use secp256k1::{verify, Message, PublicKey, PublicKeyFormat, Signature};
fn check_sig(r: &Scalar<Secp256k1>, s: &Scalar<Secp256k1>, msg: &BigInt, pk: &Point<Secp256k1>) {
use secp256k1::{Message, PublicKey, Signature, SECP256K1};

let raw_msg = BigInt::to_bytes(msg);
let mut msg: Vec<u8> = Vec::new(); // padding
msg.extend(vec![0u8; 32 - raw_msg.len()]);
msg.extend(raw_msg.iter());

let msg = Message::parse_slice(msg.as_slice()).unwrap();
let msg = Message::from_slice(msg.as_slice()).unwrap();
let slice = pk.to_bytes(false);
let mut raw_pk = Vec::new();
if slice.len() != 65 {
Expand All @@ -735,7 +730,7 @@ pub fn check_sig(

assert_eq!(raw_pk.len(), 65);

let pk = PublicKey::parse_slice(&raw_pk, Some(PublicKeyFormat::Full)).unwrap();
let pk = PublicKey::from_slice(&raw_pk).unwrap();

let mut compact: Vec<u8> = Vec::new();
let bytes_r = &r.to_bytes()[..];
Expand All @@ -746,9 +741,9 @@ pub fn check_sig(
compact.extend(vec![0u8; 32 - bytes_s.len()]);
compact.extend(bytes_s.iter());

let secp_sig = Signature::parse_slice(compact.as_slice()).unwrap();
let secp_sig = Signature::from_compact(compact.as_slice()).unwrap();

let is_correct = verify(&msg, &secp_sig, &pk);
let is_correct = SECP256K1.verify(&msg, &secp_sig, &pk).is_ok();
assert!(is_correct);
}
#[test]
Expand Down

0 comments on commit 9193fb7

Please sign in to comment.