Skip to main content

constant_time_eq

Function constant_time_eq 

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

Compare two byte strings without an early exit on the first difference, so response timing does not leak how many leading bytes of a secret a caller guessed right.

The length check is a deliberate exception: it leaks only the secret’s length, which is not the secret, and comparing unequal-length slices has no meaningful definition.

Lives here because both gglib-axum and gglib-proxy guard bearer tokens and each had a byte-identical private copy. normalize_host, which both guards also call, already lived here. A hardening change to one private copy would not have been reported against the other by any lint.