dcrypt_algorithms/ec/bls12_381/
mod.rs

1//! BLS12-381 pairing-friendly elliptic curve implementation.
2//!
3//! **Warning:** Unaudited implementation. Use at your own risk.
4
5// External crates
6#[cfg(feature = "alloc")]
7extern crate alloc;
8
9// Module declarations
10mod field;
11mod g1;
12mod g2;
13mod pairings;
14mod scalar;
15mod hash_to_curve;
16
17#[cfg(test)]
18mod tests;
19
20// Internal use for submodules
21use crate::error::Result;
22use scalar::Scalar;
23
24// Public API exports (following dcrypt conventions)
25pub use g1::{G1Affine, G1Projective};
26pub use g2::{G2Affine, G2Projective};
27pub use hash_to_curve::{hash_to_curve_g1, hash_to_curve_g2};
28pub use pairings::{pairing, Bls12, Gt, MillerLoopResult};
29pub use self::scalar::Scalar as Bls12_381Scalar;
30
31#[cfg(feature = "alloc")]
32pub use pairings::{multi_miller_loop, G2Prepared};
33
34// BLS curve parameters
35/// BLS parameter x = -0xd201000000010000
36const BLS_X: u64 = 0xd201_0000_0001_0000;
37/// Sign of BLS parameter x
38const BLS_X_IS_NEGATIVE: bool = true;
39
40impl G1Projective {
41    /// Hash a message to a point on G1 using the hash-to-curve protocol.
42    pub fn hash_to_curve(msg: &[u8], dst: &[u8]) -> Result<Self> {
43        hash_to_curve_g1(msg, dst)
44    }
45}
46
47impl G2Projective {
48    /// Hash a message to a point on G2 using the hash-to-curve protocol.
49    pub fn hash_to_curve(msg: &[u8], dst: &[u8]) -> Result<Self> {
50        hash_to_curve_g2(msg, dst)
51    }
52}