Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Secp256r1 curve (NIST P-256) #81

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
- CURVE=ec_ed25519
- CURVE=ec_ristretto
- CURVE=ec_jubjub
- CURVE=ec_secp256r1

before_script:
- rustup component add rustfmt-preview
Expand Down
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ec_secp256k1 = ["rust-gmp" ,"ecc", "secp256k1"]
ec_ristretto = ["rust-gmp", "ecc" , "curve25519-dalek"]
ec_ed25519 = ["rust-gmp", "ecc" , "cryptoxide"]
ec_jubjub = ["rust-gmp", "ecc" , "pairing", "sapling-crypto"]
ec_secp256r1 = ["rust-gmp", "ecc", "ring"]
ec_bls12_381 = ["rust-gmp", "ecc" , "bls12_381"]
ecc = []
merkle = ["rust-crypto", "merkle-sha3"]
Expand All @@ -28,6 +29,11 @@ digest = "0.8.1"
hex = "^0.3"
blake2b_simd = "0.5.7"

[dependencies.ring]
git = "https://github.com/KZen-networks/ring.git"
branch = "feature/p256"
optional = true

Comment on lines +32 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably explained it to me before, but why can't we take Ring from crate.io ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I forked and modified it (in order to extend the API of the keypair which is needed for this PR).
If we'll merge it to master (see ZenGo-X/ring#1) then we can publish KZen's repo with another name. How does that sound?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you give me a sense of what API extension were needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point arithmetics, serialization etc. (see PR)

[dependencies.rust-crypto]
version = "^0.2"
optional = true
Expand Down
5 changes: 5 additions & 0 deletions src/cryptographic_primitives/hashing/hash_sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ mod tests {

#[test]
fn create_sha256_from_ge_test() {
println!("create_sha256_from_ge_test #1");
let point = GE::base_point2();
println!("create_sha256_from_ge_test #2");
let result1 = HSha256::create_hash_from_ge(&vec![&point, &GE::generator()]);
println!("create_sha256_from_ge_test #3");
assert!(result1.to_big_int().to_str_radix(2).len() > 240);
println!("create_sha256_from_ge_test #4");
let result2 = HSha256::create_hash_from_ge(&vec![&GE::generator(), &point]);
println!("create_sha256_from_ge_test #5");
assert_ne!(result1, result2);
let result3 = HSha256::create_hash_from_ge(&vec![&GE::generator(), &point]);
assert_eq!(result2, result3);
Expand Down
13 changes: 13 additions & 0 deletions src/cryptographic_primitives/twoparty/dh_key_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,24 @@ mod tests {
#[test]
fn test_dh_key_exchange_fixed_shares() {
let secret_party_1: FE = ECScalar::from(&BigInt::one());
println!("secret_party_1 = {:?}", secret_party_1);
let (kg_party_one_first_message, kg_ec_key_pair_party1) =
Party1FirstMessage::first_with_fixed_secret_share(secret_party_1);
println!(
"kg_party_one_first_message = {:?}",
kg_party_one_first_message
);
println!("kg_ec_key_pair_party1 = {:?}", kg_ec_key_pair_party1);
let secret_party_2: FE = ECScalar::from(&BigInt::from(2));
println!("secret_party_2 = {:?}", secret_party_2);

let (kg_party_two_first_message, kg_ec_key_pair_party2) =
Party2FirstMessage::first_with_fixed_secret_share(secret_party_2);
println!(
"kg_party_two_first_message = {:?}",
kg_party_two_first_message
);
println!("kg_ec_key_pair_party2 = {:?}", kg_ec_key_pair_party2);

assert_eq!(
compute_pubkey(
Expand All @@ -130,6 +142,7 @@ mod tests {
)
);
let g: GE = GE::generator();
println!("g = {:?}", g);
assert_eq!(
compute_pubkey(
&kg_ec_key_pair_party2,
Expand Down
3 changes: 3 additions & 0 deletions src/elliptic/curves/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ pub mod curve_ristretto;
pub mod ed25519;
#[cfg(feature = "ec_secp256k1")]
pub mod secp256_k1;
#[cfg(feature = "ec_secp256r1")]
pub mod secp256_r1;

pub mod traits;
Loading