File tree 4 files changed +17
-10
lines changed
4 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -135,9 +135,16 @@ pub trait Zero: ConstantTimeEq + Sized {
135
135
/// # Returns
136
136
///
137
137
/// If zero, returns `Choice(1)`. Otherwise, returns `Choice(0)`.
138
+ #[ inline]
138
139
fn is_zero ( & self ) -> Choice {
139
140
self . ct_eq ( & Self :: zero ( ) )
140
141
}
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
+ }
141
148
}
142
149
143
150
/// Trait for associating a constant representing zero.
@@ -149,6 +156,7 @@ pub trait ZeroConstant: Zero {
149
156
}
150
157
151
158
impl < T : ZeroConstant > Zero for T {
159
+ #[ inline( always) ]
152
160
fn zero ( ) -> T {
153
161
Self :: ZERO
154
162
}
Original file line number Diff line number Diff line change @@ -237,13 +237,8 @@ impl BoxedUint {
237
237
limbs. into ( )
238
238
}
239
239
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
-
245
240
/// 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 ) {
247
242
let nlimbs = self . nlimbs ( ) ;
248
243
let limbs = self . limbs . as_mut ( ) ;
249
244
for i in 0 ..nlimbs {
@@ -408,6 +403,10 @@ impl Zero for BoxedUint {
408
403
fn is_zero ( & self ) -> Choice {
409
404
self . is_zero ( )
410
405
}
406
+
407
+ fn set_zero ( & mut self ) {
408
+ self . limbs . as_mut ( ) . fill ( Limb :: ZERO )
409
+ }
411
410
}
412
411
413
412
#[ cfg( feature = "zeroize" ) ]
Original file line number Diff line number Diff line change @@ -20,15 +20,15 @@ impl BoxedUint {
20
20
21
21
for i in 0 ..shift_bits {
22
22
let bit = Choice :: from ( ( ( shift >> i) & 1 ) as u8 ) ;
23
- temp. set_to_zero ( ) ;
23
+ temp. set_zero ( ) ;
24
24
// Will not overflow by construction
25
25
result
26
26
. shl_vartime_into ( & mut temp, 1 << i)
27
27
. expect ( "shift within range" ) ;
28
28
result. conditional_assign ( & temp, bit) ;
29
29
}
30
30
31
- result. conditional_set_to_zero ( overflow) ;
31
+ result. conditional_set_zero ( overflow) ;
32
32
33
33
( result, overflow)
34
34
}
Original file line number Diff line number Diff line change @@ -20,15 +20,15 @@ impl BoxedUint {
20
20
21
21
for i in 0 ..shift_bits {
22
22
let bit = Choice :: from ( ( ( shift >> i) & 1 ) as u8 ) ;
23
- temp. set_to_zero ( ) ;
23
+ temp. set_zero ( ) ;
24
24
// Will not overflow by construction
25
25
result
26
26
. shr_vartime_into ( & mut temp, 1 << i)
27
27
. expect ( "shift within range" ) ;
28
28
result. conditional_assign ( & temp, bit) ;
29
29
}
30
30
31
- result. conditional_set_to_zero ( overflow) ;
31
+ result. conditional_set_zero ( overflow) ;
32
32
33
33
( result, overflow)
34
34
}
You can’t perform that action at this time.
0 commit comments