Skip to content

Commit e2819ce

Browse files
authored
Merge branch 'master' into boxed-uintlike-coverage
2 parents 3e1bb2e + 3094c66 commit e2819ce

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/traits.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,16 @@ pub trait Zero: ConstantTimeEq + Sized {
135135
/// # Returns
136136
///
137137
/// If zero, returns `Choice(1)`. Otherwise, returns `Choice(0)`.
138+
#[inline]
138139
fn is_zero(&self) -> Choice {
139140
self.ct_eq(&Self::zero())
140141
}
142+
143+
/// Set `self` to its additive identity, i.e. `Self::zero`.
144+
#[inline]
145+
fn set_zero(&mut self) {
146+
*self = Zero::zero();
147+
}
141148
}
142149

143150
/// Trait for associating a constant representing zero.
@@ -149,6 +156,7 @@ pub trait ZeroConstant: Zero {
149156
}
150157

151158
impl<T: ZeroConstant> Zero for T {
159+
#[inline(always)]
152160
fn zero() -> T {
153161
Self::ZERO
154162
}

src/uint/boxed.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,8 @@ impl BoxedUint {
237237
limbs.into()
238238
}
239239

240-
/// Set the value of `self` to zero in-place.
241-
pub(crate) fn set_to_zero(&mut self) {
242-
self.limbs.as_mut().fill(Limb::ZERO)
243-
}
244-
245240
/// Set the value of `self` to zero in-place if `choice` is truthy.
246-
pub(crate) fn conditional_set_to_zero(&mut self, choice: Choice) {
241+
pub(crate) fn conditional_set_zero(&mut self, choice: Choice) {
247242
let nlimbs = self.nlimbs();
248243
let limbs = self.limbs.as_mut();
249244
for i in 0..nlimbs {
@@ -408,6 +403,10 @@ impl Zero for BoxedUint {
408403
fn is_zero(&self) -> Choice {
409404
self.is_zero()
410405
}
406+
407+
fn set_zero(&mut self) {
408+
self.limbs.as_mut().fill(Limb::ZERO)
409+
}
411410
}
412411

413412
#[cfg(feature = "zeroize")]

src/uint/boxed/shl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ impl BoxedUint {
2020

2121
for i in 0..shift_bits {
2222
let bit = Choice::from(((shift >> i) & 1) as u8);
23-
temp.set_to_zero();
23+
temp.set_zero();
2424
// Will not overflow by construction
2525
result
2626
.shl_vartime_into(&mut temp, 1 << i)
2727
.expect("shift within range");
2828
result.conditional_assign(&temp, bit);
2929
}
3030

31-
result.conditional_set_to_zero(overflow);
31+
result.conditional_set_zero(overflow);
3232

3333
(result, overflow)
3434
}

src/uint/boxed/shr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ impl BoxedUint {
2020

2121
for i in 0..shift_bits {
2222
let bit = Choice::from(((shift >> i) & 1) as u8);
23-
temp.set_to_zero();
23+
temp.set_zero();
2424
// Will not overflow by construction
2525
result
2626
.shr_vartime_into(&mut temp, 1 << i)
2727
.expect("shift within range");
2828
result.conditional_assign(&temp, bit);
2929
}
3030

31-
result.conditional_set_to_zero(overflow);
31+
result.conditional_set_zero(overflow);
3232

3333
(result, overflow)
3434
}

0 commit comments

Comments
 (0)