{"id":13532123,"url":"https://github.com/paritytech/bn","last_synced_at":"2025-04-01T20:31:22.405Z","repository":{"id":52671545,"uuid":"85753021","full_name":"paritytech/bn","owner":"paritytech","description":"Pairing cryptography library in Rust","archived":false,"fork":true,"pushed_at":"2024-01-18T22:54:25.000Z","size":6938,"stargazers_count":32,"open_issues_count":5,"forks_count":49,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-17T11:59:40.369Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"zcash-hackworks/bn","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paritytech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-21T21:01:13.000Z","updated_at":"2024-09-03T21:46:27.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/paritytech/bn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paritytech%2Fbn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paritytech%2Fbn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paritytech%2Fbn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paritytech%2Fbn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paritytech","download_url":"https://codeload.github.com/paritytech/bn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246709923,"owners_count":20821297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T07:01:08.372Z","updated_at":"2025-04-01T20:31:17.389Z","avatar_url":"https://github.com/paritytech.png","language":"Rust","funding_links":[],"categories":["Cryptography"],"sub_categories":["Theorem"],"readme":"# bn [![Crates.io](https://img.shields.io/crates/v/bn.svg)](https://crates.io/crates/bn) [![Build status](https://api.travis-ci.org/zcash/bn.svg)](https://travis-ci.org/zcash/bn)\n\nThis is a [pairing cryptography](https://en.wikipedia.org/wiki/Pairing-based_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 **G\u003csub\u003e1\u003c/sub\u003e** and **G\u003csub\u003e2\u003c/sub\u003e**, with an efficient bilinear pairing:\n\n*e: G\u003csub\u003e1\u003c/sub\u003e × G\u003csub\u003e2\u003c/sub\u003e → G\u003csub\u003eT\u003c/sub\u003e*\n\n## Security warnings\n\nThis library, like other pairing cryptography libraries implementing this construction, is not resistant to side-channel attacks.\n\n## Usage\n\nAdd the `bn` crate to your dependencies in `Cargo.toml`...\n\n```toml\n[dependencies]\nbn = \"0.4.2\"\n```\n\n...and add an `extern crate` declaration to your crate root:\n\n```rust\nextern crate bn;\n```\n\n## API\n\n* `Fr` is an element of F\u003csub\u003er\u003c/sub\u003e\n* `G1` is a point on the BN curve E/Fq : y^2 = x^3 + b\n* `G2` is a point on the twisted BN curve E'/Fq2 : y^2 = x^3 + b/xi\n* `Gt` is a group element (written multiplicatively) obtained with the `pairing` function over `G1` and `G2`.\n\n### Examples\n\n#### Joux's key agreement protocol\n\nIn 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*P\u003csub\u003e1\u003c/sub\u003e and Bob's public key *b*P\u003csub\u003e2\u003c/sub\u003e, Carol can compute the shared secret with her private key *c* by *e*(*a*P\u003csub\u003e1\u003c/sub\u003e, *b*P\u003csub\u003e2\u003c/sub\u003e)\u003csup\u003ec\u003c/sup\u003e.\n\n(See `examples/joux.rs` for the full example.)\n\n```rust\n// Generate private keys\nlet alice_sk = Fr::random(rng);\nlet bob_sk = Fr::random(rng);\nlet carol_sk = Fr::random(rng);\n\n// Generate public keys in G1 and G2\nlet (alice_pk1, alice_pk2) = (G1::one() * alice_sk, G2::one() * alice_sk);\nlet (bob_pk1, bob_pk2) = (G1::one() * bob_sk, G2::one() * bob_sk);\nlet (carol_pk1, carol_pk2) = (G1::one() * carol_sk, G2::one() * carol_sk);\n\n// Each party computes the shared secret\nlet alice_ss = pairing(bob_pk1, carol_pk2).pow(alice_sk);\nlet bob_ss = pairing(carol_pk1, alice_pk2).pow(bob_sk);\nlet carol_ss = pairing(alice_pk1, bob_pk2).pow(carol_sk);\n\nassert!(alice_ss == bob_ss \u0026\u0026 bob_ss == carol_ss);\n```\n\n## License\n\nLicensed under either of\n\n * MIT license, ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n\nat your option.\n\nCopyright 2016 [Zcash Electric Coin Company](https://z.cash/). The Zcash Company promises to maintain the \"bn\" crate on crates.io under this MIT/Apache-2.0 dual license.\n\n### Authors\n\n* [Sean Bowe](https://github.com/ebfull)\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally\nsubmitted for inclusion in the work by you, as defined in the Apache-2.0\nlicense, shall be dual licensed as above, without any additional terms or\nconditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparitytech%2Fbn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparitytech%2Fbn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparitytech%2Fbn/lists"}