Skip to content

Commit 6e5c878

Browse files
committed
Rename sh(r/l)1_with_overflow to *_with_carry
1 parent f7a016e commit 6e5c878

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
@@ -101,7 +101,7 @@ impl BoxedUint {
101101
let bit_size = bits + modulus_bits;
102102

103103
let mut m1hp = modulus.clone();
104-
let (m1hp_new, carry) = m1hp.shr1_with_overflow();
104+
let (m1hp_new, carry) = m1hp.shr1_with_carry();
105105
debug_assert!(bool::from(carry));
106106
m1hp = m1hp_new.wrapping_add(&Self::one_with_precision(bits_precision));
107107

@@ -124,9 +124,9 @@ impl BoxedUint {
124124
let cyy = new_u.conditional_adc_assign(modulus, cy);
125125
debug_assert!(bool::from(cy.ct_eq(&cyy)));
126126

127-
let (new_a, overflow) = a.shr1_with_overflow();
127+
let (new_a, overflow) = a.shr1_with_carry();
128128
debug_assert!(!bool::from(overflow));
129-
let (mut new_u, cy) = new_u.shr1_with_overflow();
129+
let (mut new_u, cy) = new_u.shr1_with_carry();
130130
let cy = new_u.conditional_adc_assign(&m1hp, cy);
131131
debug_assert!(!bool::from(cy));
132132

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
@@ -97,7 +97,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
9797
let bit_size = bits + modulus_bits;
9898

9999
let mut m1hp = *modulus;
100-
let (m1hp_new, carry) = m1hp.shr1_with_overflow();
100+
let (m1hp_new, carry) = m1hp.shr1_with_carry();
101101
debug_assert!(carry.is_true_vartime());
102102
m1hp = m1hp_new.wrapping_add(&Uint::ONE);
103103

@@ -119,9 +119,9 @@ impl<const LIMBS: usize> Uint<LIMBS> {
119119
let (new_u, cyy) = new_u.conditional_wrapping_add(modulus, cy);
120120
debug_assert!(cy.is_true_vartime() == cyy.is_true_vartime());
121121

122-
let (new_a, overflow) = a.shr1_with_overflow();
122+
let (new_a, overflow) = a.shr1_with_carry();
123123
debug_assert!(!overflow.is_true_vartime());
124-
let (new_u, cy) = new_u.shr1_with_overflow();
124+
let (new_u, cy) = new_u.shr1_with_carry();
125125
let (new_u, cy) = new_u.conditional_wrapping_add(&m1hp, cy);
126126
debug_assert!(!cy.is_true_vartime());
127127

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)