Skip to main content

FpElement

Struct FpElement 

Source
pub struct FpElement<MOD, const LIMBS: usize>
where MOD: ConstPrimeMontyParams<LIMBS>,
{ /* private fields */ }
Expand description

An element of the prime field $\mathbb{F}_p = \mathbb{Z}/p\mathbb{Z}$, stored in Montgomery form.

The internal value uses crypto-bigint’s ConstMontyForm, so arithmetic is performed in Montgomery representation while the public constructors and accessors accept and return canonical integers.

Implementations§

Source§

impl<MOD, const LIMBS: usize> FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source

pub fn from_uint(x: Uint<LIMBS>) -> Self

Goes from an Uint<LIMBS> to an element of $\mathbb{F}_p$

§Arguments
  • x - An integer (type: Uint<LIMBS>)
§Returns

Element of $\mathbb{F}_p$ (type: Self)

Source

pub fn from_words(words: [u64; LIMBS]) -> Self

Goes from an [u64; LIMBS] to an element of $\mathbb{F}_p$

§Arguments
  • words - A vec of u64 (type: [u64; LIMBS])
§Returns

Element of $\mathbb{F}_p$ (type: Self)

Source

pub fn from_limbs(limbs: &[u64]) -> Self

Goes from an &[u64] to an element of $\mathbb{F}_p$

§Arguments
  • limbs - A vec of u64 (type: &[u64])
§Returns

Element of $\mathbb{F}_p$ (type: Self)

Source

pub fn from_u64(val: u64) -> Self

Goes from an u64 to an element of $\mathbb{F}_p$

§Arguments
  • val - A u64 int (type: u64)
§Returns

Element of $\mathbb{F}_p$ (type: Self)

Source

pub fn as_uint(&self) -> Uint<LIMBS>

Goes from an element of $\mathbb{F}_p$ to the corresponding Uint

§Arguments
  • &self - Element of $\mathbb{F}_p$ (type: Self)
§Returns

The corresponding Uint (type: Uint<LIMBS>)

Source

pub fn as_limbs(&self) -> [u64; LIMBS]

Goes from an element of $\mathbb{F}_p$ to the limbs

§Arguments
  • &self - Element of $\mathbb{F}_p$ (type: Self)
§Returns

The limbs giving the integer (type: [u64; LIMBS])

Source

pub fn to_montgomery(&self) -> Uint<LIMBS>

Gives a montgomery Uint<LIMBS> from an $\mathbb{F}_p$ element

§Arguments
  • &self - Element of $\mathbb{F}_p$ (type: Self)
§Returns

Integer in montgomery from (type: Uint<LIMBS>)

Source

pub fn from_montgomery(mont: Uint<LIMBS>) -> Self

Gives an element of $\mathbb{F}_p$ from the Montgomery representation.

§Arguments
  • mont - The input montgomery value (type: Uint<LIMBS>)
§Returns

Corresponding element of $\mathbb{F}_p$ (type: Self)

Trait Implementations§

Source§

impl<MOD, const LIMBS: usize> Add for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

type Output = FpElement<MOD, LIMBS>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<MOD, const LIMBS: usize> Clone for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS> + Clone,

Source§

fn clone(&self) -> FpElement<MOD, LIMBS>

Returns a duplicate 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<MOD, const LIMBS: usize> ConditionallySelectable for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self

Select a or b according to choice. Read more
Source§

fn conditional_assign(&mut self, other: &Self, choice: Choice)

Conditionally assign other to self, according to choice. Read more
Source§

fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)

Conditionally swap self and other if choice == 1; otherwise, reassign both unto themselves. Read more
Source§

impl<MOD, const LIMBS: usize> ConstantTimeEq for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

fn ct_eq(&self, other: &Self) -> Choice

Determine if two items are equal. Read more
Source§

fn ct_ne(&self, other: &Self) -> Choice

Determine if two items are NOT equal. Read more
Source§

impl<MOD, const LIMBS: usize> Debug for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS> + Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<MOD, const LIMBS: usize> Default for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<MOD, const LIMBS: usize> Display for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<MOD, const LIMBS: usize> FieldFromRepr for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

type Repr = Uint<LIMBS>

The representation type accepted by this field.
Source§

fn from_repr(x: Self::Repr) -> Self

Constructs a field element from the given representation.
Source§

impl<MOD, const LIMBS: usize> FieldOps for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

fn zero() -> Self

Create the constant zero
Source§

fn one() -> Self

Create the constant one
Source§

fn from_u64(x: u64) -> Self

Convert u64 to the field.
Source§

fn is_zero(&self) -> Choice

Check if element is zero
Source§

fn is_one(&self) -> Choice

Check if element is one
Source§

fn negate(&self) -> Self

Negate self to -self
Source§

fn add(&self, rhs: &Self) -> Self

Add rhs to self
Source§

fn sub(&self, rhs: &Self) -> Self

Sub rhs from self
Source§

fn mul(&self, rhs: &Self) -> Self

Multipliy self by rhs
Source§

fn square(&self) -> Self

Square self
Source§

fn double(&self) -> Self

Double self
Source§

fn invert(&self) -> CtOption<Self>

Invert self
Source§

fn frobenius(&self) -> Self

Compute self^p the frobenius acting on self
Source§

fn norm(&self) -> Self

compute the norm of self down to $\mathbb{F}_p$ (as an element of type Self)
Source§

fn trace(&self) -> Self

compute the trace of self down to $\mathbb{F}_p$ (as an element of type Self)
Source§

fn sqrt(&self) -> CtOption<Self>

Returns a squareroot if it exists Read more
Source§

fn legendre(&self) -> i8

Computes the “Legendre symbol” i.e., if 0,1,-1 depending if self is 0, a square or a nonsquare.
Source§

fn characteristic() -> Vec<u64>

Returns the characteristic of the field.
Source§

fn degree() -> u32

Returns the extension degree of the field.
Source§

fn div(&self, rhs: &Self) -> CtOption<Self>

Divide self by rhs
Source§

fn pow_vartime(&self, exp: &[u64]) -> Self

self^exp using square-and multiply (litte-endian bit order) Read more
Source§

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

self^pow in constant time using a Montgomery ladder Read more
Source§

fn frobenius_pow(&self, k: u32) -> Self

Compute self^{p^k} a power of the frobenius
Source§

fn inverse_and_sqrt(&self) -> (CtOption<Self>, CtOption<Self>)

Computes the inverse and square root of self Read more
Source§

fn inv_sqrt(&self) -> CtOption<Self>

Computes the square root the inverse of self Read more
Source§

fn invertme_sqrtother(&self, rhs: &Self) -> (CtOption<Self>, CtOption<Self>)

Computes the inverse of self and square root of rhs Read more
Source§

fn sqrt_ratio(&self, rhs: &Self) -> CtOption<Self>

Computes the squareroot of a ratio self/rhs Read more
Source§

impl<MOD, const LIMBS: usize> FieldRandom for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

fn random(rng: &mut (impl CryptoRng + Rng)) -> Self

Sample a uniformly random element of Fp using a CSPRNG.

Source§

impl<MOD, const LIMBS: usize> Mul for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

type Output = FpElement<MOD, LIMBS>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<MOD, const LIMBS: usize> Neg for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

type Output = FpElement<MOD, LIMBS>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<MOD, const LIMBS: usize> PartialEq for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS> + PartialEq,

Source§

fn eq(&self, other: &FpElement<MOD, LIMBS>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<MOD, const LIMBS: usize> Sub for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Source§

type Output = FpElement<MOD, LIMBS>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<MOD, const LIMBS: usize> Copy for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS> + Copy,

Source§

impl<MOD, const LIMBS: usize> Eq for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS> + Eq,

Source§

impl<MOD, const LIMBS: usize> StructuralPartialEq for FpElement<MOD, LIMBS>
where MOD: ConstPrimeMontyParams<LIMBS>,

Auto Trait Implementations§

§

impl<MOD, const LIMBS: usize> Freeze for FpElement<MOD, LIMBS>

§

impl<MOD, const LIMBS: usize> RefUnwindSafe for FpElement<MOD, LIMBS>
where MOD: RefUnwindSafe,

§

impl<MOD, const LIMBS: usize> Send for FpElement<MOD, LIMBS>

§

impl<MOD, const LIMBS: usize> Sync for FpElement<MOD, LIMBS>

§

impl<MOD, const LIMBS: usize> Unpin for FpElement<MOD, LIMBS>
where MOD: Unpin,

§

impl<MOD, const LIMBS: usize> UnsafeUnpin for FpElement<MOD, LIMBS>

§

impl<MOD, const LIMBS: usize> UnwindSafe for FpElement<MOD, LIMBS>
where MOD: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.