Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire authored and cuviper committed Aug 7, 2019
1 parent 5be8899 commit f4af5ec
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 13 deletions.
5 changes: 0 additions & 5 deletions src/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ fn sbb(a: BigDigit, b: BigDigit, acc: &mut SignedDoubleBigDigit) -> BigDigit {

#[inline]
pub fn mac_with_carry(a: BigDigit, b: BigDigit, c: BigDigit, acc: &mut DoubleBigDigit) -> BigDigit {
// println!("mac_with_carry: {} {} {} {}", a, b, c, acc);
*acc += DoubleBigDigit::from(a);
*acc += DoubleBigDigit::from(b) * DoubleBigDigit::from(c);
// println!("acc {}", acc);
let lo = *acc as BigDigit;
// println!("lo {}", lo);
*acc >>= big_digit::BITS;
// println!("acc shifted {}", acc);
lo
}

Expand Down Expand Up @@ -211,7 +207,6 @@ pub fn sub_sign(a: &[BigDigit], b: &[BigDigit]) -> (Sign, BigUint) {
/// Three argument multiply accumulate:
/// acc += b * c
pub fn mac_digit(acc: &mut [BigDigit], b: &[BigDigit], c: BigDigit) {
// println!("mac_digit: {:?} += {:?} * {}", acc, b, c);
if c == 0 {
return;
}
Expand Down
8 changes: 1 addition & 7 deletions src/monty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ impl MontyReducer {
/// x and y are required to satisfy 0 <= z < 2**(n*_W) and then the result
/// z is guaranteed to satisfy 0 <= z < 2**(n*_W), but it may not be < m.
fn montgomery(x: &BigUint, y: &BigUint, m: &BigUint, k: BigDigit, n: usize) -> BigUint {
// println!("montgomery: {:?} {:?} {:?} {} {}", x, y, m, k, n);
// This code assumes x, y, m are all the same length, n.
// (required by addMulVVW and the for loop).
// It also assumes that x, y are already reduced mod m,
Expand Down Expand Up @@ -135,11 +134,8 @@ pub fn monty_modpow(x: &BigUint, y: &BigUint, m: &BigUint) -> BigUint {
let mr = MontyReducer::new(m);
let num_words = m.data.len();

// println!("modpow {:?} {:?} {:?}", x, y, m);
// println!("numWords {}", num_words);
let mut x = x.clone();

// println!("inverse: {:?}", mr.n0inv);
// We want the lengths of x and m to be equal.
// It is OK if x >= m as long as len(x) == len(m).
if x.data.len() > num_words {
Expand All @@ -156,7 +152,6 @@ pub fn monty_modpow(x: &BigUint, y: &BigUint, m: &BigUint) -> BigUint {
if rr.data.len() < num_words {
rr.data.resize(num_words, 0);
}
// println!("rr: {:?}", rr);
// one = 1, with equal length to that of m
let mut one = BigUint::one();
one.data.resize(num_words, 0);
Expand All @@ -170,14 +165,13 @@ pub fn monty_modpow(x: &BigUint, y: &BigUint, m: &BigUint) -> BigUint {
let r = montgomery(&powers[i - 1], &powers[1], m, mr.n0inv, num_words);
powers.push(r);
}
// println!("powers: {:?} {}", powers, 1 << n);

// initialize z = 1 (Montgomery 1)
let mut z = powers[0].clone();
z.data.resize(num_words, 0);
let mut zz = BigUint::zero();
zz.data.resize(num_words, 0);

// println!("powers: {:?}", powers);
// same windowed exponent, but with Montgomery multiplications
for i in (0..y.data.len()).rev() {
let mut yi = y.data[i];
Expand Down
2 changes: 1 addition & 1 deletion tests/modpow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod biguint {
let e: BigUint = e.into();
let m: BigUint = m.into();
let r: BigUint = r.into();
println!("checking: {} {} {} {}", b, e, m, r);

assert_eq!(b.modpow(&e, &m), r);

let even_m = &m << 1;
Expand Down

0 comments on commit f4af5ec

Please sign in to comment.