safeEqual

fnbool safeEqual(const(ubyte)[] a, const(ubyte)[] b) @safe pure nothrow @nogc

Performs a constant-time comparison of two byte arrays to prevent timing attacks.

Note

This function returns false immediately if the arrays have different lengths,

which leaks length information through timing. For cryptographic MAC verification where even the length should be hidden, compare after hashing both values to a fixed length (e.g., using HMAC).

Parameters

aThe first byte array.
bThe second byte array.

Returns

true if the arrays are identical, false otherwise.