Skip to content

Commit 433cb22

Browse files
authored
gg recid (#86)
* gg recid * remove cmp * bump version
1 parent 894ce91 commit 433cb22

File tree

5 files changed

+61
-46
lines changed

5 files changed

+61
-46
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "multi-party-ecdsa"
3-
version = "0.2.9"
3+
version = "0.3.0"
44
edition = "2018"
55
authors = [
66

examples/gg18_sign_client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ fn main() {
470470
println!("party {:?} Output Signature: \n", party_num_int);
471471
println!("R: {:?}", sig.r.get_element());
472472
println!("s: {:?} \n", sig.s.get_element());
473+
println!("recid: {:?} \n", sig.recid.clone());
473474

474475
let sign_json = serde_json::to_string(&(
475476
"r",

src/protocols/multi_party_ecdsa/gg_2018/party_i.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
1616
@license GPL-3.0+ <https://github.com/KZen-networks/multi-party-ecdsa/blob/master/LICENSE>
1717
*/
18-
1918
use centipede::juggling::proof_system::{Helgamalsegmented, Witness};
2019
use centipede::juggling::segmentation::Msegmentation;
2120
use curv::arithmetic::traits::*;
@@ -138,9 +137,10 @@ pub struct Phase5DDecom2 {
138137
}
139138

140139
#[derive(Clone, Debug, Serialize, Deserialize)]
141-
pub struct Signature {
140+
pub struct SignatureRecid {
142141
pub r: FE,
143142
pub s: FE,
143+
pub recid: u8,
144144
}
145145

146146
impl Keys {
@@ -667,10 +667,27 @@ impl LocalSignature {
667667
Err(InvalidCom)
668668
}
669669
}
670-
pub fn output_signature(&self, s_vec: &[FE]) -> Result<Signature, Error> {
671-
let s = s_vec.iter().fold(self.s_i, |acc, x| acc + x);
670+
pub fn output_signature(&self, s_vec: &[FE]) -> Result<SignatureRecid, Error> {
671+
let mut s = s_vec.iter().fold(self.s_i, |acc, x| acc + x);
672+
let s_bn = s.to_big_int();
673+
672674
let r: FE = ECScalar::from(&self.R.x_coor().unwrap().mod_floor(&FE::q()));
673-
let sig = Signature { r, s };
675+
let ry: BigInt = self.R.y_coor().unwrap().mod_floor(&FE::q());
676+
677+
/*
678+
Calculate recovery id - it is not possible to compute the public key out of the signature
679+
itself. Recovery id is used to enable extracting the public key uniquely.
680+
1. id = R.y & 1
681+
2. if (s > curve.q / 2) id = id ^ 1
682+
*/
683+
let is_ry_odd = ry.tstbit(0);
684+
let mut recid = if is_ry_odd { 1 } else { 0 };
685+
let s_tag_bn = FE::q() - &s_bn;
686+
if s_bn > s_tag_bn {
687+
s = ECScalar::from(&s_tag_bn);
688+
recid = recid ^ 1;
689+
}
690+
let sig = SignatureRecid { r, s, recid };
674691
let ver = verify(&sig, &self.y, &self.m).is_ok();
675692
if ver {
676693
Ok(sig)
@@ -680,7 +697,7 @@ impl LocalSignature {
680697
}
681698
}
682699

683-
pub fn verify(sig: &Signature, y: &GE, message: &BigInt) -> Result<(), Error> {
700+
pub fn verify(sig: &SignatureRecid, y: &GE, message: &BigInt) -> Result<(), Error> {
684701
let b = sig.s.invert();
685702
let a: FE = ECScalar::from(message);
686703
let u1 = a * b;

src/protocols/two_party_ecdsa/cclst_2019/test.rs

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,45 @@ fn test_d_log_proof_party_two_party_one() {
2626

2727
#[test]
2828
fn test_full_key_gen() {
29-
for i in 0..20 {
30-
let (party_one_first_message, comm_witness, ec_key_pair_party1) =
31-
party_one::KeyGenFirstMsg::create_commitments_with_fixed_secret_share(ECScalar::from(
32-
&BigInt::sample(253),
33-
));
34-
let (party_two_first_message, _ec_key_pair_party2) =
35-
party_two::KeyGenFirstMsg::create_with_fixed_secret_share(ECScalar::from(
36-
&BigInt::from(10),
37-
));
38-
let party_one_second_message = party_one::KeyGenSecondMsg::verify_and_decommit(
39-
comm_witness,
40-
&party_two_first_message.d_log_proof,
41-
)
42-
.expect("failed to verify and decommit");
29+
let (party_one_first_message, comm_witness, ec_key_pair_party1) =
30+
party_one::KeyGenFirstMsg::create_commitments_with_fixed_secret_share(ECScalar::from(
31+
&BigInt::sample(253),
32+
));
33+
let (party_two_first_message, _ec_key_pair_party2) =
34+
party_two::KeyGenFirstMsg::create_with_fixed_secret_share(ECScalar::from(&BigInt::from(
35+
10,
36+
)));
37+
let party_one_second_message = party_one::KeyGenSecondMsg::verify_and_decommit(
38+
comm_witness,
39+
&party_two_first_message.d_log_proof,
40+
)
41+
.expect("failed to verify and decommit");
4342

44-
let _party_two_second_message =
45-
party_two::KeyGenSecondMsg::verify_commitments_and_dlog_proof(
46-
&party_one_first_message,
47-
&party_one_second_message,
48-
)
49-
.expect("failed to verify commitments and DLog proof");
43+
let _party_two_second_message = party_two::KeyGenSecondMsg::verify_commitments_and_dlog_proof(
44+
&party_one_first_message,
45+
&party_one_second_message,
46+
)
47+
.expect("failed to verify commitments and DLog proof");
5048

51-
// init HSMCL keypair:
52-
let seed: BigInt = str::parse(
49+
// init HSMCL keypair:
50+
let seed: BigInt = str::parse(
5351
"314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848"
5452
).unwrap();
55-
let hsmcl_key_pair = party_one::HSMCLKeyPair::generate_keypair_and_encrypted_share(
56-
&ec_key_pair_party1,
57-
seed.clone(),
58-
);
59-
60-
let party_one_private =
61-
party_one::Party1Private::set_private_key(&ec_key_pair_party1, &hsmcl_key_pair);
62-
63-
let cldl_proof = party_one::HSMCLKeyPair::generate_zkcldl_proof(
64-
&hsmcl_key_pair,
65-
&party_one_private,
66-
seed.clone(),
67-
);
68-
let _party_two_hsmcl_pub =
69-
party_two::HSMCLPublic::verify_zkcldl_proof(cldl_proof).expect("proof error");
70-
}
53+
let hsmcl_key_pair = party_one::HSMCLKeyPair::generate_keypair_and_encrypted_share(
54+
&ec_key_pair_party1,
55+
seed.clone(),
56+
);
57+
58+
let party_one_private =
59+
party_one::Party1Private::set_private_key(&ec_key_pair_party1, &hsmcl_key_pair);
60+
61+
let cldl_proof = party_one::HSMCLKeyPair::generate_zkcldl_proof(
62+
&hsmcl_key_pair,
63+
&party_one_private,
64+
seed.clone(),
65+
);
66+
let _party_two_hsmcl_pub =
67+
party_two::HSMCLPublic::verify_zkcldl_proof(cldl_proof).expect("proof error");
7168
}
7269

7370
#[test]

src/protocols/two_party_ecdsa/lindell_2017/party_one.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl Signature {
565565
k1_inv.zeroize();
566566
s_tag_fe.zeroize();
567567
let s_tag_tag_bn = s_tag_tag.to_big_int();
568-
let s = cmp::min(s_tag_tag_bn.clone(), FE::q().clone() - s_tag_tag_bn.clone());
568+
let s = cmp::min(s_tag_tag_bn.clone(), FE::q() - &s_tag_tag_bn);
569569

570570
/*
571571
Calculate recovery id - it is not possible to compute the public key out of the signature

0 commit comments

Comments
 (0)