Public API, reorganize tests, benchmarks and shootout.

This commit is contained in:
Sean Bowe committed 2016-09-11 12:58:18 -06:00
1 parent b93e312eb0
commit 9e458130a6
30 files changed
+30496 -53032

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
// This is an example of three-party Diffie-Hellman key exchange
// Requires two rounds
extern crate bn;
extern crate rand;
use bn::*;
fn main() {
let rng = &mut rand::thread_rng();
// Construct private keys
let alice_sk = Fr::random(rng);
let bob_sk = Fr::random(rng);
let carol_sk = Fr::random(rng);
// Construct public keys
let alice_pk = G1::one() * alice_sk;
let bob_pk = G1::one() * bob_sk;
let carol_pk = G1::one() * carol_sk;
// Round one:
let alice_dh_1 = bob_pk * carol_sk;
let bob_dh_1 = carol_pk * alice_sk;
let carol_dh_1 = alice_pk * bob_sk;
// Round two:
let alice_dh_2 = alice_dh_1 * alice_sk;
let bob_dh_2 = bob_dh_1 * bob_sk;
let carol_dh_2 = carol_dh_1 * carol_sk;
// All parties should arrive to the same shared secret
assert!(alice_dh_2 == bob_dh_2 && bob_dh_2 == carol_dh_2);
}
+24
View File
@@ -0,0 +1,24 @@
extern crate bn;
extern crate rand;
use bn::{Fr, G1, G2, pairing};
fn main() {
let rng = &mut rand::thread_rng();
// Generate private keys
let alice_sk = Fr::random(rng);
let bob_sk = Fr::random(rng);
let carol_sk = Fr::random(rng);
// Generate public keys in G1 and G2
let (alice_pk1, alice_pk2) = (G1::one() * alice_sk, G2::one() * alice_sk);
let (bob_pk1, bob_pk2) = (G1::one() * bob_sk, G2::one() * bob_sk);
let (carol_pk1, carol_pk2) = (G1::one() * carol_sk, G2::one() * carol_sk);
// Each party computes the shared secret
let alice_ss = pairing(bob_pk1, carol_pk2).pow(alice_sk);
let bob_ss = pairing(carol_pk1, alice_pk2).pow(bob_sk);
let carol_ss = pairing(alice_pk1, bob_pk2).pow(carol_sk);
assert!(alice_ss == bob_ss && bob_ss == carol_ss);
}