Skip to content

Commit 5708db0

Browse files
committed
bigint::monty: simplify redc masks
1 parent 5a0de14 commit 5708db0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

bigint/src/monty.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,16 @@ fn monty_redc(a: BigUint, mr: &MontyReducer) -> BigUint {
6767

6868
// β is the size of a word, in this case 32 bits. So "a mod β" is
6969
// equivalent to masking a to 32 bits.
70-
let beta_mask = u32::max_value() as u64;
7170
// mu <- -N^(-1) mod β
72-
let mu = (beta_mask-mr.n0inv as u64)+1;
71+
let mu = 0u32.wrapping_sub(mr.n0inv);
7372

7473
// 1: for i = 0 to (n-1)
7574
for i in 0..n_size {
7675
// 2: q_i <- mu*c_i mod β
77-
let q_i = ((c[i] as u64) * mu) & beta_mask;
76+
let q_i = c[i].wrapping_mul(mu);
7877

7978
// 3: C <- C + q_i * N * β^i
80-
super::algorithms::mac_digit(&mut c[i..], n, q_i as u32);
79+
super::algorithms::mac_digit(&mut c[i..], n, q_i);
8180
}
8281

8382
// 4: R <- C * β^(-n)

0 commit comments

Comments
 (0)