Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python/stdlib/hmac_timing_attack.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This example demostrates an insecure way of comparing a digest
# that exposes the code to a timing attack. This is because using
# equals operator on digest does not compare in constant time.
import hmac


Expand All @@ -8,6 +11,7 @@

key = b"my-secret-key"
password = b"pass"
digest = hmac.digest(key, password, digest="sha224")

Check warning on line 14 in python/stdlib/hmac_timing_attack.py

View check run for this annotation

Precaution / Precaution Unsubscribed

PY034: Inadequate Encryption Strength

The given key is only '13' bytes which is insufficient for the 'sha224' algorithm.

return digest == received_digest
if digest == received_digest:

Check failure on line 16 in python/stdlib/hmac_timing_attack.py

View check run for this annotation

Precaution / Precaution Unsubscribed

PY005: Observable Timing Discrepancy

Comparing digests with the '==' operator is vulnerable to timing attacks.
print("Authentication okay")
Loading