constant-time comparison

Comparing two secret values in a way that always takes the same time, whether they differ in the first byte or the last.

In more detail

An ordinary equality check stops at the first differing byte, so its timing leaks how much of a guess was right. Use a constant-time comparison, such as Python's hmac.compare_digest, when checking derived password keys, signatures and tokens.

Example

hmac.compare_digest(good, tag)

Related terms

Taught in

References