@@ -49,12 +49,12 @@ impl<const LIMBS: usize> Uint<LIMBS> {
49
49
50
50
/// Returns the truthy value if `self == rhs` or the falsy value otherwise.
51
51
#[ inline]
52
- pub ( crate ) const fn ct_eq ( & self , rhs : & Self ) -> CtChoice {
52
+ pub ( crate ) const fn ct_eq ( lhs : & Self , rhs : & Self ) -> CtChoice {
53
53
let mut acc = 0 ;
54
54
let mut i = 0 ;
55
55
56
56
while i < LIMBS {
57
- acc |= self . limbs [ i] . 0 ^ rhs. limbs [ i] . 0 ;
57
+ acc |= lhs . limbs [ i] . 0 ^ rhs. limbs [ i] . 0 ;
58
58
i += 1 ;
59
59
}
60
60
@@ -64,40 +64,40 @@ impl<const LIMBS: usize> Uint<LIMBS> {
64
64
65
65
/// Returns the truthy value if `self <= rhs` and the falsy value otherwise.
66
66
#[ inline]
67
- pub ( crate ) const fn ct_lt ( & self , rhs : & Self ) -> CtChoice {
67
+ pub ( crate ) const fn ct_lt ( lhs : & Self , rhs : & Self ) -> CtChoice {
68
68
// We could use the same approach as in Limb::ct_lt(),
69
69
// but since we have to use Uint::wrapping_sub(), which calls `sbb()`,
70
70
// there are no savings compared to just calling `sbb()` directly.
71
- let ( _res, borrow) = self . sbb ( rhs, Limb :: ZERO ) ;
71
+ let ( _res, borrow) = lhs . sbb ( rhs, Limb :: ZERO ) ;
72
72
CtChoice :: from_mask ( borrow. 0 )
73
73
}
74
74
75
75
/// Returns the truthy value if `self <= rhs` and the falsy value otherwise.
76
76
#[ inline]
77
- pub ( crate ) const fn ct_gt ( & self , rhs : & Self ) -> CtChoice {
78
- let ( _res, borrow) = rhs. sbb ( self , Limb :: ZERO ) ;
77
+ pub ( crate ) const fn ct_gt ( lhs : & Self , rhs : & Self ) -> CtChoice {
78
+ let ( _res, borrow) = rhs. sbb ( lhs , Limb :: ZERO ) ;
79
79
CtChoice :: from_mask ( borrow. 0 )
80
80
}
81
81
}
82
82
83
83
impl < const LIMBS : usize > ConstantTimeEq for Uint < LIMBS > {
84
84
#[ inline]
85
85
fn ct_eq ( & self , other : & Self ) -> Choice {
86
- self . ct_eq ( other) . into ( )
86
+ Uint :: ct_eq ( self , other) . into ( )
87
87
}
88
88
}
89
89
90
90
impl < const LIMBS : usize > ConstantTimeGreater for Uint < LIMBS > {
91
91
#[ inline]
92
92
fn ct_gt ( & self , other : & Self ) -> Choice {
93
- self . ct_gt ( other) . into ( )
93
+ Uint :: ct_gt ( self , other) . into ( )
94
94
}
95
95
}
96
96
97
97
impl < const LIMBS : usize > ConstantTimeLess for Uint < LIMBS > {
98
98
#[ inline]
99
99
fn ct_lt ( & self , other : & Self ) -> Choice {
100
- self . ct_lt ( other) . into ( )
100
+ Uint :: ct_lt ( self , other) . into ( )
101
101
}
102
102
}
103
103
@@ -154,10 +154,10 @@ mod tests {
154
154
let a = U128 :: ZERO ;
155
155
let b = U128 :: MAX ;
156
156
157
- assert ! ( bool :: from( ConstantTimeEq :: ct_eq( & a , & a) ) ) ;
158
- assert ! ( !bool :: from( ConstantTimeEq :: ct_eq( & a , & b) ) ) ;
159
- assert ! ( !bool :: from( ConstantTimeEq :: ct_eq( & b , & a) ) ) ;
160
- assert ! ( bool :: from( ConstantTimeEq :: ct_eq( & b , & b) ) ) ;
157
+ assert ! ( bool :: from( a . ct_eq( & a) ) ) ;
158
+ assert ! ( !bool :: from( a . ct_eq( & b) ) ) ;
159
+ assert ! ( !bool :: from( b . ct_eq( & a) ) ) ;
160
+ assert ! ( bool :: from( b . ct_eq( & b) ) ) ;
161
161
}
162
162
163
163
#[ test]
@@ -166,17 +166,17 @@ mod tests {
166
166
let b = U128 :: ONE ;
167
167
let c = U128 :: MAX ;
168
168
169
- assert ! ( bool :: from( ConstantTimeGreater :: ct_gt( & b , & a) ) ) ;
170
- assert ! ( bool :: from( ConstantTimeGreater :: ct_gt( & c , & a) ) ) ;
171
- assert ! ( bool :: from( ConstantTimeGreater :: ct_gt( & c , & b) ) ) ;
169
+ assert ! ( bool :: from( b . ct_gt( & a) ) ) ;
170
+ assert ! ( bool :: from( c . ct_gt( & a) ) ) ;
171
+ assert ! ( bool :: from( c . ct_gt( & b) ) ) ;
172
172
173
- assert ! ( !bool :: from( ConstantTimeGreater :: ct_gt( & a , & a) ) ) ;
174
- assert ! ( !bool :: from( ConstantTimeGreater :: ct_gt( & b , & b) ) ) ;
175
- assert ! ( !bool :: from( ConstantTimeGreater :: ct_gt( & c , & c) ) ) ;
173
+ assert ! ( !bool :: from( a . ct_gt( & a) ) ) ;
174
+ assert ! ( !bool :: from( b . ct_gt( & b) ) ) ;
175
+ assert ! ( !bool :: from( c . ct_gt( & c) ) ) ;
176
176
177
- assert ! ( !bool :: from( ConstantTimeGreater :: ct_gt( & a , & b) ) ) ;
178
- assert ! ( !bool :: from( ConstantTimeGreater :: ct_gt( & a , & c) ) ) ;
179
- assert ! ( !bool :: from( ConstantTimeGreater :: ct_gt( & b , & c) ) ) ;
177
+ assert ! ( !bool :: from( a . ct_gt( & b) ) ) ;
178
+ assert ! ( !bool :: from( a . ct_gt( & c) ) ) ;
179
+ assert ! ( !bool :: from( b . ct_gt( & c) ) ) ;
180
180
}
181
181
182
182
#[ test]
@@ -185,16 +185,16 @@ mod tests {
185
185
let b = U128 :: ONE ;
186
186
let c = U128 :: MAX ;
187
187
188
- assert ! ( bool :: from( ConstantTimeLess :: ct_lt( & a , & b) ) ) ;
189
- assert ! ( bool :: from( ConstantTimeLess :: ct_lt( & a , & c) ) ) ;
190
- assert ! ( bool :: from( ConstantTimeLess :: ct_lt( & b , & c) ) ) ;
188
+ assert ! ( bool :: from( a . ct_lt( & b) ) ) ;
189
+ assert ! ( bool :: from( a . ct_lt( & c) ) ) ;
190
+ assert ! ( bool :: from( b . ct_lt( & c) ) ) ;
191
191
192
- assert ! ( !bool :: from( ConstantTimeLess :: ct_lt( & a , & a) ) ) ;
193
- assert ! ( !bool :: from( ConstantTimeLess :: ct_lt( & b , & b) ) ) ;
194
- assert ! ( !bool :: from( ConstantTimeLess :: ct_lt( & c , & c) ) ) ;
192
+ assert ! ( !bool :: from( a . ct_lt( & a) ) ) ;
193
+ assert ! ( !bool :: from( b . ct_lt( & b) ) ) ;
194
+ assert ! ( !bool :: from( c . ct_lt( & c) ) ) ;
195
195
196
- assert ! ( !bool :: from( ConstantTimeLess :: ct_lt( & b , & a) ) ) ;
197
- assert ! ( !bool :: from( ConstantTimeLess :: ct_lt( & c , & a) ) ) ;
198
- assert ! ( !bool :: from( ConstantTimeLess :: ct_lt( & c , & b) ) ) ;
196
+ assert ! ( !bool :: from( b . ct_lt( & a) ) ) ;
197
+ assert ! ( !bool :: from( c . ct_lt( & a) ) ) ;
198
+ assert ! ( !bool :: from( c . ct_lt( & b) ) ) ;
199
199
}
200
200
}
0 commit comments