Skip to main content

Module ct

Module ct 

Expand description

Constant-time byte-slice comparison.

== on &[u8] short-circuits on the first mismatching byte, which lets an attacker who can observe comparison latency probe a secret byte by byte. The helpers below always inspect the full shorter slice and then fold the length check into the result, so the time taken depends only on the lengths of the inputs (not on where they differ).

Primary use is comparing credential blobs (HTTP Basic, Bearer tokens, API keys); see rama-net::user::credentials for the consumers.

Functions§

ct_eq_bytes
Constant-time equality for two byte slices.