Struct crypto_bigint::modular::MontyForm
source · 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 = BernsteinYangInverter<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 = BernsteinYangInverter<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).
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§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 = BernsteinYangInverter<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 = BernsteinYangInverter<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>
§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§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> PartialEq for MontyForm<LIMBS>
impl<const LIMBS: usize> PartialEq 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.NOTE: this does not zeroize the parameters, in order to maintain some form of type consistency
impl<const LIMBS: usize> Copy for MontyForm<LIMBS>
impl<const LIMBS: usize> Eq for MontyForm<LIMBS>
impl<const LIMBS: usize> StructuralEq for MontyForm<LIMBS>
impl<const LIMBS: usize> StructuralPartialEq for MontyForm<LIMBS>
Auto Trait Implementations§
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> 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
.