Skip to main content

constant_time_eq

Function constant_time_eq 

Source
pub fn constant_time_eq(a: &[u8], b: &[u8]) -> bool
Expand description

Whether a equals b, compared in constant time for equal lengths.

Response timing then does not reveal how many leading bytes matched. Different lengths return false at once: lengths are not secret.

ยงExamples

assert!(ocre::token::constant_time_eq(b"secret", b"secret"));
assert!(!ocre::token::constant_time_eq(b"secret", b"secreT"));
assert!(!ocre::token::constant_time_eq(b"secret", b"secrets"));