bls12_381/
lib.rs

1//! # `bls12_381`
2//!
3//! This crate provides an implementation of the BLS12-381 pairing-friendly elliptic
4//! curve construction.
5//!
6//! * **This implementation has not been reviewed or audited. Use at your own risk.**
7//! * This implementation targets Rust `1.36` or later.
8//! * This implementation does not require the Rust standard library.
9//! * All operations are constant time unless explicitly noted.
10
11#![no_std]
12#![cfg_attr(docsrs, feature(doc_cfg))]
13// Catch documentation errors caused by code changes.
14#![deny(rustdoc::broken_intra_doc_links)]
15#![deny(missing_debug_implementations)]
16#![deny(missing_docs)]
17#![deny(unsafe_code)]
18#![allow(clippy::too_many_arguments)]
19#![allow(clippy::many_single_char_names)]
20// This lint is described at
21// https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_arithmetic_impl
22// In our library, some of the arithmetic involving extension fields will necessarily
23// involve various binary operators, and so this lint is triggered unnecessarily.
24#![allow(clippy::suspicious_arithmetic_impl)]
25
26#[cfg(feature = "alloc")]
27extern crate alloc;
28
29#[cfg(test)]
30#[macro_use]
31extern crate std;
32
33#[cfg(test)]
34#[cfg(feature = "groups")]
35mod tests;
36
37#[macro_use]
38mod util;
39
40/// Notes about how the BLS12-381 elliptic curve is designed, specified
41/// and implemented by this library.
42pub mod notes {
43    pub mod design;
44    pub mod serialization;
45}
46
47mod scalar;
48
49pub use scalar::Scalar;
50
51#[cfg(feature = "groups")]
52mod fp;
53#[cfg(feature = "groups")]
54mod fp2;
55#[cfg(feature = "groups")]
56mod g1;
57#[cfg(feature = "groups")]
58mod g2;
59
60#[cfg(feature = "groups")]
61pub use g1::{G1Affine, G1Projective};
62#[cfg(feature = "groups")]
63pub use g2::{G2Affine, G2Projective};
64
65#[cfg(feature = "groups")]
66mod fp12;
67#[cfg(feature = "groups")]
68mod fp6;
69
70// The BLS parameter x for BLS12-381 is -0xd201000000010000
71#[cfg(feature = "groups")]
72const BLS_X: u64 = 0xd201_0000_0001_0000;
73#[cfg(feature = "groups")]
74const BLS_X_IS_NEGATIVE: bool = true;
75
76#[cfg(feature = "pairings")]
77mod pairings;
78
79#[cfg(feature = "pairings")]
80pub use pairings::{pairing, Bls12, Gt, MillerLoopResult};
81
82#[cfg(all(feature = "pairings", feature = "alloc"))]
83pub use pairings::{multi_miller_loop, G2Prepared};
84
85/// Use the generic_array re-exported by digest to avoid a version mismatch
86#[cfg(feature = "experimental")]
87pub(crate) use digest::generic_array;
88
89#[cfg(feature = "experimental")]
90pub mod hash_to_curve;