Skip to content

Commit 5a735a5

Browse files
check derivation of mod_leading_zeros
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
1 parent fc1085e commit 5a735a5

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/modular/boxed_monty_form.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,14 @@ fn convert_to_montgomery(integer: &mut BoxedUint, params: &BoxedMontyParams) {
327327

328328
#[cfg(test)]
329329
mod tests {
330-
use super::{BoxedMontyForm, BoxedMontyParams, BoxedUint, Odd};
330+
use super::{BoxedMontyForm, BoxedMontyParams, BoxedUint, Limb, Odd};
331331

332332
#[test]
333333
fn new_params_with_valid_modulus() {
334334
let modulus = Odd::new(BoxedUint::from(3u8)).unwrap();
335-
BoxedMontyParams::new(modulus);
335+
let params = BoxedMontyParams::new(modulus);
336+
337+
assert_eq!(params.mod_leading_zeros, Limb::BITS - 2);
336338
}
337339

338340
#[test]

src/modular/const_monty_form/macros.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,16 @@ macro_rules! const_monty_form {
8484
$crate::modular::ConstMontyForm::<$modulus, { $modulus::LIMBS }>::new(&$variable)
8585
};
8686
}
87+
88+
#[cfg(test)]
89+
mod tests {
90+
use crate::modular::ConstMontyParams;
91+
use crate::U64;
92+
93+
#[test]
94+
fn new_params_with_valid_modulus() {
95+
impl_modulus!(Mod, U64, "0000000000000003");
96+
97+
assert_eq!(Mod::MOD_LEADING_ZEROS, 62);
98+
}
99+
}

src/modular/monty_form.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,16 @@ impl<const LIMBS: usize> zeroize::Zeroize for MontyForm<LIMBS> {
337337
self.params.zeroize();
338338
}
339339
}
340+
341+
#[cfg(test)]
342+
mod tests {
343+
use super::{Limb, MontyParams, Odd, Uint};
344+
345+
#[test]
346+
fn new_params_with_valid_modulus() {
347+
let modulus = Odd::new(Uint::from(3u8)).unwrap();
348+
let params = MontyParams::<1>::new(modulus);
349+
350+
assert_eq!(params.mod_leading_zeros, Limb::BITS - 2);
351+
}
352+
}

0 commit comments

Comments
 (0)