# bn

This is a pairing cryptography library written in pure Rust. It makes use of the Barreto-Naehrig (BN) curve construction from [BCTV2015] 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`

...

```
[]
= "0.4.2"
```

...and add an `extern crate`

declaration to your crate root:

```
extern crate bn;
```

## API

`Fr`

is an element of Fr`G1`

is a point on the BN curve E/Fq : y^{2 = x}3 + b`G2`

is a point on the twisted BN curve E'/Fq2 : y^{2 = x}3 + b/xi`Gt`

is a group element (written multiplicatively) obtained with the`pairing`

function over`G1`

and`G2`

.

### 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 *a*P1 and Bob's public key *b*P2, Carol can compute the shared secret with her private key *c* by *e*(*a*P1, *b*P2)c.

(See `examples/joux.rs`

for the full example.)

```
// Generate private keys
let alice_sk = random;
let bob_sk = random;
let carol_sk = random;
// Generate public keys in G1 and G2
let = ;
let = ;
let = ;
// Each party computes the shared secret
let alice_ss = pairing.pow;
let bob_ss = pairing.pow;
let carol_ss = pairing.pow;
assert!;
```

## License

Licensed under either of

- MIT license, (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)

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.