Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rantan committed Feb 20, 2020
1 parent dda62d9 commit 6c4b661
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/protocols/thresholdsig/bitcoin_schnorr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(non_snake_case)]
use protocols::thresholdsig::util::compute_e;
#[allow(unused_doc_comments)]
/*
Multisig Schnorr
Expand All @@ -17,7 +18,6 @@
*/
/// following the variant used in bip-schnorr: https://github.com/sipa/bips/blob/bip-schnorr/bip-schnorr.mediawiki
use Error::{self, InvalidKey, InvalidSS, InvalidSig};
use protocols::thresholdsig::util::compute_e;

use curv::arithmetic::traits::*;

Expand Down
4 changes: 2 additions & 2 deletions src/protocols/thresholdsig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
/// variant (2)
pub mod bitcoin_schnorr;
mod util;
mod test_bitcoin;
mod test_zilliqa;
mod util;
/// Schnorr signature variants:
/// Elliptic Curve Schnorr signatures for message m and public key P generally involve
/// a point R, integers e and s picked by the signer, and generator G which satisfy e = H(R || m)
Expand All @@ -28,4 +28,4 @@ mod test_zilliqa;
/// as there are no elliptic curve operations inside the hashes.

/// variant (1)
pub mod zilliqa_schnorr;
pub mod zilliqa_schnorr;
47 changes: 34 additions & 13 deletions src/protocols/thresholdsig/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#![allow(non_snake_case)]
use curv::cryptographic_primitives::hashing::hash_sha256::HSha256;
use curv::cryptographic_primitives::hashing::traits::Hash;
use curv::elliptic::curves::traits::{ECPoint, ECScalar};
#[allow(unused_doc_comments)]
/*
Multisig Schnorr
Expand All @@ -15,11 +18,7 @@
@license GPL-3.0+ <https://github.com/KZen-networks/multisig-schnorr/blob/master/LICENSE>
*/

use curv::{GE, FE};
use curv::elliptic::curves::traits::{ECPoint, ECScalar};
use curv::cryptographic_primitives::hashing::hash_sha256::HSha256;
use curv::cryptographic_primitives::hashing::traits::Hash;
use curv::{FE, GE};

/// Compute e = h(V || Y || message)
pub fn compute_e(v: &GE, y: &GE, message: &[u8]) -> FE {
Expand All @@ -37,26 +36,48 @@ pub fn compute_e(v: &GE, y: &GE, message: &[u8]) -> FE {

#[cfg(test)]
mod tests {
use protocols::thresholdsig::util::compute_e;
use curv::elliptic::curves::traits::{ECPoint, ECScalar};
use curv::{BigInt, FE, GE};
use protocols::thresholdsig::util::compute_e;

#[test]
fn test_compute_e() {
let v_x_bn = BigInt::from_str_radix("06705d6b7fd5a7a34ea47b6a8d0ce8372a83d2129a65458e2bef6f45892e7d5d", 16).unwrap();
let v_y_bn = BigInt::from_str_radix("c6441397d43ff1e0bd9d7da39caf55dffbaa246fb70b1d08d2aa85903e7ec3e0", 16).unwrap();
let v_x_bn = BigInt::from_str_radix(
"06705d6b7fd5a7a34ea47b6a8d0ce8372a83d2129a65458e2bef6f45892e7d5d",
16,
)
.unwrap();
let v_y_bn = BigInt::from_str_radix(
"c6441397d43ff1e0bd9d7da39caf55dffbaa246fb70b1d08d2aa85903e7ec3e0",
16,
)
.unwrap();
let v: GE = ECPoint::from_coor(&v_x_bn, &v_y_bn);

let y_x_bn = BigInt::from_str_radix("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", 16).unwrap();
let y_y_bn = BigInt::from_str_radix("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", 16).unwrap();
let y_x_bn = BigInt::from_str_radix(
"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
16,
)
.unwrap();
let y_y_bn = BigInt::from_str_radix(
"483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",
16,
)
.unwrap();
let y: GE = ECPoint::from_coor(&y_x_bn, &y_y_bn);

// It should be equal to expected when the message started with "00" byte.
let message = hex::decode("0000000000000000000000000000000000000000000000000000000000000000").unwrap();
let message =
hex::decode("0000000000000000000000000000000000000000000000000000000000000000")
.unwrap();

let expected_bn = BigInt::from_str_radix("85e8da2401b58b960965aab0df09554fde8d1e41b67b9cebac8d8421d6919c2a", 16).unwrap();
let expected_bn = BigInt::from_str_radix(
"85e8da2401b58b960965aab0df09554fde8d1e41b67b9cebac8d8421d6919c2a",
16,
)
.unwrap();
let expected: FE = ECScalar::from(&expected_bn);

assert_eq!(expected, compute_e(&v, &y, &message[..]));
}
}
}
4 changes: 2 additions & 2 deletions src/protocols/thresholdsig/zilliqa_schnorr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(non_snake_case)]
use protocols::thresholdsig::util::compute_e;
#[allow(unused_doc_comments)]
/*
Multisig Schnorr
Expand All @@ -19,7 +20,6 @@
/// following the signing & verify variant from https://en.wikipedia.org/wiki/Schnorr_signature (classical variant)
/// also can be found in zilliqa white paper: https://docs.zilliqa.com/whitepaper.pdf
use Error::{self, InvalidKey, InvalidSS, InvalidSig};
use protocols::thresholdsig::util::compute_e;

use curv::arithmetic::traits::*;

Expand Down Expand Up @@ -350,4 +350,4 @@ impl Signature {
Err(InvalidSig)
}
}
}
}

0 comments on commit 6c4b661

Please sign in to comment.