Skip to main content

constant_time_eq_fixed_width

Function constant_time_eq_fixed_width 

Source
pub fn constant_time_eq_fixed_width<const N: usize>(
    left: &[u8; N],
    right: &[u8; N],
) -> bool
Expand description

Compares two fixed-width byte arrays without a length-mismatch branch.

Use this helper when the value length itself should not be represented as a timing-distinct branch in the comparison API. The array length N is a compile-time public type fact, and the helper scans exactly N bytes before returning. The final equality result remains public. This is still a dependency-free, constant-time-oriented best-effort helper, not a formally verified cryptographic comparison primitive.

ยงExamples

use base64_ng::constant_time_eq_fixed_width;

assert!(constant_time_eq_fixed_width(b"token", b"token"));
assert!(!constant_time_eq_fixed_width(b"token", b"Token"));