Skip to main content

FieldElement

Struct FieldElement 

Source
pub struct FieldElement(pub(crate) ConstMontyForm<MODULUS, { MODULUS::LIMBS }>);

Tuple Fields§

§0: ConstMontyForm<MODULUS, { MODULUS::LIMBS }>

Implementations§

Source§

impl FieldElement

Source

pub const A_PLUS_TWO_OVER_FOUR: Self

Source

pub const DECAF_FACTOR: Self

Source

pub const EDWARDS_D: Self

Source

pub const J: Self

Source

pub const MINUS_ONE: Self

Source

pub const NEG_EDWARDS_D: Self

Source

pub const NEG_FOUR_TIMES_TWISTED_D: Self

Source

pub const ONE: Self

Source

pub const TWO: Self

Source

pub const TWISTED_D: Self

Source

pub const TWO_TIMES_TWISTED_D: Self

Source

pub const Z: Self

Source

pub const ZERO: Self

Source

pub fn is_negative(&self) -> Choice

Source

pub fn is_zero(&self) -> Choice

Source

pub fn invert(&self) -> Self

Inverts a field element

Source

pub fn square(&self) -> Self

Source

fn square_n<const N: u32>(&self) -> FieldElement

Squares a field element n times

Source

pub fn is_square(&self) -> Choice

Source

pub fn unchecked_sqrt(&self) -> FieldElement

Source

pub fn to_bytes(self) -> [u8; 56]

Source

pub fn to_bytes_extended(self) -> [u8; 57]

Source

pub fn from_bytes(bytes: &[u8; 56]) -> Self

Source

pub fn from_bytes_extended(bytes: &[u8; 57]) -> Self

Source

pub fn from_repr(bytes: &[u8; 56]) -> CtOption<Self>

Source

pub fn double(&self) -> Self

Source

pub(crate) fn inverse_square_root(&self) -> (FieldElement, Choice)

Computes the inverse square root of a field element Returns the result and a boolean to indicate whether self was a Quadratic residue

Source

pub(crate) fn sqrt_ratio( u: &FieldElement, v: &FieldElement, ) -> (FieldElement, Choice)

Computes the square root ratio of two elements

Source

pub(crate) fn div_by_2(&self) -> FieldElement

Source

pub(crate) fn map_to_curve_elligator2(&self) -> AffinePoint

Source

pub(crate) fn map_to_curve_decaf448(&self) -> TwistedExtendedPoint

Trait Implementations§

Source§

impl Add<&FieldElement> for &FieldElement

Source§

type Output = FieldElement

The resulting type after applying the + operator.
Source§

fn add(self, other: &FieldElement) -> FieldElement

Performs the + operation. Read more
Source§

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

Source§

type Output = FieldElement

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

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

Source§

type Output = FieldElement

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for FieldElement

Source§

type Output = FieldElement

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign<&FieldElement> for FieldElement

Source§

fn add_assign(&mut self, other: &FieldElement)

Performs the += operation. Read more
Source§

impl AddAssign for FieldElement

Source§

fn add_assign(&mut self, other: FieldElement)

Performs the += operation. Read more
Source§

impl BatchInvert for FieldElement

Source§

fn batch_invert_in_place( elements: &mut [Self], scratch_space: &mut [Self], ) -> Self

Inverts each field element in elements (when non-zero). Zero-valued elements are left as zero. Read more
Source§

fn batch_invert_in_place_vartime( elements: &mut [Self], scratch_space: &mut [Self], ) -> Self

Variable-time batch inversion. Read more
Source§

impl Clone for FieldElement

Source§

fn clone(&self) -> FieldElement

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 ConditionallySelectable for FieldElement

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 ConstantTimeEq for FieldElement

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 Debug for FieldElement

Source§

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

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

impl Default for FieldElement

Source§

fn default() -> FieldElement

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

impl Display for FieldElement

Source§

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

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

impl Field for FieldElement

Source§

const ZERO: Self = Self::ZERO

The zero element of the field, the additive identity.
Source§

const ONE: Self = Self::ONE

The one element of the field, the multiplicative identity.
Source§

fn try_random<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error>

Returns an element chosen uniformly at random using a user-provided fallible RNG. Read more
Source§

fn square(&self) -> Self

Squares this element.
Source§

fn double(&self) -> Self

Doubles this element.
Source§

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

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

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

Returns the square root of the field element, if it is quadratic residue. Read more
Source§

fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self)

Computes: Read more
Source§

fn random<R>(rng: &mut R) -> Self
where R: Rng + ?Sized,

Returns an element chosen uniformly at random using a user-provided infallible RNG. Read more
Source§

fn is_zero(&self) -> Choice

Returns true iff this element is zero.
Source§

fn is_zero_vartime(&self) -> bool

Returns true iff this element is zero. Read more
Source§

fn cube(&self) -> Self

Cubes this element.
Source§

fn sqrt_alt(&self) -> (Choice, Self)

Equivalent to Self::sqrt_ratio(self, one()). Read more
Source§

fn pow<S>(&self, exp: S) -> Self
where S: AsRef<[u64]>,

Exponentiates self by exp, where exp is a little-endian order integer exponent. Read more
Source§

fn pow_vartime<S>(&self, exp: S) -> Self
where S: AsRef<[u64]>,

Exponentiates self by exp, where exp is a little-endian order integer exponent. Read more
Source§

impl LowerHex for FieldElement

Source§

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

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

impl Mul<&FieldElement> for &FieldElement

Source§

type Output = FieldElement

The resulting type after applying the * operator.
Source§

fn mul(self, other: &FieldElement) -> FieldElement

Performs the * operation. Read more
Source§

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

Source§

type Output = FieldElement

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

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

Source§

type Output = FieldElement

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for FieldElement

Source§

type Output = FieldElement

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<&FieldElement> for FieldElement

Source§

fn mul_assign(&mut self, other: &FieldElement)

Performs the *= operation. Read more
Source§

impl MulAssign for FieldElement

Source§

fn mul_assign(&mut self, other: FieldElement)

Performs the *= operation. Read more
Source§

impl Neg for &FieldElement

Source§

type Output = FieldElement

The resulting type after applying the - operator.
Source§

fn neg(self) -> FieldElement

Performs the unary - operation. Read more
Source§

impl Neg for FieldElement

Source§

type Output = FieldElement

The resulting type after applying the - operator.
Source§

fn neg(self) -> FieldElement

Performs the unary - operation. Read more
Source§

impl PartialEq for FieldElement

Source§

fn eq(&self, other: &FieldElement) -> 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<'a> Product<&'a FieldElement> for FieldElement

Source§

fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Product for FieldElement

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Reduce<Array<u8, UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B1>, B0>, B0>>> for FieldElement

Source§

fn reduce(value: &Array<u8, U84>) -> Self

Reduces self modulo Modulus.
Source§

impl Reduce<Array<u8, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B1>, B0>, B0>, B0>>> for FieldElement

Source§

fn reduce(value: &Array<u8, U56>) -> Self

Reduces self modulo Modulus.
Source§

impl Sub<&FieldElement> for &FieldElement

Source§

type Output = FieldElement

The resulting type after applying the - operator.
Source§

fn sub(self, other: &FieldElement) -> FieldElement

Performs the - operation. Read more
Source§

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

Source§

type Output = FieldElement

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Source§

type Output = FieldElement

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub for FieldElement

Source§

type Output = FieldElement

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign<&FieldElement> for FieldElement

Source§

fn sub_assign(&mut self, other: &FieldElement)

Performs the -= operation. Read more
Source§

impl SubAssign for FieldElement

Source§

fn sub_assign(&mut self, other: FieldElement)

Performs the -= operation. Read more
Source§

impl<'a> Sum<&'a FieldElement> for FieldElement

Source§

fn sum<I: Iterator<Item = &'a FieldElement>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum for FieldElement

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl UpperHex for FieldElement

Source§

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

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

impl Copy for FieldElement

Source§

impl DefaultIsZeroes for FieldElement

Source§

impl Eq for FieldElement

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> 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> ConditionallyNegatable for T
where T: ConditionallySelectable, &'a T: for<'a> Neg<Output = T>,

Source§

fn conditional_negate(&mut self, choice: Choice)

Negate self if choice == Choice(1); otherwise, leave it unchanged. 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

Source§

type Output = T

Should always be Self
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.
Source§

impl<Z> Zeroize for Z
where Z: DefaultIsZeroes,

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<T, Rhs, Output> GroupOps<Rhs, Output> for T
where T: Add<Rhs, Output = Output> + Sub<Rhs, Output = Output> + AddAssign<Rhs> + SubAssign<Rhs>,

Source§

impl<T, Rhs, Output> GroupOpsOwned<Rhs, Output> for T
where T: for<'r> GroupOps<&'r Rhs, Output>,

Source§

impl<T, Rhs, Output> ScalarMul<Rhs, Output> for T
where T: Mul<Rhs, Output = Output> + MulAssign<Rhs>,

Source§

impl<T, Rhs, Output> ScalarMulOwned<Rhs, Output> for T
where T: for<'r> ScalarMul<&'r Rhs, Output>,