diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:19 +0000 |
commit | a0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch) | |
tree | fc451898ccaf445814e26b46664d78702178101d /vendor/crypto-bigint/src/uint/add_mod.rs | |
parent | Adding debian version 1.71.1+dfsg1-2. (diff) | |
download | rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.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.rs | 19 |
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)) } } |