Struct Residue
pub struct Residue<MOD, const LIMBS: usize>where
MOD: ResidueParams<LIMBS>,{ /* private fields */ }Expand description
A residue mod MOD, represented using LIMBS limbs. The modulus of this residue is constant, so it cannot be set at runtime.
Internally, the value is stored in Montgomery form (multiplied by MOD::R) until it is retrieved.
Implementations§
§impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
pub const fn invert(&self) -> (Residue<MOD, LIMBS>, CtChoice)
pub const fn invert(&self) -> (Residue<MOD, LIMBS>, CtChoice)
Computes the residue 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).
§impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
pub const fn pow<const RHS_LIMBS: usize>(
&self,
exponent: &Uint<RHS_LIMBS>,
) -> Residue<MOD, LIMBS>
pub const fn pow<const RHS_LIMBS: usize>( &self, exponent: &Uint<RHS_LIMBS>, ) -> Residue<MOD, LIMBS>
Raises to the exponent power.
pub const fn pow_bounded_exp<const RHS_LIMBS: usize>(
&self,
exponent: &Uint<RHS_LIMBS>,
exponent_bits: usize,
) -> Residue<MOD, LIMBS>
pub const fn pow_bounded_exp<const RHS_LIMBS: usize>( &self, exponent: &Uint<RHS_LIMBS>, exponent_bits: usize, ) -> Residue<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.
§impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
pub const fn new(integer: &Uint<LIMBS>) -> Residue<MOD, LIMBS>
pub const fn new(integer: &Uint<LIMBS>) -> Residue<MOD, LIMBS>
Instantiates a new Residue that represents this integer mod MOD.
If the modulus represented by MOD is not odd, this function will panic; use new_checked if you want to be able to detect an invalid modulus.
pub fn new_checked(integer: &Uint<LIMBS>) -> CtOption<Residue<MOD, LIMBS>>
pub fn new_checked(integer: &Uint<LIMBS>) -> CtOption<Residue<MOD, LIMBS>>
Instantiates a new Residue that represents this integer mod MOD if the modulus is odd.
Returns a CtOption that is None if the provided modulus is not odd; this is a safer version of new, which can panic.
pub const fn retrieve(&self) -> Uint<LIMBS>
pub const fn retrieve(&self) -> Uint<LIMBS>
Retrieves the integer currently encoded in this Residue, guaranteed to be reduced.
pub const fn as_montgomery(&self) -> &Uint<LIMBS>
pub const fn as_montgomery(&self) -> &Uint<LIMBS>
Access the Residue value in Montgomery form.
pub fn as_montgomery_mut(&mut self) -> &mut Uint<LIMBS>
pub fn as_montgomery_mut(&mut self) -> &mut Uint<LIMBS>
Mutably access the Residue value in Montgomery form.
pub const fn from_montgomery(integer: Uint<LIMBS>) -> Residue<MOD, LIMBS>
pub const fn from_montgomery(integer: Uint<LIMBS>) -> Residue<MOD, LIMBS>
Create a Residue from a value in Montgomery form.
pub const fn to_montgomery(&self) -> Uint<LIMBS>
pub const fn to_montgomery(&self) -> Uint<LIMBS>
Extract the value from the Residue in Montgomery form.
Trait Implementations§
§impl<MOD, const LIMBS: usize> Add<&Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add<&Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Add<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Add<Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add<Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Add for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> AddAssign<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> AddAssign<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§fn add_assign(&mut self, rhs: &Residue<MOD, LIMBS>)
fn add_assign(&mut self, rhs: &Residue<MOD, LIMBS>)
+= operation. Read more§impl<MOD, const LIMBS: usize> AddAssign for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> AddAssign for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§fn add_assign(&mut self, rhs: Residue<MOD, LIMBS>)
fn add_assign(&mut self, rhs: Residue<MOD, LIMBS>)
+= operation. Read more§impl<MOD, const LIMBS: usize> Clone for Residue<MOD, LIMBS>where
MOD: Clone + ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Clone for Residue<MOD, LIMBS>where
MOD: Clone + ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> ConditionallySelectable for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS> + Copy,
impl<MOD, const LIMBS: usize> ConditionallySelectable for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS> + Copy,
§fn conditional_select(
a: &Residue<MOD, LIMBS>,
b: &Residue<MOD, LIMBS>,
choice: Choice,
) -> Residue<MOD, LIMBS>
fn conditional_select( a: &Residue<MOD, LIMBS>, b: &Residue<MOD, LIMBS>, choice: Choice, ) -> Residue<MOD, LIMBS>
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 more§impl<MOD, const LIMBS: usize> ConstantTimeEq for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> ConstantTimeEq for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Debug for Residue<MOD, LIMBS>where
MOD: Debug + ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Debug for Residue<MOD, LIMBS>where
MOD: Debug + ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Default for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Default for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<const LIMBS: usize, P> From<&Residue<P, LIMBS>> for DynResidue<LIMBS>where
P: ResidueParams<LIMBS>,
impl<const LIMBS: usize, P> From<&Residue<P, LIMBS>> for DynResidue<LIMBS>where
P: ResidueParams<LIMBS>,
§fn from(residue: &Residue<P, LIMBS>) -> DynResidue<LIMBS>
fn from(residue: &Residue<P, LIMBS>) -> DynResidue<LIMBS>
§impl<MOD, const LIMBS: usize> Invert for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Invert for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Mul<&Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Mul<&Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Mul<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Mul<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Mul<Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Mul<Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Mul for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Mul for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> MulAssign<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> MulAssign<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§fn mul_assign(&mut self, rhs: &Residue<MOD, LIMBS>)
fn mul_assign(&mut self, rhs: &Residue<MOD, LIMBS>)
*= operation. Read more§impl<MOD, const LIMBS: usize> MulAssign for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> MulAssign for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§fn mul_assign(&mut self, rhs: Residue<MOD, LIMBS>)
fn mul_assign(&mut self, rhs: Residue<MOD, LIMBS>)
*= operation. Read more§impl<const N: usize, MOD, const LIMBS: usize, const RHS_LIMBS: usize> MultiExponentiateBoundedExp<Uint<RHS_LIMBS>, [(Residue<MOD, LIMBS>, Uint<RHS_LIMBS>); N]> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<const N: usize, MOD, const LIMBS: usize, const RHS_LIMBS: usize> MultiExponentiateBoundedExp<Uint<RHS_LIMBS>, [(Residue<MOD, LIMBS>, Uint<RHS_LIMBS>); N]> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Neg for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Neg for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Neg for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Neg for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> PartialEq for Residue<MOD, LIMBS>where
MOD: PartialEq + ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> PartialEq for Residue<MOD, LIMBS>where
MOD: PartialEq + ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize, const RHS_LIMBS: usize> PowBoundedExp<Uint<RHS_LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize, const RHS_LIMBS: usize> PowBoundedExp<Uint<RHS_LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Random for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
Available on crate feature rand_core only.
impl<MOD, const LIMBS: usize> Random for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
rand_core only.§fn random(rng: &mut impl CryptoRngCore) -> Residue<MOD, LIMBS>
fn random(rng: &mut impl CryptoRngCore) -> Residue<MOD, LIMBS>
§impl<MOD, const LIMBS: usize> Retrieve for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Retrieve for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Square for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Square for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Sub<&Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub<&Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Sub<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Sub<Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub<Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> Sub for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Sub for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§impl<MOD, const LIMBS: usize> SubAssign<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> SubAssign<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§fn sub_assign(&mut self, rhs: &Residue<MOD, LIMBS>)
fn sub_assign(&mut self, rhs: &Residue<MOD, LIMBS>)
-= operation. Read more§impl<MOD, const LIMBS: usize> SubAssign for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> SubAssign for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
§fn sub_assign(&mut self, rhs: Residue<MOD, LIMBS>)
fn sub_assign(&mut self, rhs: Residue<MOD, LIMBS>)
-= operation. Read more§impl<MOD, const LIMBS: usize> Zero for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Zero for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Copy for Residue<MOD, LIMBS>where
MOD: Copy + ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> DefaultIsZeroes for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
zeroize only.impl<MOD, const LIMBS: usize> Eq for Residue<MOD, LIMBS>where
MOD: Eq + ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> StructuralPartialEq for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
Auto Trait Implementations§
impl<MOD, const LIMBS: usize> Freeze for Residue<MOD, LIMBS>
impl<MOD, const LIMBS: usize> RefUnwindSafe for Residue<MOD, LIMBS>where
MOD: RefUnwindSafe,
impl<MOD, const LIMBS: usize> Send for Residue<MOD, LIMBS>
impl<MOD, const LIMBS: usize> Sync for Residue<MOD, LIMBS>
impl<MOD, const LIMBS: usize> Unpin for Residue<MOD, LIMBS>where
MOD: Unpin,
impl<MOD, const LIMBS: usize> UnwindSafe for Residue<MOD, LIMBS>where
MOD: UnwindSafe,
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)
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§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,
§fn multi_exponentiate(bases_and_exponents: &BasesAndExponents) -> T
fn multi_exponentiate(bases_and_exponents: &BasesAndExponents) -> T
x1 ^ k1 * ... * xn ^ kn.