Skip to content
Constant-Time Verification
step 1/5

Reading — step 1 of 5

Read

~1 min readVerification & Storage

Constant-Time Verification

DO NOT use plain == to compare hashes:

python

== returns early on the first byte mismatch. Attacker measures response times to deduce hash bytes ONE AT A TIME.

Use constant-time comparison:

python

Same concept: compare every byte, accumulate result via XOR + OR, return at end.

Side channels are real:

  • 2014: Lucky 13 attack on TLS via timing
  • 2018: Spectre/Meltdown via cache timing
  • 2020: Microarchitectural data sampling

For password comparison: ALWAYS use constant-time.

For full bcrypt/argon2 verify, the library handles this internally. Just call bcrypt.checkpw(input, stored).

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…