Skip to content

Commit

Permalink
check derivation of mod_leading_zeros
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Dec 10, 2024
1 parent fc1085e commit b428f80
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/modular/boxed_monty_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,14 @@ fn convert_to_montgomery(integer: &mut BoxedUint, params: &BoxedMontyParams) {

#[cfg(test)]
mod tests {
use super::{BoxedMontyForm, BoxedMontyParams, BoxedUint, Odd};
use super::{BoxedMontyForm, BoxedMontyParams, BoxedUint, Limb, Odd};

#[test]
fn new_params_with_valid_modulus() {
let modulus = Odd::new(BoxedUint::from(3u8)).unwrap();
BoxedMontyParams::new(modulus);
let params = BoxedMontyParams::new(modulus);

assert_eq!(params.mod_leading_zeros, Limb::BITS - 2);
}

#[test]
Expand Down
13 changes: 13 additions & 0 deletions src/modular/const_monty_form/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,16 @@ macro_rules! const_monty_form {
$crate::modular::ConstMontyForm::<$modulus, { $modulus::LIMBS }>::new(&$variable)
};
}

#[cfg(test)]
mod tests {
use crate::modular::ConstMontyParams;
use crate::{Limb, U64};

#[test]
fn new_params_with_valid_modulus() {
impl_modulus!(Mod, U64, "0000000000000003");

assert_eq!(Mod::MOD_LEADING_ZEROS, core::cmp::min(Limb::BITS - 1, 62));
}
}
13 changes: 13 additions & 0 deletions src/modular/monty_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,16 @@ impl<const LIMBS: usize> zeroize::Zeroize for MontyForm<LIMBS> {
self.params.zeroize();
}
}

#[cfg(test)]
mod tests {
use super::{Limb, MontyParams, Odd, Uint};

#[test]
fn new_params_with_valid_modulus() {
let modulus = Odd::new(Uint::from(3u8)).unwrap();
let params = MontyParams::<1>::new(modulus);

assert_eq!(params.mod_leading_zeros, Limb::BITS - 2);
}
}

0 comments on commit b428f80

Please sign in to comment.