Skip to content

Commit

Permalink
Use curv from crates.io and bump version (#44)
Browse files Browse the repository at this point in the history
* Bump curv version to 0.7 and centipede to 0.2.12

* Fix code after updating curv to 0.7

* Bump version to 0.4.4
  • Loading branch information
elichai authored May 13, 2021
1 parent 384d904 commit ec5fb69
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "multi-party-schnorr"
version = "0.4.3"
version = "0.4.4"
authors = [
"Omer <omer@kzencorp.com>",
"Gary <gary@kzencorp.com>",
Expand All @@ -13,11 +13,11 @@ crate-type = ["lib"]
[dependencies]
serde = "1.0"
serde_derive = "1.0"
curv = { git = "https://github.com/KZen-networks/curv" , tag = "v0.5.9"}
curv = { package = "curv-kzen", version = "0.7" }

[dependencies.centipede]
git = "https://github.com/KZen-networks/centipede"
tag = "v0.2.9"
tag = "v0.2.12"

[dev-dependencies]
hex = "0.3.2"
Expand Down
10 changes: 5 additions & 5 deletions src/protocols/aggsig/musig_three_rounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl EphemeralKey {
pub fn create_from_private_key(x1: &KeyPair, message: &[u8]) -> EphemeralKey {
let base_point: GE = ECPoint::generator();
let hash_private_key_message =
HSha256::create_hash(&[&x1.private_key.to_big_int(), &BigInt::from(message)]);
HSha256::create_hash(&[&x1.private_key.to_big_int(), &BigInt::from_bytes(message)]);
let ephemeral_private_key: FE = ECScalar::from(&hash_private_key_message);
let ephemeral_public_key = base_point.scalar_mul(&ephemeral_private_key.get_element());
let (commitment, blind_factor) =
Expand Down Expand Up @@ -183,13 +183,13 @@ impl EphemeralKey {
&BigInt::from(0),
&r_hat.x_coor().unwrap(),
&apk.bytes_compressed_to_big_int(),
&BigInt::from(message),
&BigInt::from_bytes(message),
])
} else {
HSha256::create_hash(&[
&r_hat.x_coor().unwrap(),
&apk.bytes_compressed_to_big_int(),
&BigInt::from(message),
&BigInt::from_bytes(message),
])
}
}
Expand Down Expand Up @@ -227,13 +227,13 @@ pub fn verify(
&BigInt::from(0),
&r_x,
&apk.bytes_compressed_to_big_int(),
&BigInt::from(message),
&BigInt::from_bytes(message),
])
} else {
HSha256::create_hash(&[
r_x,
&apk.bytes_compressed_to_big_int(),
&BigInt::from(message),
&BigInt::from_bytes(message),
])
};

Expand Down
2 changes: 1 addition & 1 deletion src/protocols/aggsig/musig_two_rounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl State {
for i in 0..Nv {
hnon_preimage.push(R_j_vec[i].bytes_compressed_to_big_int());
}
hnon_preimage.push(BigInt::from(message));
hnon_preimage.push(BigInt::from_bytes(message));
hnon_preimage.push(BigInt::from(j as i32));
let b_j = HSha256::create_hash(&hnon_preimage.iter().collect::<Vec<_>>());
b_coefficients.push(b_j);
Expand Down
3 changes: 2 additions & 1 deletion src/protocols/multisig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! Schnorr {n,n}-Signatures based on Accountable-Subgroup Multisignatures
//!
//See (https://pdfs.semanticscholar.org/6bf4/f9450e7a8e31c106a8670b961de4735589cf.pdf)
use curv::arithmetic::Converter;
use curv::elliptic::curves::traits::*;
use curv::BigInt;

Expand Down Expand Up @@ -180,7 +181,7 @@ impl EphKey {
.iter()
.fold(first_eph_pub_key, |acc, x| acc.add_point(&x.get_element()));
//TODO: maybe there is a better way?
let m_fe: FE = ECScalar::from(&BigInt::from(message));
let m_fe: FE = ECScalar::from(&BigInt::from_bytes(message));
let base_point: GE = GE::generator();
let m_ge = base_point.scalar_mul(&m_fe.get_element());
let e = multisig::hash_4(&[&sum_pub_eph, &m_ge, &sum_pub]);
Expand Down
8 changes: 4 additions & 4 deletions src/protocols/thresholdsig/bitcoin_schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ impl LocalSig {
let message_len_bits = message.len() * 8;
let R = local_ephemeral_key.y.bytes_compressed_to_big_int();
let X = local_private_key.y.bytes_compressed_to_big_int();
let X_vec = BigInt::to_vec(&X);
let X_vec = BigInt::to_bytes(&X);
let X_vec_len_bits = X_vec.len() * 8;
let e_bn = HSha256::create_hash_from_slice(
&BigInt::to_vec(
&((((R << X_vec_len_bits) + X) << message_len_bits) + BigInt::from(message)),
&BigInt::to_bytes(
&((((R << X_vec_len_bits) + X) << message_len_bits) + BigInt::from_bytes(message)),
)[..],
);

Expand Down Expand Up @@ -284,7 +284,7 @@ impl Signature {
let e_bn = HSha256::create_hash(&[
&self.v.bytes_compressed_to_big_int(),
&pubkey_y.bytes_compressed_to_big_int(),
&BigInt::from(message),
&BigInt::from_bytes(message),
]);
let e: FE = ECScalar::from(&e_bn);

Expand Down
12 changes: 6 additions & 6 deletions src/protocols/thresholdsig/zilliqa_schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ impl LocalSig {
/*
let hash_in_concat = local_ephemaral_key.y.bytes_compressed_to_big_int()
+ (local_private_key.y.bytes_compressed_to_big_int() << 264)
+ (BigInt::from(message) << 528);
+ (BigInt::from_bytes(message) << 528);
let e_bn = HSha256::create_hash(&[&hash_in_concat]);
*/
let e_bn = HSha256::create_hash(&[
&local_ephemaral_key.y.bytes_compressed_to_big_int(),
&local_private_key.y.bytes_compressed_to_big_int(),
&BigInt::from(message),
&BigInt::from_bytes(message),
]);

let e: FE = ECScalar::from(&e_bn);
Expand Down Expand Up @@ -322,13 +322,13 @@ impl Signature {
/*
let hash_in_concat = v.bytes_compressed_to_big_int()
+ (Y.bytes_compressed_to_big_int() << 264)
+ (BigInt::from(message) << 528);
+ (BigInt::from_bytes(message) << 528);
let r = HSha256::create_hash(&[&hash_in_concat]);
*/
let r = HSha256::create_hash(&[
&v.bytes_compressed_to_big_int(),
&Y.bytes_compressed_to_big_int(),
&BigInt::from(message),
&BigInt::from_bytes(message),
]);

Signature {
Expand All @@ -345,14 +345,14 @@ impl Signature {
/*
let hash_in_concat = sg_plus_ey.bytes_compressed_to_big_int()
+ (pubkey_y.bytes_compressed_to_big_int() << 264)
+ (BigInt::from(message) << 528);
+ (BigInt::from_bytes(message) << 528);
let r = HSha256::create_hash(&[&hash_in_concat]);
*/

let r = HSha256::create_hash(&[
&sg_plus_ey.bytes_compressed_to_big_int(),
&pubkey_y.bytes_compressed_to_big_int(),
&BigInt::from(message),
&BigInt::from_bytes(message),
]);
let r: FE = ECScalar::from(&r);

Expand Down

0 comments on commit ec5fb69

Please sign in to comment.