Skip to content

Commit 2eba0e7

Browse files
committed
Use crate::ConstantTimeSelect as a substitute for subtle::ConditionallySelectable in BoxedUint
1 parent 89816e7 commit 2eba0e7

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/modular/div_by_2.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,18 @@ pub(crate) fn div_by_2<const LIMBS: usize>(a: &Uint<LIMBS>, modulus: &Uint<LIMBS
3131

3232
#[cfg(feature = "alloc")]
3333
pub(crate) mod boxed {
34-
use crate::BoxedUint;
34+
use crate::{BoxedUint, ConstantTimeSelect};
3535

3636
pub(crate) fn div_by_2(a: &BoxedUint, modulus: &BoxedUint) -> BoxedUint {
3737
debug_assert_eq!(a.bits_precision(), modulus.bits_precision());
3838

39-
let (mut ret, is_odd) = a.shr1_with_carry();
39+
let (half, is_odd) = a.shr1_with_carry();
4040
let half_modulus = modulus.shr1();
4141

42-
let if_odd = ret
42+
let if_odd = half
4343
.wrapping_add(&half_modulus)
4444
.wrapping_add(&BoxedUint::one_with_precision(a.bits_precision()));
45-
ret.conditional_assign(&if_odd, is_odd);
4645

47-
ret
46+
BoxedUint::ct_select(&half, &if_odd, is_odd)
4847
}
4948
}

src/uint/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod sub_mod;
2727
#[cfg(feature = "rand_core")]
2828
mod rand;
2929

30-
use crate::{Integer, Limb, NonZero, Uint, Word, Zero, U128, U64};
30+
use crate::{Integer, Limb, NonZero, Word, Zero};
3131
use alloc::{boxed::Box, vec, vec::Vec};
3232
use core::fmt;
3333
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

src/uint/boxed/sqrt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use subtle::{ConstantTimeEq, ConstantTimeGreater, CtOption};
44

5-
use crate::{BoxedUint, NonZero};
5+
use crate::{ConstantTimeSelect, BoxedUint, NonZero};
66

77
impl BoxedUint {
88
/// Computes √(`self`) in constant time.
@@ -35,7 +35,7 @@ impl BoxedUint {
3535
let (q, _) = self.div_rem(&nz_x);
3636

3737
// A protection in case `self == 0`, which will make `x == 0`
38-
let q = Self::conditional_select(
38+
let q = Self::ct_select(
3939
&Self::zero_with_precision(self.bits_precision()),
4040
&q,
4141
is_some,
@@ -48,7 +48,7 @@ impl BoxedUint {
4848
// At this point `x_prev == x_{n}` and `x == x_{n+1}`
4949
// where `n == i - 1 == LOG2_BITS + 1 == floor(log2(BITS)) + 1`.
5050
// Thus, according to Hast, `sqrt(self) = min(x_n, x_{n+1})`.
51-
Self::conditional_select(&x_prev, &x, Self::ct_gt(&x_prev, &x))
51+
Self::ct_select(&x_prev, &x, Self::ct_gt(&x_prev, &x))
5252
}
5353

5454
/// Computes √(`self`)

0 commit comments

Comments
 (0)