Function secure_cmp
pub fn secure_cmp(a: &[u8], b: &[u8]) -> Result<(), UnknownCryptoError> ⓘ
Available on crate feature
dep_orion
only.Expand description
Compare two equal length slices in constant time.
§About:
Compare two equal length slices, in constant time, using the subtle crate.
§Parameters:
a
: The first slice used in the comparison.b
: The second slice used in the comparison.
§Errors:
An error will be returned if:
a
andb
do not have the same length.a
is not equal tob
.
§Example:
use orion::util;
let mut rnd_bytes = [0u8; 64];
assert!(util::secure_cmp(&rnd_bytes, &[0u8; 64]).is_ok());
util::secure_rand_bytes(&mut rnd_bytes)?;
assert!(util::secure_cmp(&rnd_bytes, &[0u8; 64]).is_err());