constant_time_eq
Compares two byte slices without stopping at the first difference.
The loop visits every byte and combines the differences with |, so the time it takes does
not depend on where the slices differ, only on their length (a length mismatch returns at
once, so the length is not secret). This is a best effort: Rust and LLVM give no hard
guarantee that a compiler will not turn it back into an early exit, so for cryptographic
code that needs one, use a dedicated crate such as subtle.
Import
Section titled “Import”Cargo feature bytes (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
a | &[u8] | The first slice. |
b | &[u8] | The second slice. |
Returns
Section titled “Returns”bool — true when both slices have the same length and the same content.
