summaryrefslogtreecommitdiffstats
path: root/vendor/crypto-bigint/src/uint/sqrt.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/crypto-bigint/src/uint/sqrt.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/crypto-bigint/src/uint/sqrt.rs')
-rw-r--r--vendor/crypto-bigint/src/uint/sqrt.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/vendor/crypto-bigint/src/uint/sqrt.rs b/vendor/crypto-bigint/src/uint/sqrt.rs
index 4a9f26a61..56815e2de 100644
--- a/vendor/crypto-bigint/src/uint/sqrt.rs
+++ b/vendor/crypto-bigint/src/uint/sqrt.rs
@@ -1,10 +1,10 @@
-//! [`UInt`] square root operations.
+//! [`Uint`] square root operations.
-use super::UInt;
+use super::Uint;
use crate::{Limb, Word};
use subtle::{ConstantTimeEq, CtOption};
-impl<const LIMBS: usize> UInt<LIMBS> {
+impl<const LIMBS: usize> Uint<LIMBS> {
/// Computes √(`self`)
/// Uses Brent & Zimmermann, Modern Computer Arithmetic, v0.5.9, Algorithm 1.13
///
@@ -21,13 +21,12 @@ impl<const LIMBS: usize> UInt<LIMBS> {
// If guess increased, the initial guess was low.
// Repeat until reverse course.
- while guess.ct_cmp(&xn) == -1 {
+ while Uint::ct_lt(&guess, &xn).is_true_vartime() {
// Sometimes an increase is too far, especially with large
// powers, and then takes a long time to walk back. The upper
// bound is based on bit size, so saturate on that.
- let res = Limb::ct_cmp(Limb(xn.bits_vartime() as Word), Limb(max_bits as Word)) - 1;
- let le = Limb::is_nonzero(Limb(res as Word));
- guess = Self::ct_select(cap, xn, le);
+ let le = Limb::ct_le(Limb(xn.bits_vartime() as Word), Limb(max_bits as Word));
+ guess = Self::ct_select(&cap, &xn, le);
xn = {
let q = self.wrapping_div(&guess);
let t = guess.wrapping_add(&q);
@@ -36,7 +35,7 @@ impl<const LIMBS: usize> UInt<LIMBS> {
}
// Repeat while guess decreases.
- while guess.ct_cmp(&xn) == 1 && xn.ct_is_nonzero() == Word::MAX {
+ while Uint::ct_gt(&guess, &xn).is_true_vartime() && xn.ct_is_nonzero().is_true_vartime() {
guess = xn;
xn = {
let q = self.wrapping_div(&guess);
@@ -45,7 +44,7 @@ impl<const LIMBS: usize> UInt<LIMBS> {
};
}
- Self::ct_select(Self::ZERO, guess, self.ct_is_nonzero())
+ Self::ct_select(&Self::ZERO, &guess, self.ct_is_nonzero())
}
/// Wrapped sqrt is just normal √(`self`)
@@ -60,7 +59,7 @@ impl<const LIMBS: usize> UInt<LIMBS> {
pub fn checked_sqrt(&self) -> CtOption<Self> {
let r = self.sqrt();
let s = r.wrapping_mul(&r);
- CtOption::new(r, self.ct_eq(&s))
+ CtOption::new(r, ConstantTimeEq::ct_eq(self, &s))
}
}