#[repr(C)]pub struct Fn(/* private fields */);Expand description
Fn is a prime field with n elements where n is the order of the cyclic groups ๐พ1, ๐พ2 and ๐พt Represents an element of the finite field Fr
Examples
use sm9_core::*;
use hex_literal::hex;
let ks = Fr::from_slice(&hex!("000130E78459D78545CB54C587E02CF480CE0B66340F319F348A1D5B1F2DC5F4")).unwrap();
let r = Fr::from_slice(&hex!("00033C86 16B06704 813203DF D0096502 2ED15975 C662337A ED648835 DC4B1CBE")).unwrap();
let pub_s = G2::one() * ks;
let g = pairing(G1::one(), pub_s).pow(r);
let r1 = g.to_slice();
println!("{:#?}", g);
let r0 = hex!(
"81377B8F DBC2839B 4FA2D0E0 F8AA6853 BBBE9E9C 4099608F 8612C607 8ACD7563"
"815AEBA2 17AD502D A0F48704 CC73CABB 3C06209B D87142E1 4CBD99E8 BCA1680F"
"30DADC5C D9E207AE E32209F6 C3CA3EC0 D800A1A4 2D33C731 53DED47C 70A39D2E"
"8EAF5D17 9A1836B3 59A9D1D9 BFC19F2E FCDB8293 28620962 BD3FDF15 F2567F58"
"A543D256 09AE9439 20679194 ED30328B B33FD156 60BDE485 C6B79A7B 32B01398"
"3F012DB0 4BA59FE8 8DB88932 1CC2373D 4C0C35E8 4F7AB1FF 33679BCA 575D6765"
"4F8624EB 435B838C CA77B2D0 347E65D5 E4696441 2A096F41 50D8C5ED E5440DDF"
"0656FCB6 63D24731 E8029218 8A2471B8 B68AA993 89926849 9D23C897 55A1A897"
"44643CEA D40F0965 F28E1CD2 895C3D11 8E4F65C9 A0E3E741 B6DD52C0 EE2D25F5"
"898D6084 8026B7EF B8FCC1B2 442ECF07 95F8A81C EE99A624 8F294C82 C90D26BD"
"6A814AAF 475F128A EF43A128 E37F8015 4AE6CB92 CAD7D150 1BAE30F7 50B3A9BD"
"1F96B08E 97997363 91131470 5BFB9A9D BB97F755 53EC90FB B2DDAE53 C8F68E42"
);
assert_eq!(r0, r1);
// test fast_pairing
let g1 = fast_pairing(G1::one(), pub_s).pow(r);
let r1 = g1.to_slice();
assert_eq!(r0, r1);Implementationsยง
sourceยงimpl Fr
impl Fr
sourcepub fn from_slice(hex: &[u8]) -> Option<Fr>
pub fn from_slice(hex: &[u8]) -> Option<Fr>
Attempts to convert a big-endian byte slice
into an element of Fr, sliceโs length must be in [1, 64]
sourcepub fn from_hash(hex: &[u8]) -> Option<Fr>
pub fn from_hash(hex: &[u8]) -> Option<Fr>
for H1() and H2(), Attempts to convert a HASH result (40 bytes) to a Fr element
sourcepub fn pow(&self, exp: Fr) -> Fr
pub fn pow(&self, exp: Fr) -> Fr
Exponentiates self by exp, where exp is a
Fr element exponent.
sourcepub fn inverse(&self) -> Option<Fr>
pub fn inverse(&self) -> Option<Fr>
Computes the multiplicative inverse of this element, failing if the element is zero.
sourcepub fn interpret(buf: &[u8; 64]) -> Fr
pub fn interpret(buf: &[u8; 64]) -> Fr
Attempts to convert a big-endian byte representation of
a field element into an element of Fr, slice length must be 64
Trait Implementationsยง
sourceยงimpl<'b> AddAssign<&'b Fr> for Fr
impl<'b> AddAssign<&'b Fr> for Fr
sourceยงfn add_assign(&mut self, rhs: &'b Fr)
fn add_assign(&mut self, rhs: &'b Fr)
Performs the
+= operation. Read moresourceยงimpl AddAssign for Fr
impl AddAssign for Fr
sourceยงfn add_assign(&mut self, rhs: Fr)
fn add_assign(&mut self, rhs: Fr)
Performs the
+= operation. Read moresourceยงimpl<'b> MulAssign<&'b Fr> for Fr
impl<'b> MulAssign<&'b Fr> for Fr
sourceยงfn mul_assign(&mut self, rhs: &'b Fr)
fn mul_assign(&mut self, rhs: &'b Fr)
Performs the
*= operation. Read moresourceยงimpl MulAssign for Fr
impl MulAssign for Fr
sourceยงfn mul_assign(&mut self, rhs: Fr)
fn mul_assign(&mut self, rhs: Fr)
Performs the
*= operation. Read moresourceยงimpl PartialEq for Fr
impl PartialEq for Fr
sourceยงimpl<'b> SubAssign<&'b Fr> for Fr
impl<'b> SubAssign<&'b Fr> for Fr
sourceยงfn sub_assign(&mut self, rhs: &'b Fr)
fn sub_assign(&mut self, rhs: &'b Fr)
Performs the
-= operation. Read moresourceยงimpl SubAssign for Fr
impl SubAssign for Fr
sourceยงfn sub_assign(&mut self, rhs: Fr)
fn sub_assign(&mut self, rhs: Fr)
Performs the
-= operation. Read moreimpl Copy for Fr
impl Eq for Fr
impl StructuralEq for Fr
impl StructuralPartialEq for Fr
Auto Trait Implementationsยง
impl RefUnwindSafe for Fr
impl Send for Fr
impl Sync for Fr
impl Unpin for Fr
impl UnwindSafe for Fr
Blanket Implementationsยง
sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more