A naive equality check returns the instant it finds a mismatch — and that early exit is a side channel: an attacker who measures how long a password or MAC comparison takes learns how many leading bytes were right, and can forge a secret one byte at a time. The fix is to refuse to hurry: XOR every pair of bytes and OR the differences into an accumulator, always visiting the whole input, then check if the accumulator is zero. Same yes/no answer, but the running time no longer depends on where the first difference is. Security here is a property of the mechanism’s timing, not its output.
The demo compares two arrays that differ at index 2 (equal answer to a naive check) while visiting all four elements — no early exit: live demo
“Return as soon as you know the answer.” — for secrets, the when is the leak; a safe compare always runs to the end. cited
An equality test that always runs to the end — the answer unchanged, the timing silenced. side-channel
On the canonical compiler, the constant-time compare returns not-equal for arrays differing at index 2, and equal for identical arrays — visiting all elements either way: