pub struct MontParams {
pub n: BigInt,
pub n_limbs: usize,
pub n_inv_neg: u64,
pub r_mod_n: BigInt,
pub r2_mod_n: BigInt,
}Expand description
Parameters for Montgomery modular arithmetic.
Fields§
§n: BigIntThe modulus n.
n_limbs: usizeNumber of limbs.
n_inv_neg: u64-n^{-1} mod 2^64.
r_mod_n: BigIntR = 2^{64*n_limbs} (not stored, implicit). R mod n.
r2_mod_n: BigIntR^2 mod n.
Implementations§
Source§impl MontParams
impl MontParams
Sourcepub fn mont_mul(&self, a: &BigInt, b: &BigInt) -> BigInt
pub fn mont_mul(&self, a: &BigInt, b: &BigInt) -> BigInt
Montgomery multiplication: (a * b * R^{-1}) mod n. Uses the CIOS (Coarsely Integrated Operand Scanning) method.
Sourcepub fn mod_exp(&self, base: &BigInt, exp: &BigInt) -> BigInt
pub fn mod_exp(&self, base: &BigInt, exp: &BigInt) -> BigInt
Modular exponentiation via a Montgomery ladder. Computes
base^exp mod n.
Not constant-time yet. The ladder is square-always in
structure, but it branches on the secret exponent bit
(exp.bit(i)) rather than using a constant-time conditional
swap, and mont_mul’s conditional final subtract is not
black_box-shielded (Walter 2002). Per the module header, do
not use on secret exponents until T1-E lands the CT rework.
[CESTI]
Auto Trait Implementations§
impl Freeze for MontParams
impl RefUnwindSafe for MontParams
impl Send for MontParams
impl Sync for MontParams
impl Unpin for MontParams
impl UnsafeUnpin for MontParams
impl UnwindSafe for MontParams
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
Mutably borrows from an owned value. Read more