paritytech/bn

Name: bn

Owner: Parity Technologies

Description: Pairing cryptography library in Rust

Forked from: zcash-hackworks/bn

Created: 2017-03-21 21:01:13.0

Updated: 2018-03-29 17:08:24.0

Pushed: 2018-03-26 16:42:48.0

Homepage:

Size: 6833

Language: Rust

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

bn Crates.io Build status

This is a pairing cryptography library written in pure Rust. It makes use of the Barreto-Naehrig (BN) curve construction from [[BCTV2015]](https://eprint.iacr.org/2013/879.pdf) to provide two cyclic groups G1 and G2, with an efficient bilinear pairing:

e: G1 × G2 ? GT

Security warnings

This library, like other pairing cryptography libraries implementing this construction, is not resistant to side-channel attacks.

Usage

Add the bn crate to your dependencies in Cargo.toml

endencies]
 "0.4.2"

…and add an extern crate declaration to your crate root:

rn crate bn;
API
Examples
Joux's key agreement protocol

In a typical Diffie-Hellman key exchange, relying on ECDLP, a three-party key exchange requires two rounds. A single round protocol is possible through the use of a bilinear pairing: given Alice's public key aP1 and Bob's public key bP2, Carol can compute the shared secret with her private key c by e(aP1, bP2)c.

(See examples/joux.rs for the full example.)

enerate private keys
alice_sk = Fr::random(rng);
bob_sk = Fr::random(rng);
carol_sk = Fr::random(rng);

enerate public keys in G1 and G2
(alice_pk1, alice_pk2) = (G1::one() * alice_sk, G2::one() * alice_sk);
(bob_pk1, bob_pk2) = (G1::one() * bob_sk, G2::one() * bob_sk);
(carol_pk1, carol_pk2) = (G1::one() * carol_sk, G2::one() * carol_sk);

ach party computes the shared secret
alice_ss = pairing(bob_pk1, carol_pk2).pow(alice_sk);
bob_ss = pairing(carol_pk1, alice_pk2).pow(bob_sk);
carol_ss = pairing(alice_pk1, bob_pk2).pow(carol_sk);

rt!(alice_ss == bob_ss && bob_ss == carol_ss);
License

Licensed under either of

at your option.

Copyright 2016 Zcash Electric Coin Company. The Zcash Company promises to maintain the “bn” crate on crates.io under this MIT/Apache-2.0 dual license.

Authors
Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.