Skip to main content

MontgomeryElement

Struct MontgomeryElement 

Source
pub struct MontgomeryElement {
    standard: FieldElement,
}
Expand description

A field element that tracks both standard and Montgomery forms.

Internally stores the standard value. Arithmetic is performed in standard form for correctness. The Montgomery representation (aR mod p) is available for hardware comparison.

Fields§

§standard: FieldElement

The standard (non-Montgomery) value.

Implementations§

Source§

impl MontgomeryElement

Source

pub fn from_field(a: FieldElement) -> Self

Wraps a standard field element for Montgomery-domain operations.

Source

pub fn to_field(self) -> FieldElement

Returns the standard (non-Montgomery) field element.

Source

pub fn to_mont_repr(self) -> FieldElement

Returns the Montgomery representation aR mod p.

This is what the hardware stores internally.

Source

pub fn from_mont_repr(mont_repr: FieldElement) -> Self

Constructs from a Montgomery representation aR mod p.

Recovers the standard value a by halving 128 times (each halving computes x * 2^{-1} mod p).

Source

pub fn sqr(self) -> Self

Montgomery squaring.

Source

pub fn curve(&self) -> Curve

Returns the curve.

Source

pub fn zero(curve: Curve) -> Self

The zero element.

Source

pub fn one(curve: Curve) -> Self

The multiplicative identity.

Source

pub fn pow(self, exp: &[u64; 4], num_bits: usize) -> Self

Modular exponentiation.

Source

pub fn fifth_root(self) -> Self

Computes the fifth root.

Source

pub fn from_raw_mont_limbs(limbs: [u64; 4], curve: Curve) -> Result<Self, Error>

Constructs from raw limbs in Montgomery representation.

The limbs are interpreted as aR mod p and converted to the standard value internally.

§Errors

Returns Error::OutOfRange if the limbs are not less than the modulus.

Trait Implementations§

Source§

impl Clone for MontgomeryElement

Source§

fn clone(&self) -> MontgomeryElement

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

Source§

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

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

impl Hash for MontgomeryElement

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul for MontgomeryElement

Source§

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

Montgomery multiplication: produces a * b in the Montgomery domain.

Source§

type Output = MontgomeryElement

The resulting type after applying the * operator.
Source§

impl PartialEq for MontgomeryElement

Source§

fn eq(&self, other: &MontgomeryElement) -> 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 Copy for MontgomeryElement

Source§

impl Eq for MontgomeryElement

Source§

impl StructuralPartialEq for MontgomeryElement

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