File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,19 @@ pub trait ConstantTimeEq {
259
259
/// * `Choice(0u8)` if `self != other`.
260
260
#[ inline]
261
261
fn ct_eq ( & self , other : & Self ) -> Choice ;
262
+
263
+ /// Determine if two items are NOT equal.
264
+ ///
265
+ /// The `ct_ne` function should execute in constant time.
266
+ ///
267
+ /// # Returns
268
+ ///
269
+ /// * `Choice(0u8)` if `self == other`;
270
+ /// * `Choice(1u8)` if `self != other`.
271
+ #[ inline]
272
+ fn ct_ne ( & self , other : & Self ) -> Choice {
273
+ !self . ct_eq ( other)
274
+ }
262
275
}
263
276
264
277
impl < T : ConstantTimeEq > ConstantTimeEq for [ T ] {
Original file line number Diff line number Diff line change @@ -105,6 +105,8 @@ macro_rules! generate_integer_equal_tests {
105
105
106
106
assert_eq!( x. ct_eq( & y) . unwrap_u8( ) , 0 ) ;
107
107
assert_eq!( x. ct_eq( & z) . unwrap_u8( ) , 1 ) ;
108
+ assert_eq!( x. ct_ne( & y) . unwrap_u8( ) , 1 ) ;
109
+ assert_eq!( x. ct_ne( & z) . unwrap_u8( ) , 0 ) ;
108
110
) * )
109
111
}
110
112
You can’t perform that action at this time.
0 commit comments