Skip to content

Commit 92d231a

Browse files
committed
Address review comments from #277
1 parent 8b24d2e commit 92d231a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/uint/sqrt.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
2222
// See Hast, "Note on computation of integer square roots" for a proof of this bound.
2323
// https://github.com/RustCrypto/crypto-bigint/files/12600669/ct_sqrt.pdf
2424
let mut i = 0;
25-
while i < usize::BITS - Self::BITS.leading_zeros() {
25+
while i < Self::LOG2_BITS {
2626
guess = xn;
2727
xn = {
2828
let (q, _, is_some) = self.const_div_rem(&guess);
@@ -53,7 +53,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
5353
// Note, xn <= guess at this point.
5454

5555
// Repeat while guess decreases.
56-
while Uint::ct_gt(&guess, &xn).is_true_vartime() && xn.ct_is_nonzero().is_true_vartime() {
56+
while guess.cmp_vartime(&xn).is_gt() && !xn.cmp_vartime(&Self::ZERO).is_eq() {
5757
guess = xn;
5858
xn = {
5959
let q = self.wrapping_div_vartime(&guess);
@@ -62,7 +62,11 @@ impl<const LIMBS: usize> Uint<LIMBS> {
6262
};
6363
}
6464

65-
Self::ct_select(&Self::ZERO, &guess, self.ct_is_nonzero())
65+
if self.ct_is_nonzero().is_true_vartime() {
66+
guess
67+
} else {
68+
Self::ZERO
69+
}
6670
}
6771

6872
/// Wrapped sqrt is just normal √(`self`)

0 commit comments

Comments
 (0)