pub struct MontyForm<const LIMBS: usize> { /* private fields */ }
Expand description
An integer in Montgomery form represented using LIMBS
limbs.
The odd modulus is set at runtime.
Implementations§
Source§impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> MontyForm<SAT_LIMBS>where
Odd<Uint<SAT_LIMBS>>: PrecomputeInverter<Inverter = SafeGcdInverter<SAT_LIMBS, UNSAT_LIMBS>, Output = Uint<SAT_LIMBS>>,
impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> MontyForm<SAT_LIMBS>where
Odd<Uint<SAT_LIMBS>>: PrecomputeInverter<Inverter = SafeGcdInverter<SAT_LIMBS, UNSAT_LIMBS>, Output = Uint<SAT_LIMBS>>,
Sourcepub const fn inv(&self) -> ConstCtOption<Self>
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).
Sourcepub const fn inv_vartime(&self) -> ConstCtOption<Self>
pub const fn inv_vartime(&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).
This version is variable-time with respect to the value of self
, but constant-time with
respect to self
’s params
.
Source§impl<const LIMBS: usize> MontyForm<LIMBS>
impl<const LIMBS: usize> MontyForm<LIMBS>
Sourcepub const fn lincomb_vartime(products: &[(&Self, &Self)]) -> Self
pub const fn lincomb_vartime(products: &[(&Self, &Self)]) -> Self
Calculate the sum of products of pairs (a, b)
in products
.
This method is variable time only with the value of the modulus. For a modulus with leading zeros, this method is more efficient than a naive sum of products.
This method will panic if products
is empty. All terms must be associated
with equivalent MontyParams
.
Source§impl<const LIMBS: usize> MontyForm<LIMBS>
impl<const LIMBS: usize> MontyForm<LIMBS>
Sourcepub const fn pow<const RHS_LIMBS: usize>(
&self,
exponent: &Uint<RHS_LIMBS>,
) -> MontyForm<LIMBS>
pub const fn pow<const RHS_LIMBS: usize>( &self, exponent: &Uint<RHS_LIMBS>, ) -> MontyForm<LIMBS>
Raises to the exponent
power.
Sourcepub const fn pow_bounded_exp<const RHS_LIMBS: usize>(
&self,
exponent: &Uint<RHS_LIMBS>,
exponent_bits: u32,
) -> Self
pub const fn pow_bounded_exp<const RHS_LIMBS: usize>( &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.
NOTE: exponent_bits
may be leaked in the time pattern.
Source§impl<const LIMBS: usize> MontyForm<LIMBS>
impl<const LIMBS: usize> MontyForm<LIMBS>
Sourcepub const fn new(integer: &Uint<LIMBS>, params: MontyParams<LIMBS>) -> Self
pub const fn new(integer: &Uint<LIMBS>, params: MontyParams<LIMBS>) -> Self
Instantiates a new MontyForm
that represents this integer
mod MOD
.
Sourcepub const fn retrieve(&self) -> Uint<LIMBS>
pub const fn retrieve(&self) -> Uint<LIMBS>
Retrieves the integer currently encoded in this MontyForm
, guaranteed to be reduced.
Sourcepub const fn zero(params: MontyParams<LIMBS>) -> Self
pub const fn zero(params: MontyParams<LIMBS>) -> Self
Instantiates a new MontyForm
that represents zero.
Sourcepub const fn one(params: MontyParams<LIMBS>) -> Self
pub const fn one(params: MontyParams<LIMBS>) -> Self
Instantiates a new MontyForm
that represents 1.
Sourcepub const fn params(&self) -> &MontyParams<LIMBS>
pub const fn params(&self) -> &MontyParams<LIMBS>
Returns the parameter struct used to initialize this object.
Sourcepub const fn as_montgomery(&self) -> &Uint<LIMBS>
pub const fn as_montgomery(&self) -> &Uint<LIMBS>
Access the MontyForm
value in Montgomery form.
Sourcepub fn as_montgomery_mut(&mut self) -> &mut Uint<LIMBS>
pub fn as_montgomery_mut(&mut self) -> &mut Uint<LIMBS>
Mutably access the MontyForm
value in Montgomery form.
Sourcepub const fn from_montgomery(
integer: Uint<LIMBS>,
params: MontyParams<LIMBS>,
) -> Self
pub const fn from_montgomery( integer: Uint<LIMBS>, params: MontyParams<LIMBS>, ) -> Self
Create a MontyForm
from a value in Montgomery form.
Sourcepub const fn to_montgomery(&self) -> Uint<LIMBS>
pub const fn to_montgomery(&self) -> Uint<LIMBS>
Extract the value from the MontyForm
in Montgomery form.
Trait Implementations§
Source§impl<const LIMBS: usize> AddAssign<&MontyForm<LIMBS>> for MontyForm<LIMBS>
impl<const LIMBS: usize> AddAssign<&MontyForm<LIMBS>> for MontyForm<LIMBS>
Source§fn add_assign(&mut self, rhs: &MontyForm<LIMBS>)
fn add_assign(&mut self, rhs: &MontyForm<LIMBS>)
+=
operation. Read moreSource§impl<const LIMBS: usize> AddAssign for MontyForm<LIMBS>
impl<const LIMBS: usize> AddAssign for MontyForm<LIMBS>
Source§fn add_assign(&mut self, rhs: MontyForm<LIMBS>)
fn add_assign(&mut self, rhs: MontyForm<LIMBS>)
+=
operation. Read moreSource§impl<const LIMBS: usize> ConditionallySelectable for MontyForm<LIMBS>
impl<const LIMBS: usize> ConditionallySelectable for MontyForm<LIMBS>
Source§fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
self
and other
if choice == 1
; otherwise,
reassign both unto themselves. Read moreSource§impl<const LIMBS: usize> ConstantTimeEq for MontyForm<LIMBS>
impl<const LIMBS: usize> ConstantTimeEq for MontyForm<LIMBS>
Source§impl<const LIMBS: usize, P: ConstMontyParams<LIMBS>> From<&ConstMontyForm<P, LIMBS>> for MontyForm<LIMBS>
impl<const LIMBS: usize, P: ConstMontyParams<LIMBS>> From<&ConstMontyForm<P, LIMBS>> for MontyForm<LIMBS>
Source§fn from(const_monty_form: &ConstMontyForm<P, LIMBS>) -> Self
fn from(const_monty_form: &ConstMontyForm<P, LIMBS>) -> Self
Source§impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> Invert for MontyForm<SAT_LIMBS>where
Odd<Uint<SAT_LIMBS>>: PrecomputeInverter<Inverter = SafeGcdInverter<SAT_LIMBS, UNSAT_LIMBS>, Output = Uint<SAT_LIMBS>>,
impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> Invert for MontyForm<SAT_LIMBS>where
Odd<Uint<SAT_LIMBS>>: PrecomputeInverter<Inverter = SafeGcdInverter<SAT_LIMBS, UNSAT_LIMBS>, Output = Uint<SAT_LIMBS>>,
Source§impl<const LIMBS: usize> Monty for MontyForm<LIMBS>
impl<const LIMBS: usize> Monty for MontyForm<LIMBS>
Source§type Params = MontyParams<LIMBS>
type Params = MontyParams<LIMBS>
Source§fn new_params_vartime(modulus: Odd<Self::Integer>) -> Self::Params
fn new_params_vartime(modulus: Odd<Self::Integer>) -> Self::Params
modulus
,
variable time in modulus
.Source§fn new(value: Self::Integer, params: Self::Params) -> Self
fn new(value: Self::Integer, params: Self::Params) -> Self
Source§fn params(&self) -> &Self::Params
fn params(&self) -> &Self::Params
Source§fn as_montgomery(&self) -> &Self::Integer
fn as_montgomery(&self) -> &Self::Integer
Source§fn lincomb_vartime(products: &[(&Self, &Self)]) -> Self
fn lincomb_vartime(products: &[(&Self, &Self)]) -> Self
Source§impl<const LIMBS: usize> MulAssign<&MontyForm<LIMBS>> for MontyForm<LIMBS>
impl<const LIMBS: usize> MulAssign<&MontyForm<LIMBS>> for MontyForm<LIMBS>
Source§fn mul_assign(&mut self, rhs: &MontyForm<LIMBS>)
fn mul_assign(&mut self, rhs: &MontyForm<LIMBS>)
*=
operation. Read moreSource§impl<const LIMBS: usize> MulAssign for MontyForm<LIMBS>
impl<const LIMBS: usize> MulAssign for MontyForm<LIMBS>
Source§fn mul_assign(&mut self, rhs: MontyForm<LIMBS>)
fn mul_assign(&mut self, rhs: MontyForm<LIMBS>)
*=
operation. Read moreSource§impl<const LIMBS: usize, const RHS_LIMBS: usize> MultiExponentiateBoundedExp<Uint<RHS_LIMBS>, [(MontyForm<LIMBS>, Uint<RHS_LIMBS>)]> for MontyForm<LIMBS>
Available on crate feature alloc
only.
impl<const LIMBS: usize, const RHS_LIMBS: usize> MultiExponentiateBoundedExp<Uint<RHS_LIMBS>, [(MontyForm<LIMBS>, Uint<RHS_LIMBS>)]> for MontyForm<LIMBS>
alloc
only.Source§fn multi_exponentiate_bounded_exp(
bases_and_exponents: &[(Self, Uint<RHS_LIMBS>)],
exponent_bits: u32,
) -> Self
fn multi_exponentiate_bounded_exp( bases_and_exponents: &[(Self, Uint<RHS_LIMBS>)], exponent_bits: u32, ) -> Self
x1 ^ k1 * ... * xn ^ kn
.Source§impl<const N: usize, const LIMBS: usize, const RHS_LIMBS: usize> MultiExponentiateBoundedExp<Uint<RHS_LIMBS>, [(MontyForm<LIMBS>, Uint<RHS_LIMBS>); N]> for MontyForm<LIMBS>
impl<const N: usize, const LIMBS: usize, const RHS_LIMBS: usize> MultiExponentiateBoundedExp<Uint<RHS_LIMBS>, [(MontyForm<LIMBS>, Uint<RHS_LIMBS>); N]> for MontyForm<LIMBS>
Source§impl<const LIMBS: usize, const RHS_LIMBS: usize> PowBoundedExp<Uint<RHS_LIMBS>> for MontyForm<LIMBS>
impl<const LIMBS: usize, const RHS_LIMBS: usize> PowBoundedExp<Uint<RHS_LIMBS>> for MontyForm<LIMBS>
Source§impl<const LIMBS: usize> SquareAssign for MontyForm<LIMBS>
impl<const LIMBS: usize> SquareAssign for MontyForm<LIMBS>
Source§fn square_assign(&mut self)
fn square_assign(&mut self)
self * self
, but may be more efficient.
Writes the result in self
.Source§impl<const LIMBS: usize> SubAssign<&MontyForm<LIMBS>> for MontyForm<LIMBS>
impl<const LIMBS: usize> SubAssign<&MontyForm<LIMBS>> for MontyForm<LIMBS>
Source§fn sub_assign(&mut self, rhs: &MontyForm<LIMBS>)
fn sub_assign(&mut self, rhs: &MontyForm<LIMBS>)
-=
operation. Read moreSource§impl<const LIMBS: usize> SubAssign for MontyForm<LIMBS>
impl<const LIMBS: usize> SubAssign for MontyForm<LIMBS>
Source§fn sub_assign(&mut self, rhs: MontyForm<LIMBS>)
fn sub_assign(&mut self, rhs: MontyForm<LIMBS>)
-=
operation. Read moreSource§impl<const LIMBS: usize> Zeroize for MontyForm<LIMBS>
Available on crate feature zeroize
only.
impl<const LIMBS: usize> Zeroize for MontyForm<LIMBS>
zeroize
only.impl<const LIMBS: usize> Copy for MontyForm<LIMBS>
impl<const LIMBS: usize> Eq for MontyForm<LIMBS>
impl<const LIMBS: usize> StructuralPartialEq for MontyForm<LIMBS>
Auto Trait Implementations§
impl<const LIMBS: usize> Freeze for MontyForm<LIMBS>
impl<const LIMBS: usize> RefUnwindSafe for MontyForm<LIMBS>
impl<const LIMBS: usize> Send for MontyForm<LIMBS>
impl<const LIMBS: usize> Sync for MontyForm<LIMBS>
impl<const LIMBS: usize> Unpin for MontyForm<LIMBS>
impl<const LIMBS: usize> UnwindSafe for MontyForm<LIMBS>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ConditionallyNegatable for T
impl<T> ConditionallyNegatable for T
Source§fn conditional_negate(&mut self, choice: Choice)
fn conditional_negate(&mut self, choice: Choice)
Source§impl<T> ConstantTimeSelect for Twhere
T: ConditionallySelectable,
impl<T> ConstantTimeSelect for Twhere
T: ConditionallySelectable,
Source§impl<T, Exponent, BasesAndExponents> MultiExponentiate<Exponent, BasesAndExponents> for Twhere
T: MultiExponentiateBoundedExp<Exponent, BasesAndExponents>,
Exponent: Bounded,
BasesAndExponents: AsRef<[(T, Exponent)]> + ?Sized,
impl<T, Exponent, BasesAndExponents> MultiExponentiate<Exponent, BasesAndExponents> for Twhere
T: MultiExponentiateBoundedExp<Exponent, BasesAndExponents>,
Exponent: Bounded,
BasesAndExponents: AsRef<[(T, Exponent)]> + ?Sized,
Source§fn multi_exponentiate(bases_and_exponents: &BasesAndExponents) -> T
fn multi_exponentiate(bases_and_exponents: &BasesAndExponents) -> T
x1 ^ k1 * ... * xn ^ kn
.