ct_eq

Function ct_eq 

Source
pub fn ct_eq<A: AsRef<[u8]>, B: AsRef<[u8]>>(a: A, b: B) -> bool
Expand description

Compare two slices in constant-time.

§Arguments

The two arguments being compared in constant-time, both of these arguments must implement AsRef<[u8]> (such as &str, &[u8] itself, etc.)

§Note

If the length of slice a and slice b are not equivalent, this will exit early. In short, there is variable timing on length comparisons.

§Warning

Constant-time programming is nuanced, this implementation provides a best-effort constant-time equivalence check. While tools for verifying constant time properties over LLVM bitcode, a great deal of testing, paired with manual review of the output assembly, build some degree of confidence, there is still no guarantee of constant-time properties across all existing hardware.

§Returns

true if a == b, false otherwise.