summaryrefslogtreecommitdiffstats
path: root/vendor/crypto-bigint/src/uint/add_mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/crypto-bigint/src/uint/add_mod.rs')
-rw-r--r--vendor/crypto-bigint/src/uint/add_mod.rs19
1 files changed, 4 insertions, 15 deletions
diff --git a/vendor/crypto-bigint/src/uint/add_mod.rs b/vendor/crypto-bigint/src/uint/add_mod.rs
index bfdda6ff5..70674f5e8 100644
--- a/vendor/crypto-bigint/src/uint/add_mod.rs
+++ b/vendor/crypto-bigint/src/uint/add_mod.rs
@@ -16,19 +16,9 @@ impl<const LIMBS: usize> Uint<LIMBS> {
// If underflow occurred on the final limb, borrow = 0xfff...fff, otherwise
// borrow = 0x000...000. Thus, we use it as a mask to conditionally add the
// modulus.
- let mut i = 0;
- let mut res = Self::ZERO;
- let mut carry = Limb::ZERO;
-
- while i < LIMBS {
- let rhs = p.limbs[i].bitand(borrow);
- let (limb, c) = w.limbs[i].adc(rhs, carry);
- res.limbs[i] = limb;
- carry = c;
- i += 1;
- }
-
- res
+ let mask = Uint::from_words([borrow.0; LIMBS]);
+
+ w.wrapping_add(&p.bitand(&mask))
}
/// Computes `self + rhs mod p` in constant time for the special modulus
@@ -43,8 +33,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
// for the overflow. Otherwise, we need to subtract `c` again, which
// in that case cannot underflow.
let l = carry.0.wrapping_sub(1) & c.0;
- let (out, _) = out.sbb(&Uint::from_word(l), Limb::ZERO);
- out
+ out.wrapping_sub(&Uint::from_word(l))
}
}