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
- HMAC — A way of combining a secret key with a hash function to produce a tag that shows a message came from someone holding the key and was not changed.
- MAC — A short tag computed from a message and a secret key, which lets the receiver check the message is unchanged and came from a key holder.
- secret — Any value that grants access, such as a password, access token or private key, and must be kept out of code and version control.
- timing attack — An attack that works out secret information by measuring how long an operation takes.
- password hashing — Storing a password as the output of a deliberately slow, salted hash function, so a stolen database does not reveal the passwords.
Taught in
- CIA Triad, Non-Repudiation & Parkerian Hexad — Cybersecurity Fundamentals, GRC & Cryptography
- Cryptographic Hashing: SHA-256, SHA-3 & Passwords — Cybersecurity Fundamentals, GRC & Cryptography
- Authentication Versus Authorisation — Application Security & Threat Modeling for Engineers
- Provenance And Signing — Application Security & Threat Modeling for Engineers