summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-03-17 22:14:14 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-03-18 09:45:44 +0100
commit7cf0f04230b1b6dd2680548338fe584c0ad3f85a (patch)
tree1177ba8bc06d7c71be06a9d336ecbe6418b26acd
parent20a91cce04c72bc8c64a1c43b7398edac7b709cc (diff)
Clarified that constant_time_compare doesn't protect string lengths.
-rw-r--r--django/utils/crypto.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/django/utils/crypto.py b/django/utils/crypto.py
index 94f717bb17..5d0f381ffa 100644
--- a/django/utils/crypto.py
+++ b/django/utils/crypto.py
@@ -85,6 +85,11 @@ def constant_time_compare(val1, val2):
Returns True if the two strings are equal, False otherwise.
The time taken is independent of the number of characters that match.
+
+ For the sake of simplicity, this function executes in constant time only
+ when the two strings have the same length. It short-circuits when they
+ have different lengths. Since Django only uses it to compare hashes of
+ known expected length, this is acceptable.
"""
if len(val1) != len(val2):
return False