Skip to content

Commit 5a0de14

Browse files
committed
bigint::monty: use mac_digit
1 parent 4d35815 commit 5a0de14

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

bigint/src/algorithms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub fn sub_sign(a: &[BigDigit], b: &[BigDigit]) -> (Sign, BigUint) {
220220

221221
/// Three argument multiply accumulate:
222222
/// acc += b * c
223-
fn mac_digit(acc: &mut [BigDigit], b: &[BigDigit], c: BigDigit) {
223+
pub fn mac_digit(acc: &mut [BigDigit], b: &[BigDigit], c: BigDigit) {
224224
if c == 0 {
225225
return;
226226
}

bigint/src/monty.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,11 @@ fn monty_redc(a: BigUint, mr: &MontyReducer) -> BigUint {
7373

7474
// 1: for i = 0 to (n-1)
7575
for i in 0..n_size {
76-
// Carry storage
77-
let mut carry = 0;
78-
7976
// 2: q_i <- mu*c_i mod β
8077
let q_i = ((c[i] as u64) * mu) & beta_mask;
8178

8279
// 3: C <- C + q_i * N * β^i
83-
// When iterating over each word, this becomes:
84-
for j in 0..n_size {
85-
// c_(i+j) <- c_(i+j) + q_i * n_j
86-
let x = (c[i+j] as u64) + q_i * (n[j] as u64) + carry;
87-
c[i+j] = (x & beta_mask) as u32;
88-
carry = x >> 32;
89-
}
90-
91-
// Apply the remaining carry to the rest of the work space
92-
for j in n_size..2*n_size-i+2 {
93-
let x = (c[i+j] as u64) + carry;
94-
c[i+j] = (x & beta_mask) as u32;
95-
carry = x >> 32;
96-
}
80+
super::algorithms::mac_digit(&mut c[i..], n, q_i as u32);
9781
}
9882

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

0 commit comments

Comments
 (0)