pub fn constant_time_compare(a: &[u8], b: &[u8]) -> boolExpand description
Performs constant-time comparison of two byte slices to prevent timing attacks.
This function compares two byte slices in constant time, meaning the execution time does not depend on where the first difference occurs. This is crucial for security-sensitive comparisons like tokens, passwords, or MAC verification.
§Arguments
a- First byte slice to compareb- Second byte slice to compare
§Returns
trueif the byte slices are equal,falseotherwise
§Security Notes
This function is designed to prevent timing attacks by ensuring that the comparison time remains constant regardless of input values.
§Example
use auth_framework::secure_utils::constant_time_compare;
let token1 = b"secure_token_value";
let token2 = b"secure_token_value";
let token3 = b"different_token";
assert!(constant_time_compare(token1, token2));
assert!(!constant_time_compare(token1, token3));