Files
Andronik Ordian 47d6e4f919 merge substrate-bn branch into master (#21)
* fix edition and prepare publish

* Publish for substrate branch

* fix edition 2018

* add Parity as authors

Co-authored-by: NikVolf <nikvolf@gmail.com>
2021-04-21 14:52:44 +02:00

23 lines
795 B
Rust

use substrate_bn::{Group, 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);
}