[][src]Struct amcl_wrapper_ml::field_elem::FieldElement

pub struct FieldElement { /* fields omitted */ }

Methods

impl FieldElement[src]

Represents an element of the prime field of the curve. All operations are done modulo the curve order

pub fn new() -> Self[src]

Creates a new field element with value 0

pub fn zero() -> Self[src]

pub fn one() -> Self[src]

pub fn minus_one() -> Self[src]

pub fn random() -> Self[src]

Return a random non-zero field element

pub fn random_using_rng<R: RngCore + CryptoRng>(rng: &mut R) -> Self[src]

Return a random non-zero field element using the given random number generator

pub fn is_zero(&self) -> bool[src]

pub fn is_one(&self) -> bool[src]

pub fn to_bytes(&self) -> Vec<u8>[src]

Return bytes in MSB form

pub fn from_bytes(bytes: &[u8]) -> Result<Self, SerzDeserzError>[src]

Expects bytes in MSB form

pub fn write_to_slice(&self, target: &mut [u8]) -> Result<(), SerzDeserzError>[src]

Writes bytes in MSB form to given slice. Raises exception when given slice is not of desired length.

pub fn write_to_slice_unchecked(&self, target: &mut [u8])[src]

Writes bytes in MSB form to given slice. Will panic when given slice is not of desired length.

pub fn to_bignum(&self) -> BigNum[src]

pub fn normalize(&mut self)[src]

pub fn from_msg_hash(msg: &[u8]) -> Self[src]

Hash an arbitrary sized message using SHAKE and return output as a field element

pub fn add_assign_(&mut self, b: &Self)[src]

Add a field element to itself. self = self + b

pub fn sub_assign_(&mut self, b: &Self)[src]

Subtract a field element from itself. self = self - b

pub fn plus(&self, b: &Self) -> Self[src]

Return sum of a field element and itself. self + b

pub fn minus(&self, b: &Self) -> Self[src]

Return difference of a field element and itself. self - b

pub fn multiply(&self, b: &Self) -> Self[src]

Multiply 2 field elements modulus the order of the curve. (field_element_a * field_element_b) % modulus

pub fn square(&self) -> Self[src]

Calculate square of a field element modulo the curve order, i.e a^2 % MODULUS

pub fn pow(&self, exp: &Self) -> Self[src]

Exponentiation modulo curve order, i.e. self^exp % MODULUS

pub fn negation(&self) -> Self[src]

Return negative of field element

pub fn negate(&mut self)[src]

pub fn inverse(&self) -> Self[src]

Calculate inverse of a field element modulo the curve order, i.e a^-1 % MODULUS

pub fn inverse_mut(&mut self)[src]

pub fn shift_right(&self, k: usize) -> Self[src]

pub fn shift_left(&self, k: usize) -> Self[src]

pub fn is_even(&self) -> bool[src]

pub fn is_odd(&self) -> bool[src]

pub fn to_bitvectors(&self) -> Vec<Vec<u8>>[src]

Gives vectors of bit-vectors for the Big number. Each limb has a separate bit-vector, hence upto NLEN bit-vectors possible. Least significant bytes come first. NOT SIDE CHANNEL RESISTANT

pub fn to_bits(&self) -> Vec<u8>[src]

Returns bits. Least significant bits come first

pub fn to_wnaf(&self, w: usize) -> Vec<i8>[src]

Conversion to wNAF, i.e. windowed Non Adjacent form Taken from Guide to Elliptic Curve Cryptography book, "Algorithm 3.35 Computing the width-w NAF of a positive integer" with modification at step 2.1, if k_i >= 2^(w-1), k_i = k_i - 2^w

pub fn to_power_of_2_base(&self, n: usize) -> Vec<u8>[src]

Convert to base that is power of 2. Does not handle negative nos or base higher than 2^7

pub fn from_power_of_2_base(repr: &[u8], n: usize) -> Self[src]

Convert to base that is power of 2. Does not handle negative nos or base higher than 2^7

pub fn nth_bit(&self, n: usize) -> u8[src]

Return n-th bit, n starts from 0

pub fn or(&mut self, other: &Self)[src]

pub fn batch_invert(elems: &[Self]) -> (Vec<Self>, Self)[src]

Takes a bunch of field elements and returns the inverse of all field elements. Also returns the product of all inverses as its computed as a side effect. For an input of n elements, rather than doing n inversions, does only 1 inversion but 3n multiplications. eg batch_invert([a, b, c, d]) returns ([1/a, 1/b, 1/c, 1/d], 1/a * 1/b * 1/c * 1/d) Algorithm taken from Guide to Elliptic Curve Cryptography book, "Algorithm 2.26 Simultaneous inversion"

pub fn to_hex(&self) -> String[src]

Returns hex string in big endian

pub fn from_hex(s: String) -> Result<Self, SerzDeserzError>[src]

Create big number from hex string in big endian

pub fn reduce_dmod_curve_order(x: &DoubleBigNum) -> BigNum[src]

Useful for reducing product of BigNums. Uses Barrett reduction

pub fn parse_hex_as_bignum(val: String) -> Result<BigNum, SerzDeserzError>[src]

Parse given hex string as BigNum in constant time.

pub fn cmove(&self, b: &Self, c: bool) -> Self[src]

If c is False, cmove returns self, otherwise it returns b.

pub fn sgn0(&self) -> Sgn0[src]

returns either +1 or -1 indicating the "sign" of x, where sgn0(x) == -1 just when x is "negative". In other words, this function always considers 0 to be positive.

pub fn negate_if(&self, sgn: Sgn0) -> Self[src]

pub const fn from_array(w: [Limb; 7]) -> FieldElement[src]

Use this instead of static ref and new_int. This allows for initialization at compile time

Trait Implementations

impl<'a> Add<&'a FieldElement> for FieldElement[src]

type Output = Self

The resulting type after applying the + operator.

impl<'a, '_> Add<&'a FieldElement> for &'_ FieldElement[src]

type Output = FieldElement

The resulting type after applying the + operator.

impl Add<FieldElement> for FieldElement[src]

type Output = Self

The resulting type after applying the + operator.

impl<'_> Add<FieldElement> for &'_ FieldElement[src]

type Output = FieldElement

The resulting type after applying the + operator.

impl<'a> AddAssign<&'a FieldElement> for FieldElement[src]

impl AddAssign<FieldElement> for FieldElement[src]

impl Clone for FieldElement[src]

impl Debug for FieldElement[src]

impl Default for FieldElement[src]

impl<'a> Deserialize<'a> for FieldElement[src]

impl Display for FieldElement[src]

impl Drop for FieldElement[src]

impl Eq for FieldElement[src]

impl<'_> From<&'_ [u8; 48]> for FieldElement[src]

impl From<BIG> for FieldElement[src]

impl From<i32> for FieldElement[src]

impl From<u32> for FieldElement[src]

impl From<u64> for FieldElement[src]

impl From<u8> for FieldElement[src]

impl Hash for FieldElement[src]

impl<'_> Mul<&'_ FieldElement> for G1[src]

type Output = Self

The resulting type after applying the * operator.

impl<'_, '_> Mul<&'_ FieldElement> for &'_ G1[src]

type Output = G1

The resulting type after applying the * operator.

impl<'_> Mul<&'_ FieldElement> for G2[src]

type Output = Self

The resulting type after applying the * operator.

impl<'_, '_> Mul<&'_ FieldElement> for &'_ G2[src]

type Output = G2

The resulting type after applying the * operator.

impl<'_> Mul<&'_ G1> for FieldElement[src]

type Output = G1

The resulting type after applying the * operator.

impl<'_, '_> Mul<&'_ G1> for &'_ FieldElement[src]

type Output = G1

The resulting type after applying the * operator.

impl<'_> Mul<&'_ G2> for FieldElement[src]

type Output = G2

The resulting type after applying the * operator.

impl<'_, '_> Mul<&'_ G2> for &'_ FieldElement[src]

type Output = G2

The resulting type after applying the * operator.

impl<'a> Mul<&'a FieldElement> for FieldElement[src]

type Output = FieldElement

The resulting type after applying the * operator.

impl<'a, '_> Mul<&'a FieldElement> for &'_ FieldElement[src]

type Output = FieldElement

The resulting type after applying the * operator.

impl Mul<FieldElement> for FieldElement[src]

type Output = Self

The resulting type after applying the * operator.

impl<'_> Mul<FieldElement> for &'_ FieldElement[src]

type Output = FieldElement

The resulting type after applying the * operator.

impl Mul<FieldElement> for G1[src]

type Output = Self

The resulting type after applying the * operator.

impl<'_> Mul<FieldElement> for &'_ G1[src]

type Output = G1

The resulting type after applying the * operator.

impl Mul<FieldElement> for G2[src]

type Output = Self

The resulting type after applying the * operator.

impl<'_> Mul<FieldElement> for &'_ G2[src]

type Output = G2

The resulting type after applying the * operator.

impl Mul<G1> for FieldElement[src]

type Output = G1

The resulting type after applying the * operator.

impl<'_> Mul<G1> for &'_ FieldElement[src]

type Output = G1

The resulting type after applying the * operator.

impl Mul<G2> for FieldElement[src]

type Output = G2

The resulting type after applying the * operator.

impl<'_> Mul<G2> for &'_ FieldElement[src]

type Output = G2

The resulting type after applying the * operator.

impl Neg for FieldElement[src]

type Output = Self

The resulting type after applying the - operator.

impl<'_> Neg for &'_ FieldElement[src]

type Output = FieldElement

The resulting type after applying the - operator.

impl Ord for FieldElement[src]

impl PartialEq<FieldElement> for FieldElement[src]

impl PartialOrd<FieldElement> for FieldElement[src]

impl Serialize for FieldElement[src]

impl<'a> Sub<&'a FieldElement> for FieldElement[src]

type Output = Self

The resulting type after applying the - operator.

impl<'a, '_> Sub<&'a FieldElement> for &'_ FieldElement[src]

type Output = FieldElement

The resulting type after applying the - operator.

impl Sub<FieldElement> for FieldElement[src]

type Output = Self

The resulting type after applying the - operator.

impl<'_> Sub<FieldElement> for &'_ FieldElement[src]

type Output = FieldElement

The resulting type after applying the - operator.

impl<'a> SubAssign<&'a FieldElement> for FieldElement[src]

impl SubAssign<FieldElement> for FieldElement[src]

impl Zeroize for FieldElement[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

impl<Z> Zeroize for Z where
    Z: DefaultIsZeroes
[src]