Skip to content

Commit 9bf90ad

Browse files
authored
Merge pull request #17 from ZenGo-X/0.7-curv
Bump curv to 0.7 and bump version
2 parents 828d5bc + 77d0f4a commit 9bf90ad

File tree

7 files changed

+51
-42
lines changed

7 files changed

+51
-42
lines changed

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "multi-party-eddsa"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
authors = [
55
66
@@ -10,8 +10,11 @@ authors = [
1010
crate-type = ["rlib", "dylib"]
1111

1212
[dependencies]
13-
curv = { git = "https://github.com/KZen-networks/curv", tag = "v0.2.0-ed25519", features = ["ec_ed25519"]}
13+
curv = { package = "curv-kzen", version = "0.7", default-features = false }
1414
hex = "0.3.2"
1515
serde = "1.0"
1616
serde_json = "1.0"
1717
serde_derive = "1.0"
18+
19+
[features]
20+
default = ["curv/rust-gmp-kzen"]

src/protocols/aggsig/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
//! See https://tools.ietf.org/html/rfc8032
2222
use curv::cryptographic_primitives::proofs::*;
2323
pub use curv::elliptic::curves::traits::*;
24-
pub use curv::{BigInt, FE, GE};
24+
use curv::elliptic::curves::ed25519::{GE, FE};
25+
use curv::BigInt;
2526

2627
use curv::cryptographic_primitives::hashing::hash_sha512::HSha512;
2728
use curv::cryptographic_primitives::hashing::traits::*;
@@ -62,7 +63,7 @@ impl KeyPair {
6263
fn create_from_private_key_internal(sk: &FE) -> KeyPair {
6364
let ec_point: GE = ECPoint::generator();
6465
let h = HSha512::create_hash(&vec![&sk.to_big_int()]);
65-
let h_vec = BigInt::to_vec(&h);
66+
let h_vec = BigInt::to_bytes(&h);
6667
let mut h_vec_padded = vec![0; 64 - h_vec.len()]; // ensure hash result is padded to 64 bytes
6768
h_vec_padded.extend_from_slice(&h_vec);
6869
let mut private_key: [u8; 32] = [0u8; 32];
@@ -74,8 +75,8 @@ impl KeyPair {
7475
private_key[31] |= 64;
7576
let private_key = &private_key[..private_key.len()];
7677
let prefix = &prefix[..prefix.len()];
77-
let private_key: FE = ECScalar::from(&BigInt::from(private_key));
78-
let prefix: FE = ECScalar::from(&BigInt::from(prefix));
78+
let private_key: FE = ECScalar::from(&BigInt::from_bytes(private_key));
79+
let prefix: FE = ECScalar::from(&BigInt::from_bytes(prefix));
7980
let public_key = ec_point * &private_key;
8081
KeyPair {
8182
public_key,
@@ -159,7 +160,7 @@ impl Signature {
159160
let r = HSha512::create_hash(&vec![
160161
&BigInt::from(2), // domain seperation
161162
&keys.expended_private_key.prefix.to_big_int(),
162-
&BigInt::from(message),
163+
&BigInt::from_bytes(message),
163164
&FE::new_random().to_big_int(),
164165
]);
165166
let r = reverse_bn_to_fe(&r);
@@ -177,7 +178,7 @@ impl Signature {
177178
let k = HSha512::create_hash(&vec![
178179
&R_tot.bytes_compressed_to_big_int(),
179180
&apk.bytes_compressed_to_big_int(),
180-
&BigInt::from(message),
181+
&BigInt::from_bytes(message),
181182
]);
182183
let k = reverse_bn_to_fe(&k);
183184
k
@@ -201,15 +202,15 @@ impl Signature {
201202
pub fn sign_single(message: &[u8], keys: &KeyPair) -> Signature {
202203
let r = HSha512::create_hash(&vec![
203204
&keys.expended_private_key.prefix.to_big_int(),
204-
&BigInt::from(message),
205+
&BigInt::from_bytes(message),
205206
]);
206207
let r: FE = ECScalar::from(&r);
207208
let ec_point: GE = ECPoint::generator();
208209
let R = ec_point.scalar_mul(&r.get_element());
209210
let k = HSha512::create_hash(&vec![
210211
&R.bytes_compressed_to_big_int(),
211212
&keys.public_key.bytes_compressed_to_big_int(),
212-
&BigInt::from(message),
213+
&BigInt::from_bytes(message),
213214
]);
214215
let k = reverse_bn_to_fe(&k);
215216
let k_mul_sk = k.mul(&keys.expended_private_key.private_key.get_element());
@@ -235,7 +236,7 @@ pub fn verify(signature: &Signature, message: &[u8], public_key: &GE) -> Result<
235236
let k = HSha512::create_hash(&vec![
236237
&signature.R.bytes_compressed_to_big_int(),
237238
&public_key.bytes_compressed_to_big_int(),
238-
&BigInt::from(message),
239+
&BigInt::from_bytes(message),
239240
]);
240241

241242
let k_fe = reverse_bn_to_fe(&k);
@@ -264,8 +265,8 @@ pub fn test_com(r_to_test: &GE, blind_factor: &BigInt, comm: &BigInt) -> bool {
264265
mod test;
265266

266267
pub fn reverse_bn_to_fe(scalar: &BigInt) -> FE {
267-
let mut vec = BigInt::to_vec(&scalar);
268+
let mut vec = BigInt::to_bytes(&scalar);
268269
vec.reverse();
269-
let scalar_out = BigInt::from(&vec[..]);
270+
let scalar_out = BigInt::from_bytes(&vec[..]);
270271
ECScalar::from(&scalar_out)
271272
}

src/protocols/aggsig/test.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
#[cfg(test)]
1818
mod tests {
1919
use curv::elliptic::curves::traits::ECPoint;
20-
use curv::GE;
20+
use curv::elliptic::curves::ed25519::{GE, FE};
21+
use curv::BigInt;
2122
use protocols::aggsig::{test_com, verify, KeyPair, Signature};
23+
use curv::arithmetic::Converter;
2224

2325
#[test]
2426
fn test_ed25519_one_party() {
@@ -196,7 +198,6 @@ mod tests {
196198
}
197199

198200
use curv::elliptic::curves::traits::ECScalar;
199-
use curv::{BigInt, FE};
200201
use hex::decode;
201202
#[test]
202203
fn test_verify_standard_sig() {
@@ -227,7 +228,7 @@ mod tests {
227228
let s_str = "5a180452743fac943b53728e4cbea288a566ba49f7695808d53b3f9f1cd6ed02";
228229
let mut s_dec = decode(s_str).unwrap();
229230
s_dec.reverse();
230-
let s_bn = BigInt::from(&s_dec[..]);
231+
let s_bn = BigInt::from_bytes(&s_dec[..]);
231232
let s: FE = ECScalar::from(&s_bn);
232233

233234
let sig = Signature { R, s };

src/protocols/multisig/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use curv::cryptographic_primitives::hashing::hash_sha256::HSha256;
2222
use curv::cryptographic_primitives::hashing::hash_sha512::HSha512;
2323
use curv::cryptographic_primitives::hashing::traits::*;
2424
use curv::elliptic::curves::traits::*;
25-
use curv::{BigInt, FE, GE};
25+
use curv::elliptic::curves::ed25519::{GE, FE};
26+
use curv::BigInt;
2627
use protocols::multisig;
2728

2829
// TODO: move to a common location to be used by all protocols.
@@ -78,7 +79,7 @@ impl ExpendedKeyPair {
7879
pub fn create_from_private_key(sk: FE) -> ExpendedKeyPair {
7980
let ec_point: GE = ECPoint::generator();
8081
let h = HSha512::create_hash(&vec![&sk.to_big_int()]);
81-
let h_vec = BigInt::to_vec(&h);
82+
let h_vec = BigInt::to_bytes(&h);
8283
let mut h_vec_padded = vec![0; 64 - h_vec.len()]; // ensure hash result is padded to 64 bytes
8384
h_vec_padded.extend_from_slice(&h_vec);
8485
let mut private_key: [u8; 32] = [0u8; 32];
@@ -90,8 +91,8 @@ impl ExpendedKeyPair {
9091
private_key[31] |= 64;
9192
let private_key = &private_key[..private_key.len()];
9293
let prefix = &prefix[..prefix.len()];
93-
let private_key: FE = ECScalar::from(&BigInt::from(private_key));
94-
let prefix: FE = ECScalar::from(&BigInt::from(prefix));
94+
let private_key: FE = ECScalar::from(&BigInt::from_bytes(private_key));
95+
let prefix: FE = ECScalar::from(&BigInt::from_bytes(prefix));
9596
let public_key = ec_point * &private_key;
9697
ExpendedKeyPair {
9798
public_key,

src/protocols/multisig/test.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ mod tests {
2121
use curv::cryptographic_primitives::hashing::merkle_tree::MT256;
2222
use curv::cryptographic_primitives::hashing::traits::Hash;
2323
use curv::elliptic::curves::traits::ECScalar;
24-
use curv::{BigInt, FE};
24+
use curv::elliptic::curves::ed25519::{GE, FE};
25+
use curv::BigInt;
26+
use curv::arithmetic::Converter;
2527
use protocols::multisig::{partial_sign, verify, EphKey, Keys, Signature};
2628

2729
#[test]
@@ -33,7 +35,7 @@ mod tests {
3335

3436
fn two_party_key_gen_internal() {
3537
let message_vec = vec![79, 77, 69, 82];
36-
let message_bn = BigInt::from(&message_vec[..]);
38+
let message_bn = BigInt::from_bytes(&message_vec[..]);
3739
let message = HSha256::create_hash(&vec![&message_bn]);
3840

3941
// party1 key gen:
@@ -84,8 +86,8 @@ mod tests {
8486
let sig = Signature::set_signature(&Xt, &y);
8587
assert!(verify(&It, &sig, &es).is_ok());
8688

87-
assert!(MT256::validate_proof(&proof1, root).is_ok());
88-
assert!(MT256::validate_proof(&proof2, root).is_ok());
89+
assert!(MT256::<GE>::validate_proof(&proof1, root).is_ok());
90+
assert!(MT256::<GE>::validate_proof(&proof2, root).is_ok());
8991
}
9092

9193
}

src/protocols/thresholdsig/mod.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use curv::cryptographic_primitives::commitments::traits::Commitment;
2222
use curv::cryptographic_primitives::hashing::hash_sha512::HSha512;
2323
use curv::cryptographic_primitives::hashing::traits::*;
2424
use curv::cryptographic_primitives::secret_sharing::feldman_vss::VerifiableSS;
25-
use curv::{BigInt, FE, GE};
25+
use curv::elliptic::curves::ed25519::{GE, FE};
26+
use curv::BigInt;
2627

2728
const SECURITY: usize = 256;
2829

@@ -87,7 +88,7 @@ impl Keys {
8788
fn phase1_create_from_private_key_internal(index: usize, sk: &FE) -> Keys {
8889
let ec_point: GE = ECPoint::generator();
8990
let h = HSha512::create_hash(&vec![&sk.to_big_int()]);
90-
let h_vec = BigInt::to_vec(&h);
91+
let h_vec = BigInt::to_bytes(&h);
9192
let mut h_vec_padded = vec![0; 64 - h_vec.len()]; // ensure hash result is padded to 64 bytes
9293
h_vec_padded.extend_from_slice(&h_vec);
9394
let mut private_key: [u8; 32] = [0u8; 32];
@@ -99,8 +100,8 @@ impl Keys {
99100
private_key[31] |= 64;
100101
let private_key = &private_key[..private_key.len()];
101102
let prefix = &prefix[..prefix.len()];
102-
let private_key: FE = ECScalar::from(&BigInt::from(private_key));
103-
let prefix: FE = ECScalar::from(&BigInt::from(prefix));
103+
let private_key: FE = ECScalar::from(&BigInt::from_bytes(private_key));
104+
let prefix: FE = ECScalar::from(&BigInt::from_bytes(prefix));
104105
let public_key = ec_point * &private_key;
105106

106107
Keys {
@@ -128,7 +129,7 @@ impl Keys {
128129
y_vec: &Vec<GE>,
129130
bc1_vec: &Vec<KeyGenBroadcastMessage1>,
130131
parties: &[usize],
131-
) -> Result<(VerifiableSS, Vec<FE>, usize), Error> {
132+
) -> Result<(VerifiableSS<GE>, Vec<FE>, usize), Error> {
132133
// test length:
133134
assert_eq!(blind_vec.len(), params.share_count);
134135
assert_eq!(bc1_vec.len(), params.share_count);
@@ -161,7 +162,7 @@ impl Keys {
161162
params: &Parameters,
162163
y_vec: &Vec<GE>,
163164
secret_shares_vec: &Vec<FE>,
164-
vss_scheme_vec: &Vec<VerifiableSS>,
165+
vss_scheme_vec: &Vec<VerifiableSS<GE>>,
165166
index: &usize,
166167
) -> Result<SharedKeys, Error> {
167168
assert_eq!(y_vec.len(), params.share_count);
@@ -207,7 +208,7 @@ impl EphemeralKey {
207208
// to the nonce
208209
let r_local = HSha512::create_hash(&[
209210
&keys.prefix.to_big_int(),
210-
&BigInt::from(message),
211+
&BigInt::from_bytes(message),
211212
&FE::new_random().to_big_int(),
212213
]);
213214
let r_i: FE = ECScalar::from(&r_local);
@@ -237,7 +238,7 @@ impl EphemeralKey {
237238
R_vec: &Vec<GE>,
238239
bc1_vec: &Vec<KeyGenBroadcastMessage1>,
239240
parties: &[usize],
240-
) -> Result<(VerifiableSS, Vec<FE>, usize), Error> {
241+
) -> Result<(VerifiableSS<GE>, Vec<FE>, usize), Error> {
241242
// test length:
242243
assert!(blind_vec.len() > params.threshold && blind_vec.len() <= params.share_count);
243244
assert!(bc1_vec.len() > params.threshold && bc1_vec.len() <= params.share_count);
@@ -270,7 +271,7 @@ impl EphemeralKey {
270271
params: &Parameters,
271272
R_vec: &Vec<GE>,
272273
secret_shares_vec: &Vec<FE>,
273-
vss_scheme_vec: &Vec<VerifiableSS>,
274+
vss_scheme_vec: &Vec<VerifiableSS<GE>>,
274275
index: &usize,
275276
) -> Result<EphemeralSharedKeys, Error> {
276277
assert!(R_vec.len() > params.threshold && R_vec.len() <= params.share_count);
@@ -316,7 +317,7 @@ impl LocalSig {
316317
let e_bn = HSha512::create_hash(&[
317318
&local_ephemaral_key.R.bytes_compressed_to_big_int(),
318319
&local_private_key.y.bytes_compressed_to_big_int(),
319-
&BigInt::from(message),
320+
&BigInt::from_bytes(message),
320321
]);
321322
let k: FE = ECScalar::from(&e_bn);
322323
let gamma_i = r_i + k * s_i;
@@ -329,9 +330,9 @@ impl LocalSig {
329330
pub fn verify_local_sigs(
330331
gamma_vec: &Vec<LocalSig>,
331332
parties_index_vec: &[usize],
332-
vss_private_keys: &Vec<VerifiableSS>,
333-
vss_ephemeral_keys: &Vec<VerifiableSS>,
334-
) -> Result<(VerifiableSS), Error> {
333+
vss_private_keys: &Vec<VerifiableSS<GE>>,
334+
vss_ephemeral_keys: &Vec<VerifiableSS<GE>>,
335+
) -> Result<VerifiableSS<GE>, Error> {
335336
//parties_index_vec is a vector with indices of the parties that are participating and provided gamma_i for this step
336337
// test that enough parties are in this round
337338
assert!(parties_index_vec.len() > vss_private_keys[0].parameters.threshold);
@@ -380,7 +381,7 @@ impl LocalSig {
380381

381382
impl Signature {
382383
pub fn generate(
383-
vss_sum_local_sigs: &VerifiableSS,
384+
vss_sum_local_sigs: &VerifiableSS<GE>,
384385
local_sig_vec: &Vec<LocalSig>,
385386
parties_index_vec: &[usize],
386387
R: GE,
@@ -400,7 +401,7 @@ impl Signature {
400401
let e_bn = HSha512::create_hash(&[
401402
&self.R.bytes_compressed_to_big_int(),
402403
&pubkey_y.bytes_compressed_to_big_int(),
403-
&BigInt::from(message),
404+
&BigInt::from_bytes(message),
404405
]);
405406

406407
let e: FE = ECScalar::from(&e_bn);

src/protocols/thresholdsig/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#[cfg(test)]
1414
mod tests {
1515
use curv::cryptographic_primitives::secret_sharing::feldman_vss::VerifiableSS;
16-
use curv::{FE, GE};
16+
use curv::elliptic::curves::ed25519::{GE, FE};
1717
use protocols::thresholdsig::*;
1818

1919
#[test]
@@ -132,7 +132,7 @@ mod tests {
132132
t: usize,
133133
n: usize,
134134
parties: &[usize],
135-
) -> (Vec<Keys>, Vec<SharedKeys>, GE, Vec<VerifiableSS>) {
135+
) -> (Vec<Keys>, Vec<SharedKeys>, GE, Vec<VerifiableSS<GE>>) {
136136
let parames = Parameters {
137137
threshold: t,
138138
share_count: n.clone(),
@@ -209,7 +209,7 @@ mod tests {
209209
Vec<EphemeralKey>,
210210
Vec<EphemeralSharedKeys>,
211211
GE,
212-
Vec<VerifiableSS>,
212+
Vec<VerifiableSS<GE>>,
213213
) {
214214
let parames = Parameters {
215215
threshold: t,

0 commit comments

Comments
 (0)