This crate provides an implementation of the BLS12-381 pairing-friendly elliptic curve construction with hash-to-curve and multi-exponentiation methods.
- This implementation has not been reviewed or audited. Use at your own risk.
- This implementation targets Rust
1.87or later. - This implementation does not require the Rust standard library.
- All operations are constant time unless explicitly noted.
bits(on by default): Enables APIs for obtaining bit iterators for scalars.groups(on by default): Enables APIs for performing group arithmetic with G1, G2, and GT.pairings(on by default): Enables APIs for performing pairings.alloc(on by default): Enables APIs that require an allocator.ark: Enables compatibility with the arkworks ecosystem and the Rust standard library.expose-fields: Exposes the internal field modules; this also enablesgroups.std: Enables APIs that require the Rust standard library.
elliptic-curve,ff, andgroup0.14traits are implemented forScalar, the G1/G2 types, and theBls12381G1/Bls12381G2curve markers.- The
ffandgroup0.13traits are also implemented, becausepairing0.23needs them. They are re-exported asff_013andgroup_013. elliptic-curve0.13is no longer supported as of0.10.0.
Hash-to-curve follows RFC 9380 and takes any hash2curve 0.14 ExpandMsg at the 128-bit security level:
use blstrs_plus::{G1Projective, G2Projective, Scalar};
use hash2curve::ExpandMsgXmd;
use sha2::Sha256;
let msg = b"message";
let p = G1Projective::hash::<ExpandMsgXmd<Sha256>>(msg, b"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_");
let q = G2Projective::hash::<ExpandMsgXmd<Sha256>>(msg, b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_");
let s = Scalar::hash::<ExpandMsgXmd<Sha256>>(msg, b"my-scalar-dst");This needs hash2curve = "0.14" and sha2 = "0.11" in your Cargo.toml. The DST must be non-empty, or these functions panic.
Test for non-wasm32 targets:
cargo test --all-featuresTest wasm32 targets:
cargo test --target wasm32-unknown-unknownLicensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.