Skip to content

Commit

Permalink
replace select with conditional_select
Browse files Browse the repository at this point in the history
  • Loading branch information
xuganyu96 committed Dec 18, 2023
1 parent 13892bd commit ad95de0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
17 changes: 0 additions & 17 deletions src/uint/boxed/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,6 @@ use subtle::{
};

impl BoxedUint {
/// Return `b` if `c` is truthy, otherwise return `a`.
#[inline]
pub(crate) fn select(a: &Self, b: &Self, c: ConstChoice) -> Self {
debug_assert_eq!(a.limbs.len(), b.limbs.len());
let mut limbs = vec![Limb::ZERO; a.limbs.len()];

let mut i = 0;
while i < limbs.len() {
limbs[i] = Limb::select(a.limbs[i], b.limbs[i], c);
i += 1;
}

Self {
limbs: limbs.into(),
}
}

/// Returns the truthy value if `self >= rhs` and the falsy value otherwise.
#[inline]
pub(crate) fn gt(lhs: &Self, rhs: &Self) -> ConstChoice {
Expand Down
2 changes: 1 addition & 1 deletion src/uint/boxed/sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl BoxedUint {
// At this point `x_prev == x_{n}` and `x == x_{n+1}`
// where `n == i - 1 == LOG2_BITS + 1 == floor(log2(BITS)) + 1`.
// Thus, according to Hast, `sqrt(self) = min(x_n, x_{n+1})`.
Self::select(&x_prev, &x, BoxedUint::gt(&x_prev, &x))
Self::conditional_select(&x_prev, &x, Self::gt(&x_prev, &x).into())
}

/// Computes √(`self`)
Expand Down

0 comments on commit ad95de0

Please sign in to comment.