Skip to content

Commit 1640e79

Browse files
committed
Rename sh(r/l)1_with_overflow to *_with_carry
1 parent 17145af commit 1640e79

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

src/modular/div_by_2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) fn div_by_2<const LIMBS: usize>(a: &Uint<LIMBS>, modulus: &Uint<LIMBS
1818
// ("+1" because both `a` and `modulus` are odd, we lose 0.5 in each integer division).
1919
// This will not overflow, so we can just use wrapping operations.
2020

21-
let (half, is_odd) = a.shr1_with_overflow();
21+
let (half, is_odd) = a.shr1_with_carry();
2222
let half_modulus = modulus.shr1();
2323

2424
let if_even = half;

src/uint/boxed/inv_mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ impl BoxedUint {
126126
let cyy = new_u.conditional_adc_assign(modulus, cy);
127127
debug_assert!(bool::from(cy.ct_eq(&cyy)));
128128

129-
let (new_a, overflow) = a.shr1_with_overflow();
130-
debug_assert!(bool::from(!modulus_is_odd | !overflow));
131-
let (mut new_u, cy) = new_u.shr1_with_overflow();
129+
let (new_a, carry) = a.shr1_with_carry();
130+
debug_assert!(bool::from(!modulus_is_odd | !carry));
131+
let (mut new_u, cy) = new_u.shr1_with_carry();
132132
let cy = new_u.conditional_adc_assign(&m1hp, cy);
133133
debug_assert!(bool::from(!modulus_is_odd | !cy));
134134

src/uint/boxed/shr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ impl BoxedUint {
8585
success.map(|_| result)
8686
}
8787

88-
/// Computes `self >> 1` in constant-time, returning a true [`Choice`] if the overflowing bit
89-
/// was set, and a false [`Choice::FALSE`] otherwise.
90-
pub(crate) fn shr1_with_overflow(&self) -> (Self, Choice) {
88+
/// Computes `self >> 1` in constant-time, returning a true [`Choice`]
89+
/// if the least significant bit was set, and a false [`Choice::FALSE`] otherwise.
90+
pub(crate) fn shr1_with_carry(&self) -> (Self, Choice) {
9191
let carry = self.limbs[0].0 & 1;
9292
(self.shr1(), Choice::from(carry as u8))
9393
}

src/uint/inv_mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ impl<const LIMBS: usize> Uint<LIMBS> {
128128
let (new_u, cyy) = new_u.conditional_wrapping_add(modulus, cy);
129129
debug_assert!(cy.is_true_vartime() == cyy.is_true_vartime());
130130

131-
let (new_a, overflow) = a.shr1_with_overflow();
132-
debug_assert!(modulus_is_odd.not().or(overflow.not()).is_true_vartime());
133-
let (new_u, cy) = new_u.shr1_with_overflow();
131+
let (new_a, carry) = a.shr1_with_carry();
132+
debug_assert!(modulus_is_odd.not().or(carry.not()).is_true_vartime());
133+
let (new_u, cy) = new_u.shr1_with_carry();
134134
let (new_u, cy) = new_u.conditional_wrapping_add(&m1hp, cy);
135135
debug_assert!(modulus_is_odd.not().or(cy.not()).is_true_vartime());
136136

src/uint/shl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ impl<const LIMBS: usize> Uint<LIMBS> {
118118
(Uint::<LIMBS>::new(limbs), Limb(carry))
119119
}
120120

121-
/// Computes `self << 1` in constant-time, returning [`CtChoice::TRUE`] if the overflowing bit
122-
/// was set, and [`CtChoice::FALSE`] otherwise.
121+
/// Computes `self << 1` in constant-time, returning [`CtChoice::TRUE`]
122+
/// if the most significant bit was set, and [`CtChoice::FALSE`] otherwise.
123123
#[inline(always)]
124-
pub(crate) const fn shl1_with_overflow(&self) -> (Self, CtChoice) {
124+
pub(crate) const fn shl1_with_carry(&self) -> (Self, CtChoice) {
125125
let mut ret = Self::ZERO;
126126
let mut i = 0;
127127
let mut carry = Limb::ZERO;
@@ -138,7 +138,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
138138
/// Computes `self << 1` in constant-time.
139139
pub(crate) const fn shl1(&self) -> Self {
140140
// TODO(tarcieri): optimized implementation
141-
self.shl1_with_overflow().0
141+
self.shl1_with_carry().0
142142
}
143143
}
144144

src/uint/shr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ impl<const LIMBS: usize> Uint<LIMBS> {
9393
}
9494
}
9595

96-
/// Computes `self >> 1` in constant-time, returning [`CtChoice::TRUE`] if the overflowing bit
97-
/// was set, and [`CtChoice::FALSE`] otherwise.
96+
/// Computes `self >> 1` in constant-time, returning [`CtChoice::TRUE`]
97+
/// if the least significant bit was set, and [`CtChoice::FALSE`] otherwise.
9898
#[inline(always)]
99-
pub(crate) const fn shr1_with_overflow(&self) -> (Self, CtChoice) {
99+
pub(crate) const fn shr1_with_carry(&self) -> (Self, CtChoice) {
100100
let mut ret = Self::ZERO;
101101
let mut i = LIMBS;
102102
let mut carry = Limb::ZERO;
@@ -113,7 +113,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
113113
/// Computes `self >> 1` in constant-time.
114114
pub(crate) const fn shr1(&self) -> Self {
115115
// TODO(tarcieri): optimized implementation
116-
self.shr1_with_overflow().0
116+
self.shr1_with_carry().0
117117
}
118118
}
119119

0 commit comments

Comments
 (0)