1- use crate :: { CtChoice , Limb , Uint } ;
1+ use crate :: { ConstChoice , Limb , Uint } ;
22
33impl < const LIMBS : usize > Uint < LIMBS > {
4- /// Get the value of the bit at position `index`, as a truthy or falsy `CtChoice `.
4+ /// Get the value of the bit at position `index`, as a truthy or falsy `ConstChoice `.
55 /// Returns the falsy value for indices out of range.
6- pub const fn bit ( & self , index : u32 ) -> CtChoice {
6+ pub const fn bit ( & self , index : u32 ) -> ConstChoice {
77 let limb_num = index / Limb :: BITS ;
88 let index_in_limb = index % Limb :: BITS ;
99 let index_mask = 1 << index_in_limb;
@@ -14,12 +14,12 @@ impl<const LIMBS: usize> Uint<LIMBS> {
1414 let mut i = 0 ;
1515 while i < LIMBS {
1616 let bit = limbs[ i] & index_mask;
17- let is_right_limb = CtChoice :: from_u32_eq ( i as u32 , limb_num) ;
17+ let is_right_limb = ConstChoice :: from_u32_eq ( i as u32 , limb_num) ;
1818 result |= is_right_limb. if_true_word ( bit) ;
1919 i += 1 ;
2020 }
2121
22- CtChoice :: from_word_lsb ( result >> index_in_limb)
22+ ConstChoice :: from_word_lsb ( result >> index_in_limb)
2323 }
2424
2525 /// Returns `true` if the bit at position `index` is set, `false` otherwise.
@@ -59,14 +59,14 @@ impl<const LIMBS: usize> Uint<LIMBS> {
5959
6060 let mut count = 0 ;
6161 let mut i = LIMBS ;
62- let mut nonzero_limb_not_encountered = CtChoice :: TRUE ;
62+ let mut nonzero_limb_not_encountered = ConstChoice :: TRUE ;
6363 while i > 0 {
6464 i -= 1 ;
6565 let l = limbs[ i] ;
6666 let z = l. leading_zeros ( ) ;
6767 count += nonzero_limb_not_encountered. if_true_u32 ( z) ;
6868 nonzero_limb_not_encountered =
69- nonzero_limb_not_encountered. and ( CtChoice :: from_word_nonzero ( l. 0 ) . not ( ) ) ;
69+ nonzero_limb_not_encountered. and ( ConstChoice :: from_word_nonzero ( l. 0 ) . not ( ) ) ;
7070 }
7171
7272 count
@@ -98,13 +98,13 @@ impl<const LIMBS: usize> Uint<LIMBS> {
9898
9999 let mut count = 0 ;
100100 let mut i = 0 ;
101- let mut nonzero_limb_not_encountered = CtChoice :: TRUE ;
101+ let mut nonzero_limb_not_encountered = ConstChoice :: TRUE ;
102102 while i < LIMBS {
103103 let l = limbs[ i] ;
104104 let z = l. trailing_zeros ( ) ;
105105 count += nonzero_limb_not_encountered. if_true_u32 ( z) ;
106106 nonzero_limb_not_encountered =
107- nonzero_limb_not_encountered. and ( CtChoice :: from_word_nonzero ( l. 0 ) . not ( ) ) ;
107+ nonzero_limb_not_encountered. and ( ConstChoice :: from_word_nonzero ( l. 0 ) . not ( ) ) ;
108108 i += 1 ;
109109 }
110110
@@ -137,13 +137,13 @@ impl<const LIMBS: usize> Uint<LIMBS> {
137137
138138 let mut count = 0 ;
139139 let mut i = 0 ;
140- let mut nonmax_limb_not_encountered = CtChoice :: TRUE ;
140+ let mut nonmax_limb_not_encountered = ConstChoice :: TRUE ;
141141 while i < LIMBS {
142142 let l = limbs[ i] ;
143143 let z = l. trailing_ones ( ) ;
144144 count += nonmax_limb_not_encountered. if_true_u32 ( z) ;
145145 nonmax_limb_not_encountered =
146- nonmax_limb_not_encountered. and ( CtChoice :: from_word_eq ( l. 0 , Limb :: MAX . 0 ) ) ;
146+ nonmax_limb_not_encountered. and ( ConstChoice :: from_word_eq ( l. 0 , Limb :: MAX . 0 ) ) ;
147147 i += 1 ;
148148 }
149149
@@ -171,15 +171,15 @@ impl<const LIMBS: usize> Uint<LIMBS> {
171171 }
172172
173173 /// Sets the bit at `index` to 0 or 1 depending on the value of `bit_value`.
174- pub ( crate ) const fn set_bit ( self , index : u32 , bit_value : CtChoice ) -> Self {
174+ pub ( crate ) const fn set_bit ( self , index : u32 , bit_value : ConstChoice ) -> Self {
175175 let mut result = self ;
176176 let limb_num = index / Limb :: BITS ;
177177 let index_in_limb = index % Limb :: BITS ;
178178 let index_mask = 1 << index_in_limb;
179179
180180 let mut i = 0 ;
181181 while i < LIMBS {
182- let is_right_limb = CtChoice :: from_u32_eq ( i as u32 , limb_num) ;
182+ let is_right_limb = ConstChoice :: from_u32_eq ( i as u32 , limb_num) ;
183183 let old_limb = result. limbs [ i] . 0 ;
184184 let new_limb = bit_value. select_word ( old_limb & !index_mask, old_limb | index_mask) ;
185185 result. limbs [ i] = Limb ( is_right_limb. select_word ( old_limb, new_limb) ) ;
@@ -191,7 +191,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
191191
192192#[ cfg( test) ]
193193mod tests {
194- use crate :: { CtChoice , U256 } ;
194+ use crate :: { ConstChoice , U256 } ;
195195
196196 fn uint_with_bits_at ( positions : & [ u32 ] ) -> U256 {
197197 let mut result = U256 :: ZERO ;
@@ -337,25 +337,25 @@ mod tests {
337337 fn set_bit ( ) {
338338 let u = uint_with_bits_at ( & [ 16 , 79 , 150 ] ) ;
339339 assert_eq ! (
340- u. set_bit( 127 , CtChoice :: TRUE ) ,
340+ u. set_bit( 127 , ConstChoice :: TRUE ) ,
341341 uint_with_bits_at( & [ 16 , 79 , 127 , 150 ] )
342342 ) ;
343343
344344 let u = uint_with_bits_at ( & [ 16 , 79 , 150 ] ) ;
345345 assert_eq ! (
346- u. set_bit( 150 , CtChoice :: TRUE ) ,
346+ u. set_bit( 150 , ConstChoice :: TRUE ) ,
347347 uint_with_bits_at( & [ 16 , 79 , 150 ] )
348348 ) ;
349349
350350 let u = uint_with_bits_at ( & [ 16 , 79 , 150 ] ) ;
351351 assert_eq ! (
352- u. set_bit( 127 , CtChoice :: FALSE ) ,
352+ u. set_bit( 127 , ConstChoice :: FALSE ) ,
353353 uint_with_bits_at( & [ 16 , 79 , 150 ] )
354354 ) ;
355355
356356 let u = uint_with_bits_at ( & [ 16 , 79 , 150 ] ) ;
357357 assert_eq ! (
358- u. set_bit( 150 , CtChoice :: FALSE ) ,
358+ u. set_bit( 150 , ConstChoice :: FALSE ) ,
359359 uint_with_bits_at( & [ 16 , 79 ] )
360360 ) ;
361361 }
0 commit comments