File tree Expand file tree Collapse file tree 4 files changed +17
-10
lines changed Expand file tree Collapse file tree 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 {
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
151158impl < T : ZeroConstant > Zero for T {
159+ #[ inline( always) ]
152160 fn zero ( ) -> T {
153161 Self :: ZERO
154162 }
Original file line number Diff line number Diff 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" ) ]
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments