summaryrefslogtreecommitdiffstats
path: root/vendor/crypto-bigint/src/uint/add_mod.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/crypto-bigint/src/uint/add_mod.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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))
}
}