Skip to content

Commit e965e0a

Browse files
committed
rust: add tink::subtle::constant_time_compare
Based on the `subtle` crate's `ConstantTimeEq` trait.
1 parent ab87b8d commit e965e0a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

rust/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/tink/src/subtle/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
use crate::TinkError;
1818
use digest::Digest;
19+
use subtle::ConstantTimeEq;
1920

2021
mod hkdf;
2122
pub use self::hkdf::*;
@@ -127,3 +128,8 @@ pub fn new_big_int_from_hex(s : &str) (*big.Int, error) {
127128
return ret, nil
128129
}
129130
*/
131+
132+
/// Compare two slices in constant time. Return `true` if they are equal, `false` otherwise.
133+
pub fn constant_time_compare(left: &[u8], right: &[u8]) -> bool {
134+
left.ct_eq(right).into()
135+
}

0 commit comments

Comments
 (0)