diff --git a/src/modular/div_by_2.rs b/src/modular/div_by_2.rs index 278f3dda..12d82ed7 100644 --- a/src/modular/div_by_2.rs +++ b/src/modular/div_by_2.rs @@ -18,7 +18,7 @@ pub(crate) fn div_by_2(a: &Uint, modulus: &Uint> 1` in constant-time, returning a true [`Choice`] if the overflowing bit - /// was set, and a false [`Choice::FALSE`] otherwise. - pub(crate) fn shr1_with_overflow(&self) -> (Self, Choice) { + /// Computes `self >> 1` in constant-time, returning a true [`Choice`] + /// if the least significant bit was set, and a false [`Choice::FALSE`] otherwise. + pub(crate) fn shr1_with_carry(&self) -> (Self, Choice) { let carry = self.limbs[0].0 & 1; (self.shr1(), Choice::from(carry as u8)) } diff --git a/src/uint/inv_mod.rs b/src/uint/inv_mod.rs index bc8beb82..236f0ac1 100644 --- a/src/uint/inv_mod.rs +++ b/src/uint/inv_mod.rs @@ -128,9 +128,9 @@ impl Uint { let (new_u, cyy) = new_u.conditional_wrapping_add(modulus, cy); debug_assert!(cy.is_true_vartime() == cyy.is_true_vartime()); - let (new_a, overflow) = a.shr1_with_overflow(); - debug_assert!(modulus_is_odd.not().or(overflow.not()).is_true_vartime()); - let (new_u, cy) = new_u.shr1_with_overflow(); + let (new_a, carry) = a.shr1_with_carry(); + debug_assert!(modulus_is_odd.not().or(carry.not()).is_true_vartime()); + let (new_u, cy) = new_u.shr1_with_carry(); let (new_u, cy) = new_u.conditional_wrapping_add(&m1hp, cy); debug_assert!(modulus_is_odd.not().or(cy.not()).is_true_vartime()); diff --git a/src/uint/shl.rs b/src/uint/shl.rs index 632fe4e7..2b885d8d 100644 --- a/src/uint/shl.rs +++ b/src/uint/shl.rs @@ -118,10 +118,10 @@ impl Uint { (Uint::::new(limbs), Limb(carry)) } - /// Computes `self << 1` in constant-time, returning [`CtChoice::TRUE`] if the overflowing bit - /// was set, and [`CtChoice::FALSE`] otherwise. + /// Computes `self << 1` in constant-time, returning [`CtChoice::TRUE`] + /// if the most significant bit was set, and [`CtChoice::FALSE`] otherwise. #[inline(always)] - pub(crate) const fn shl1_with_overflow(&self) -> (Self, CtChoice) { + pub(crate) const fn shl1_with_carry(&self) -> (Self, CtChoice) { let mut ret = Self::ZERO; let mut i = 0; let mut carry = Limb::ZERO; @@ -138,7 +138,7 @@ impl Uint { /// Computes `self << 1` in constant-time. pub(crate) const fn shl1(&self) -> Self { // TODO(tarcieri): optimized implementation - self.shl1_with_overflow().0 + self.shl1_with_carry().0 } } diff --git a/src/uint/shr.rs b/src/uint/shr.rs index 3a4cd044..ffe984a9 100644 --- a/src/uint/shr.rs +++ b/src/uint/shr.rs @@ -93,10 +93,10 @@ impl Uint { } } - /// Computes `self >> 1` in constant-time, returning [`CtChoice::TRUE`] if the overflowing bit - /// was set, and [`CtChoice::FALSE`] otherwise. + /// Computes `self >> 1` in constant-time, returning [`CtChoice::TRUE`] + /// if the least significant bit was set, and [`CtChoice::FALSE`] otherwise. #[inline(always)] - pub(crate) const fn shr1_with_overflow(&self) -> (Self, CtChoice) { + pub(crate) const fn shr1_with_carry(&self) -> (Self, CtChoice) { let mut ret = Self::ZERO; let mut i = LIMBS; let mut carry = Limb::ZERO; @@ -113,7 +113,7 @@ impl Uint { /// Computes `self >> 1` in constant-time. pub(crate) const fn shr1(&self) -> Self { // TODO(tarcieri): optimized implementation - self.shr1_with_overflow().0 + self.shr1_with_carry().0 } }