Skip to content

Commit

Permalink
Migrated from Residue to Monty
Browse files Browse the repository at this point in the history
  • Loading branch information
xuganyu96 committed Dec 20, 2023
1 parent 49d72c5 commit d2d0e0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
15 changes: 6 additions & 9 deletions src/modular/boxed_monty_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
}
}
Expand All @@ -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() {
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/modular/monty_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d2d0e0f

Please sign in to comment.