sm9_core
This is a pairing cryptography library written in pure Rust. It makes use of the Barreto-Naehrig (BN) curve construction from "SM9 identity-based cryptographic algorithms" as well as ISO/IEC 11770 to provide two cyclic groups G 1 and G 2 , with an R-ate pairing:
e: G 1 × G 2 → G T
Security warnings
This library, like other pairing cryptography libraries implementing this construction, is not resistant to side-channel attacks.
Usage
Add the sm9_core
crate to your dependencies in Cargo.toml
[]
= "0.3.8"
API
Fr
is an element of F rG1
is a point on the BN curve E/Fq : y 2 = x 3 + bG2
is a point on the twisted BN curve E'/Fq2 : y 2 = x 3 + b x iGt
is a group element (written multiplicatively)pairing()
is a API to compute R-ate Pairing G2 x G1 -> GTfast_pairing()
is another API to compute R-ate Pairing G2 x G1 -> GT
Examples
(See integration_test.rs
for the full example.)
use hex;
use *;
let ks = from_slice.unwrap;
let r = from_slice.unwrap;
let pub_s = G2 one * ks;
let g = pairing.pow;
println!;
let r1 = g.to_slice;
let r0 = hex!;
assert_eq!;
// test fast_pairing
let g1 = fast_pairing.pow;
let r1 = g1.to_slice;
assert_eq!;
License
Licensed under either of
at your option.
Copyright 2023 John-Yu.
Thanks
The fields and groups algorithms come from zcash-bn and bls12_381, and pairing algorithms come from GmSSL. The fast_pairing algorithms come from MIRACL, it is 23% faster than pairing().
Thanks to them.
Benchmark
(OS: windows11, CPU: i7-8700K 3.70GHz, See my_benchmark.rs
for the details)
function | times |
---|---|
pairing | time: [1.3327 ms 1.3383 ms 1.3452 ms] |
fast_pairing | time: [994.39 µs 997.82 µs 1.0017 ms] |
precomputed_pairing | time: [854.58 µs 857.26 µs 860.06 µs] |
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.