@@ -10,46 +10,46 @@ use subtle::{Choice, ConstantTimeEq, ConstantTimeGreater, ConstantTimeLess};
1010impl < const LIMBS : usize > Uint < LIMBS > {
1111 /// Return `b` if `c` is truthy, otherwise return `a`.
1212 #[ inline]
13- pub ( crate ) const fn ct_select ( a : & Self , b : & Self , c : CtChoice ) -> Self {
13+ pub ( crate ) const fn select ( a : & Self , b : & Self , c : CtChoice ) -> Self {
1414 let mut limbs = [ Limb :: ZERO ; LIMBS ] ;
1515
1616 let mut i = 0 ;
1717 while i < LIMBS {
18- limbs[ i] = Limb :: ct_select ( a. limbs [ i] , b. limbs [ i] , c) ;
18+ limbs[ i] = Limb :: select ( a. limbs [ i] , b. limbs [ i] , c) ;
1919 i += 1 ;
2020 }
2121
2222 Uint { limbs }
2323 }
2424
2525 #[ inline]
26- pub ( crate ) const fn ct_swap ( a : & Self , b : & Self , c : CtChoice ) -> ( Self , Self ) {
27- let new_a = Self :: ct_select ( a, b, c) ;
28- let new_b = Self :: ct_select ( b, a, c) ;
26+ pub ( crate ) const fn swap ( a : & Self , b : & Self , c : CtChoice ) -> ( Self , Self ) {
27+ let new_a = Self :: select ( a, b, c) ;
28+ let new_b = Self :: select ( b, a, c) ;
2929
3030 ( new_a, new_b)
3131 }
3232
3333 /// Returns the truthy value if `self`!=0 or the falsy value otherwise.
3434 #[ inline]
35- pub ( crate ) const fn ct_is_nonzero ( & self ) -> CtChoice {
35+ pub ( crate ) const fn is_nonzero ( & self ) -> CtChoice {
3636 let mut b = 0 ;
3737 let mut i = 0 ;
3838 while i < LIMBS {
3939 b |= self . limbs [ i] . 0 ;
4040 i += 1 ;
4141 }
42- Limb ( b) . ct_is_nonzero ( )
42+ Limb ( b) . is_nonzero ( )
4343 }
4444
4545 /// Returns the truthy value if `self` is odd or the falsy value otherwise.
46- pub ( crate ) const fn ct_is_odd ( & self ) -> CtChoice {
46+ pub ( crate ) const fn is_odd ( & self ) -> CtChoice {
4747 CtChoice :: from_word_lsb ( self . limbs [ 0 ] . 0 & 1 )
4848 }
4949
5050 /// Returns the truthy value if `self == rhs` or the falsy value otherwise.
5151 #[ inline]
52- pub ( crate ) const fn ct_eq ( lhs : & Self , rhs : & Self ) -> CtChoice {
52+ pub ( crate ) const fn eq ( lhs : & Self , rhs : & Self ) -> CtChoice {
5353 let mut acc = 0 ;
5454 let mut i = 0 ;
5555
@@ -59,12 +59,12 @@ impl<const LIMBS: usize> Uint<LIMBS> {
5959 }
6060
6161 // acc == 0 if and only if self == rhs
62- Limb ( acc) . ct_is_nonzero ( ) . not ( )
62+ Limb ( acc) . is_nonzero ( ) . not ( )
6363 }
6464
6565 /// Returns the truthy value if `self <= rhs` and the falsy value otherwise.
6666 #[ inline]
67- pub ( crate ) const fn ct_lt ( lhs : & Self , rhs : & Self ) -> CtChoice {
67+ pub ( crate ) const fn lt ( lhs : & Self , rhs : & Self ) -> CtChoice {
6868 // We could use the same approach as in Limb::ct_lt(),
6969 // but since we have to use Uint::wrapping_sub(), which calls `sbb()`,
7070 // there are no savings compared to just calling `sbb()` directly.
@@ -74,7 +74,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
7474
7575 /// Returns the truthy value if `self >= rhs` and the falsy value otherwise.
7676 #[ inline]
77- pub ( crate ) const fn ct_gt ( lhs : & Self , rhs : & Self ) -> CtChoice {
77+ pub ( crate ) const fn gt ( lhs : & Self , rhs : & Self ) -> CtChoice {
7878 let ( _res, borrow) = rhs. sbb ( lhs, Limb :: ZERO ) ;
7979 CtChoice :: from_word_mask ( borrow. 0 )
8080 }
@@ -85,7 +85,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
8585 /// 0 is Equal
8686 /// 1 is Greater
8787 #[ inline]
88- pub ( crate ) const fn ct_cmp ( lhs : & Self , rhs : & Self ) -> i8 {
88+ pub ( crate ) const fn cmp ( lhs : & Self , rhs : & Self ) -> i8 {
8989 let mut i = 0 ;
9090 let mut borrow = Limb :: ZERO ;
9191 let mut diff = Limb :: ZERO ;
@@ -97,7 +97,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
9797 i += 1 ;
9898 }
9999 let sgn = ( ( borrow. 0 & 2 ) as i8 ) - 1 ;
100- ( diff. ct_is_nonzero ( ) . to_u8 ( ) as i8 ) * sgn
100+ ( diff. is_nonzero ( ) . to_u8 ( ) as i8 ) * sgn
101101 }
102102
103103 /// Returns the Ordering between `self` and `rhs` in variable time.
@@ -123,29 +123,29 @@ impl<const LIMBS: usize> Uint<LIMBS> {
123123impl < const LIMBS : usize > ConstantTimeEq for Uint < LIMBS > {
124124 #[ inline]
125125 fn ct_eq ( & self , other : & Self ) -> Choice {
126- Uint :: ct_eq ( self , other) . into ( )
126+ Uint :: eq ( self , other) . into ( )
127127 }
128128}
129129
130130impl < const LIMBS : usize > ConstantTimeGreater for Uint < LIMBS > {
131131 #[ inline]
132132 fn ct_gt ( & self , other : & Self ) -> Choice {
133- Uint :: ct_gt ( self , other) . into ( )
133+ Uint :: gt ( self , other) . into ( )
134134 }
135135}
136136
137137impl < const LIMBS : usize > ConstantTimeLess for Uint < LIMBS > {
138138 #[ inline]
139139 fn ct_lt ( & self , other : & Self ) -> Choice {
140- Uint :: ct_lt ( self , other) . into ( )
140+ Uint :: lt ( self , other) . into ( )
141141 }
142142}
143143
144144impl < const LIMBS : usize > Eq for Uint < LIMBS > { }
145145
146146impl < const LIMBS : usize > Ord for Uint < LIMBS > {
147147 fn cmp ( & self , other : & Self ) -> Ordering {
148- let c = Self :: ct_cmp ( self , other) ;
148+ let c = Self :: cmp ( self , other) ;
149149 match c {
150150 -1 => Ordering :: Less ,
151151 0 => Ordering :: Equal ,
@@ -181,9 +181,15 @@ mod tests {
181181
182182 #[ test]
183183 fn is_odd ( ) {
184+ // inherent methods
184185 assert ! ( !bool :: from( U128 :: ZERO . is_odd( ) ) ) ;
185186 assert ! ( bool :: from( U128 :: ONE . is_odd( ) ) ) ;
186187 assert ! ( bool :: from( U128 :: MAX . is_odd( ) ) ) ;
188+
189+ // `Integer` methods
190+ assert ! ( !bool :: from( <U128 as Integer >:: is_odd( & U128 :: ZERO ) ) ) ;
191+ assert ! ( bool :: from( <U128 as Integer >:: is_odd( & U128 :: ONE ) ) ) ;
192+ assert ! ( bool :: from( <U128 as Integer >:: is_odd( & U128 :: MAX ) ) ) ;
187193 }
188194
189195 #[ test]
0 commit comments