pub struct ConstMontyForm<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> { /* private fields */ }
Expand description

An integer in Montgomery form modulo MOD, represented using LIMBS limbs. The modulus is constant, so it cannot be set at runtime.

Internally, the value is stored in Montgomery form (multiplied by MOD::ONE) until it is retrieved.

Implementations§

source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> ConstMontyForm<MOD, LIMBS>

source

pub const fn add(&self, rhs: &ConstMontyForm<MOD, LIMBS>) -> Self

Adds rhs.

source§

impl<MOD: ConstMontyParams<SAT_LIMBS>, const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> ConstMontyForm<MOD, SAT_LIMBS>
where Odd<Uint<SAT_LIMBS>>: PrecomputeInverter<Inverter = BernsteinYangInverter<SAT_LIMBS, UNSAT_LIMBS>, Output = Uint<SAT_LIMBS>>,

source

pub const fn inv(&self) -> ConstCtOption<Self>

Computes self^-1 representing the multiplicative inverse of self. I.e. self * self^-1 = 1. If the number was invertible, the second element of the tuple is the truthy value, otherwise it is the falsy value (in which case the first element’s value is unspecified).

source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> ConstMontyForm<MOD, LIMBS>

source

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

Multiplies by rhs.

source

pub const fn square(&self) -> Self

Computes the (reduced) square.

source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> ConstMontyForm<MOD, LIMBS>

source

pub const fn neg(&self) -> Self

Negates the number.

source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> ConstMontyForm<MOD, LIMBS>

source

pub const fn pow<const RHS_LIMBS: usize>( &self, exponent: &Uint<RHS_LIMBS> ) -> ConstMontyForm<MOD, LIMBS>

Raises to the exponent power.

source

pub const fn pow_bounded_exp<const RHS_LIMBS: usize>( &self, exponent: &Uint<RHS_LIMBS>, exponent_bits: u32 ) -> ConstMontyForm<MOD, LIMBS>

Raises to the exponent power, with exponent_bits representing the number of (least significant) bits to take into account for the exponent.

NOTE: exponent_bits may be leaked in the time pattern.

source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> ConstMontyForm<MOD, LIMBS>

source

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

Subtracts rhs.

source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> ConstMontyForm<MOD, LIMBS>

source

pub const ZERO: Self = _

The representation of 0 mod MOD.

source

pub const ONE: Self = _

The representation of 1 mod MOD.

source

pub const fn new(integer: &Uint<LIMBS>) -> Self

Instantiates a new ConstMontyForm that represents this integer mod MOD.

source

pub const fn retrieve(&self) -> Uint<LIMBS>

Retrieves the integer currently encoded in this ConstMontyForm, guaranteed to be reduced.

source

pub const fn as_montgomery(&self) -> &Uint<LIMBS>

Access the ConstMontyForm value in Montgomery form.

source

pub fn as_montgomery_mut(&mut self) -> &mut Uint<LIMBS>

Mutably access the ConstMontyForm value in Montgomery form.

source

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

Create a ConstMontyForm from a value in Montgomery form.

source

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

Extract the value from the ConstMontyForm in Montgomery form.

source

pub const fn div_by_2(&self) -> Self

Performs division by 2, that is returns x such that x + x = self.

Trait Implementations§

source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Add<&ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the + operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Add<&ConstMontyForm<MOD, LIMBS>> for ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the + operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Add<ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the + operator.
source§

fn add(self, rhs: ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the + operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Add for ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the + operator.
source§

fn add(self, rhs: ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the + operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> AddAssign<&ConstMontyForm<MOD, LIMBS>> for ConstMontyForm<MOD, LIMBS>

source§

fn add_assign(&mut self, rhs: &Self)

Performs the += operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> AddAssign for ConstMontyForm<MOD, LIMBS>

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl<MOD: Clone + ConstMontyParams<LIMBS>, const LIMBS: usize> Clone for ConstMontyForm<MOD, LIMBS>

source§

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

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<MOD: ConstMontyParams<LIMBS> + Copy, const LIMBS: usize> ConditionallySelectable for ConstMontyForm<MOD, 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: ConstMontyParams<LIMBS>, const LIMBS: usize> ConstZero for ConstMontyForm<MOD, LIMBS>

source§

const ZERO: Self = Self::ZERO

The value 0.
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> ConstantTimeEq for ConstMontyForm<MOD, 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: Debug + ConstMontyParams<LIMBS>, const LIMBS: usize> Debug for ConstMontyForm<MOD, LIMBS>

source§

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

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

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Default for ConstMontyForm<MOD, LIMBS>

source§

fn default() -> Self

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

impl<'de, MOD, const LIMBS: usize> Deserialize<'de> for ConstMontyForm<MOD, LIMBS>
where MOD: ConstMontyParams<LIMBS>, Uint<LIMBS>: Encoding,

Available on crate feature serde only.
source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<const LIMBS: usize, P: ConstMontyParams<LIMBS>> From<&ConstMontyForm<P, LIMBS>> for MontyForm<LIMBS>

source§

fn from(const_monty_form: &ConstMontyForm<P, LIMBS>) -> Self

Converts to this type from the input type.
source§

impl<MOD: ConstMontyParams<SAT_LIMBS>, const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> Invert for ConstMontyForm<MOD, SAT_LIMBS>
where Odd<Uint<SAT_LIMBS>>: PrecomputeInverter<Inverter = BernsteinYangInverter<SAT_LIMBS, UNSAT_LIMBS>, Output = Uint<SAT_LIMBS>>,

§

type Output = CtOption<ConstMontyForm<MOD, SAT_LIMBS>>

Output of the inversion.
source§

fn invert(&self) -> Self::Output

Computes the inverse.
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Mul<&ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the * operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Mul<&ConstMontyForm<MOD, LIMBS>> for ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the * operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Mul<ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the * operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Mul for ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the * operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> MulAssign<&ConstMontyForm<MOD, LIMBS>> for ConstMontyForm<MOD, LIMBS>

source§

fn mul_assign(&mut self, rhs: &ConstMontyForm<MOD, LIMBS>)

Performs the *= operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> MulAssign for ConstMontyForm<MOD, LIMBS>

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize, const RHS_LIMBS: usize> MultiExponentiateBoundedExp<Uint<RHS_LIMBS>, [(ConstMontyForm<MOD, LIMBS>, Uint<RHS_LIMBS>)]> for ConstMontyForm<MOD, LIMBS>

Available on crate feature alloc only.
source§

fn multi_exponentiate_bounded_exp( bases_and_exponents: &[(Self, Uint<RHS_LIMBS>)], exponent_bits: u32 ) -> Self

Calculates x1 ^ k1 * ... * xn ^ kn.
source§

impl<const N: usize, MOD: ConstMontyParams<LIMBS>, const LIMBS: usize, const RHS_LIMBS: usize> MultiExponentiateBoundedExp<Uint<RHS_LIMBS>, [(ConstMontyForm<MOD, LIMBS>, Uint<RHS_LIMBS>); N]> for ConstMontyForm<MOD, LIMBS>

source§

fn multi_exponentiate_bounded_exp( bases_and_exponents: &[(Self, Uint<RHS_LIMBS>); N], exponent_bits: u32 ) -> Self

Calculates x1 ^ k1 * ... * xn ^ kn.
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Neg for &ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the - operator.
source§

fn neg(self) -> ConstMontyForm<MOD, LIMBS>

Performs the unary - operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Neg for ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl<MOD: PartialEq + ConstMontyParams<LIMBS>, const LIMBS: usize> PartialEq for ConstMontyForm<MOD, LIMBS>

source§

fn eq(&self, other: &ConstMontyForm<MOD, LIMBS>) -> 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<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize, const RHS_LIMBS: usize> PowBoundedExp<Uint<RHS_LIMBS>> for ConstMontyForm<MOD, LIMBS>

source§

fn pow_bounded_exp( &self, exponent: &Uint<RHS_LIMBS>, exponent_bits: u32 ) -> Self

Raises to the exponent power, with exponent_bits representing the number of (least significant) bits to take into account for the exponent. Read more
source§

impl<MOD, const LIMBS: usize> Random for ConstMontyForm<MOD, LIMBS>
where MOD: ConstMontyParams<LIMBS>,

Available on crate feature rand_core only.
source§

fn random(rng: &mut impl CryptoRngCore) -> Self

Generate a cryptographically secure random value.
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Retrieve for ConstMontyForm<MOD, LIMBS>

§

type Output = Uint<LIMBS>

The original type.
source§

fn retrieve(&self) -> Self::Output

Convert the number back from the optimized representation.
source§

impl<MOD, const LIMBS: usize> Serialize for ConstMontyForm<MOD, LIMBS>
where MOD: ConstMontyParams<LIMBS>, Uint<LIMBS>: Encoding,

Available on crate feature serde only.
source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Square for ConstMontyForm<MOD, LIMBS>

source§

fn square(&self) -> Self

Computes the same as self * self, but may be more efficient.
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Sub<&ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the - operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Sub<&ConstMontyForm<MOD, LIMBS>> for ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the - operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Sub<ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the - operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> Sub for ConstMontyForm<MOD, LIMBS>

§

type Output = ConstMontyForm<MOD, LIMBS>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: ConstMontyForm<MOD, LIMBS>) -> ConstMontyForm<MOD, LIMBS>

Performs the - operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> SubAssign<&ConstMontyForm<MOD, LIMBS>> for ConstMontyForm<MOD, LIMBS>

source§

fn sub_assign(&mut self, rhs: &Self)

Performs the -= operation. Read more
source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> SubAssign for ConstMontyForm<MOD, LIMBS>

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl<MOD: Copy + ConstMontyParams<LIMBS>, const LIMBS: usize> Copy for ConstMontyForm<MOD, LIMBS>

source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> DefaultIsZeroes for ConstMontyForm<MOD, LIMBS>

Available on crate feature zeroize only.
source§

impl<MOD: Eq + ConstMontyParams<LIMBS>, const LIMBS: usize> Eq for ConstMontyForm<MOD, LIMBS>

source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> StructuralEq for ConstMontyForm<MOD, LIMBS>

source§

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> StructuralPartialEq for ConstMontyForm<MOD, LIMBS>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<MOD, const LIMBS: usize> UnwindSafe for ConstMontyForm<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> 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> ConstantTimeSelect for T

source§

fn ct_select(a: &T, b: &T, choice: Choice) -> T

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

fn ct_assign(&mut self, other: &T, choice: Choice)

Conditionally assign other to self, according to choice.
source§

fn ct_swap(a: &mut T, b: &mut T, choice: Choice)

Conditionally swap self and other if choice == 1; otherwise, reassign both unto themselves.
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, Exponent, BasesAndExponents> MultiExponentiate<Exponent, BasesAndExponents> for T
where T: MultiExponentiateBoundedExp<Exponent, BasesAndExponents>, Exponent: Bounded, BasesAndExponents: AsRef<[(T, Exponent)]> + ?Sized,

source§

fn multi_exponentiate(bases_and_exponents: &BasesAndExponents) -> T

Calculates x1 ^ k1 * ... * xn ^ kn.
source§

impl<T, Exponent> Pow<Exponent> for T
where T: PowBoundedExp<Exponent>, Exponent: Bounded,

source§

fn pow(&self, exponent: &Exponent) -> T

Raises to the exponent power.
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.
source§

impl<T> Zero for T
where T: ConstZero,

source§

fn zero() -> T

The value 0.
source§

fn is_zero(&self) -> Choice

Determine if this value is equal to zero. Read more
source§

fn set_zero(&mut self)

Set self to its additive identity, i.e. Self::zero.
source§

fn zero_like(other: &Self) -> Self
where Self: Clone,

Return the value 0 with the same precision as other.
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,