Skip to content

Commit

Permalink
Make it to compute e without converting through BigInt
Browse files Browse the repository at this point in the history
  • Loading branch information
rantan committed Feb 17, 2020
1 parent 5f520c0 commit 180ad2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
19 changes: 9 additions & 10 deletions src/protocols/thresholdsig/bitcoin_schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,15 @@ impl Signature {

/// Compute e = h(V || Y || message)
fn compute_e(v: &GE, y: &GE, message: &[u8]) -> FE {
let message_len_bits = message.len() * 8;
let R = v.bytes_compressed_to_big_int();
let X = y.bytes_compressed_to_big_int();
let X_vec = BigInt::to_vec(&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)),
)[..],
);
let v = v.get_element().serialize();
let y = y.get_element().serialize();

let mut vec: Vec<u8> = Vec::with_capacity(v.len() + y.len() + message.len());
vec.extend(&v[..]);
vec.extend(&y[..]);
vec.extend(message);

let e_bn = HSha256::create_hash_from_slice(&vec[..]);
ECScalar::from(&e_bn)
}

Expand Down
19 changes: 7 additions & 12 deletions src/protocols/thresholdsig/zilliqa_schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,20 +353,15 @@ impl Signature {

/// Compute e = h(V || Y || message)
fn compute_e(v: &GE, y: &GE, message: &[u8]) -> FE {
let v_bn = v.bytes_compressed_to_big_int();
let y_bn = y.bytes_compressed_to_big_int();
let v = v.get_element().serialize();
let y = y.get_element().serialize();

let mut big_ints = vec![&v_bn, &y_bn];
let mut vec: Vec<u8> = Vec::with_capacity(v.len() + y.len() + message.len());
vec.extend(&v[..]);
vec.extend(&y[..]);
vec.extend(message);

let m: Vec<BigInt> = Vec::from(message)
.into_iter()
.map(|i| BigInt::from(i as i32))
.collect();
for i in &m {
big_ints.push(i);
}

let e_bn = HSha256::create_hash(&big_ints);
let e_bn = HSha256::create_hash_from_slice(&vec[..]);
ECScalar::from(&e_bn)
}

Expand Down

0 comments on commit 180ad2f

Please sign in to comment.