Struct sm9::Fn

source ยท
#[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

source

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]

source

pub fn from_hash(hex: &[u8]) -> Option<Fr>

for H1() and H2(), Attempts to convert a HASH result (40 bytes) to a Fr element

source

pub fn zero() -> Fr

Returns zero, the additive identity.

source

pub fn one() -> Fr

Returns one, the multiplicative identity.

source

pub fn pow(&self, exp: Fr) -> Fr

Exponentiates self by exp, where exp is a Fr element exponent.

source

pub fn inverse(&self) -> Option<Fr>

Computes the multiplicative inverse of this element, failing if the element is zero.

source

pub fn random<R>(rng: &mut R) -> Fr
where R: Rng,

Get a random element

source

pub fn is_zero(&self) -> bool

Returns true if element is the additive identity.

source

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

source

pub fn to_slice(self) -> [u8; 32]

Converts an element of Fr into a byte representation in big-endian byte order.

source

pub fn set_bit(&mut self, bit: usize, to: bool)

Set the specified bit to 0 or 1

Trait Implementationsยง

sourceยง

impl<'a, 'b> Add<&'b Fr> for &'a Fr

ยง

type Output = Fr

The resulting type after applying the + operator.
sourceยง

fn add(self, rhs: &'b Fr) -> Fr

Performs the + operation. Read more
sourceยง

impl<'b> Add<&'b Fr> for Fr

ยง

type Output = Fr

The resulting type after applying the + operator.
sourceยง

fn add(self, rhs: &'b Fr) -> Fr

Performs the + operation. Read more
sourceยง

impl<'a> Add<Fr> for &'a Fr

ยง

type Output = Fr

The resulting type after applying the + operator.
sourceยง

fn add(self, rhs: Fr) -> Fr

Performs the + operation. Read more
sourceยง

impl Add for Fr

ยง

type Output = Fr

The resulting type after applying the + operator.
sourceยง

fn add(self, rhs: Fr) -> Fr

Performs the + operation. Read more
sourceยง

impl<'b> AddAssign<&'b Fr> for Fr

sourceยง

fn add_assign(&mut self, rhs: &'b Fr)

Performs the += operation. Read more
sourceยง

impl AddAssign for Fr

sourceยง

fn add_assign(&mut self, rhs: Fr)

Performs the += operation. Read more
sourceยง

impl Clone for Fr

sourceยง

fn clone(&self) -> Fr

Returns a copy of the value. Read more
1.0.0 ยท sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
sourceยง

impl Debug for Fr

sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
sourceยง

impl FromStr for Fr

sourceยง

fn from_str(s: &str) -> Result<Fr, <Fr as FromStr>::Err>

Attempts to convert a decimal base string to a element of Fr

ยง

type Err = FieldError

The associated error which can be returned from parsing.
sourceยง

impl<'a, 'b> Mul<&'b Fr> for &'a Fr

ยง

type Output = Fr

The resulting type after applying the * operator.
sourceยง

fn mul(self, rhs: &'b Fr) -> Fr

Performs the * operation. Read more
sourceยง

impl<'b> Mul<&'b Fr> for Fr

ยง

type Output = Fr

The resulting type after applying the * operator.
sourceยง

fn mul(self, rhs: &'b Fr) -> Fr

Performs the * operation. Read more
sourceยง

impl<'a> Mul<Fr> for &'a Fr

ยง

type Output = Fr

The resulting type after applying the * operator.
sourceยง

fn mul(self, rhs: Fr) -> Fr

Performs the * operation. Read more
sourceยง

impl Mul<G1> for Fr

ยง

type Output = G1

The resulting type after applying the * operator.
sourceยง

fn mul(self, other: G1) -> G1

Performs the * operation. Read more
sourceยง

impl Mul<G2> for Fr

ยง

type Output = G2

The resulting type after applying the * operator.
sourceยง

fn mul(self, other: G2) -> G2

Performs the * operation. Read more
sourceยง

impl Mul for Fr

ยง

type Output = Fr

The resulting type after applying the * operator.
sourceยง

fn mul(self, rhs: Fr) -> Fr

Performs the * operation. Read more
sourceยง

impl<'b> MulAssign<&'b Fr> for Fr

sourceยง

fn mul_assign(&mut self, rhs: &'b Fr)

Performs the *= operation. Read more
sourceยง

impl MulAssign for Fr

sourceยง

fn mul_assign(&mut self, rhs: Fr)

Performs the *= operation. Read more
sourceยง

impl<'a> Neg for &'a Fr

ยง

type Output = Fr

The resulting type after applying the - operator.
sourceยง

fn neg(self) -> Fr

Performs the unary - operation. Read more
sourceยง

impl Neg for Fr

ยง

type Output = Fr

The resulting type after applying the - operator.
sourceยง

fn neg(self) -> Fr

Performs the unary - operation. Read more
sourceยง

impl PartialEq for Fr

sourceยง

fn eq(&self, other: &Fr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 ยท sourceยง

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
sourceยง

impl<'a, 'b> Sub<&'b Fr> for &'a Fr

ยง

type Output = Fr

The resulting type after applying the - operator.
sourceยง

fn sub(self, rhs: &'b Fr) -> Fr

Performs the - operation. Read more
sourceยง

impl<'b> Sub<&'b Fr> for Fr

ยง

type Output = Fr

The resulting type after applying the - operator.
sourceยง

fn sub(self, rhs: &'b Fr) -> Fr

Performs the - operation. Read more
sourceยง

impl<'a> Sub<Fr> for &'a Fr

ยง

type Output = Fr

The resulting type after applying the - operator.
sourceยง

fn sub(self, rhs: Fr) -> Fr

Performs the - operation. Read more
sourceยง

impl Sub for Fr

ยง

type Output = Fr

The resulting type after applying the - operator.
sourceยง

fn sub(self, rhs: Fr) -> Fr

Performs the - operation. Read more
sourceยง

impl<'b> SubAssign<&'b Fr> for Fr

sourceยง

fn sub_assign(&mut self, rhs: &'b Fr)

Performs the -= operation. Read more
sourceยง

impl SubAssign for Fr

sourceยง

fn sub_assign(&mut self, rhs: Fr)

Performs the -= operation. Read more
sourceยง

impl TryFrom<&[u8]> for Fr

ยง

type Error = FieldError

The type returned in the event of a conversion error.
sourceยง

fn try_from(hex: &[u8]) -> Result<Fr, <Fr as TryFrom<&[u8]>>::Error>

Performs the conversion.
sourceยง

impl Copy for Fr

sourceยง

impl Eq for Fr

sourceยง

impl StructuralEq for Fr

sourceยง

impl StructuralPartialEq for Fr

Auto Trait Implementationsยง

Blanket Implementationsยง

sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
sourceยง

impl<T> From<T> for T

sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

sourceยง

impl<T> Same for T

ยง

type Output = T

Should always be Self
sourceยง

impl<T> ToOwned for T
where T: Clone,

ยง

type Owned = T

The resulting type after obtaining ownership.
sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

ยง

type Error = Infallible

The type returned in the event of a conversion error.
sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

ยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
ยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

ยง

fn vzip(self) -> V