From d2d0e0f05c5759c634c2b4fead3c2d0159f5169c Mon Sep 17 00:00:00 2001 From: "Ganyu (Bruce) Xu" Date: Wed, 20 Dec 2023 11:05:05 -0500 Subject: [PATCH] Migrated from Residue to Monty --- src/modular/boxed_monty_form.rs | 15 ++++++--------- src/modular/monty_form.rs | 6 +++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/modular/boxed_monty_form.rs b/src/modular/boxed_monty_form.rs index 54164a85..c64c6b7e 100644 --- a/src/modular/boxed_monty_form.rs +++ b/src/modular/boxed_monty_form.rs @@ -251,11 +251,8 @@ impl BoxedMontyForm { /// (since the modulus `p` in Montgomery form is always odd, this divides entirely). pub fn div_by_2(&self) -> Self { Self { - montgomery_form: div_by_2::boxed::div_by_2( - &self.montgomery_form, - &self.residue_params.modulus, - ), - residue_params: self.residue_params.clone(), // TODO: avoid clone? + montgomery_form: div_by_2::boxed::div_by_2(&self.montgomery_form, &self.params.modulus), + params: self.params.clone(), // TODO: avoid clone? } } } @@ -279,7 +276,7 @@ fn convert_to_montgomery(integer: &mut BoxedUint, params: &BoxedMontyParams) { #[cfg(test)] mod tests { - use super::{BoxedMontyParams, BoxedUint}; + use super::{BoxedMontyForm, BoxedMontyParams, BoxedUint}; #[test] fn new_params_with_invalid_modulus() { @@ -299,9 +296,9 @@ mod tests { #[test] fn div_by_2() { - let params = BoxedResidueParams::new(BoxedUint::from(9u8)).unwrap(); - let zero = BoxedResidue::zero(params.clone()); - let one = BoxedResidue::one(params.clone()); + let params = BoxedMontyParams::new(BoxedUint::from(9u8)).unwrap(); + let zero = BoxedMontyForm::zero(params.clone()); + let one = BoxedMontyForm::one(params.clone()); let two = one.add(&one); assert_eq!(zero.div_by_2(), zero); diff --git a/src/modular/monty_form.rs b/src/modular/monty_form.rs index 371ea3e5..f24bd065 100644 --- a/src/modular/monty_form.rs +++ b/src/modular/monty_form.rs @@ -269,9 +269,9 @@ mod test { #[test] fn div_by_2() { - let params = DynResidueParams::new(&Uint::<1>::from(9u8)).unwrap(); - let zero = DynResidue::zero(params.clone()); - let one = DynResidue::one(params.clone()); + let params = MontyParams::new(&Uint::<1>::from(9u8)).unwrap(); + let zero = MontyForm::zero(params.clone()); + let one = MontyForm::one(params.clone()); let two = one.add(&one); assert_eq!(zero.div_by_2(), zero);