Merge pull request #1321 from ShySec/master
fixed timing attack in gluon.utils.compare
This commit is contained in:
+3
-5
@@ -83,11 +83,9 @@ def compare(a, b):
|
|||||||
""" Compares two strings and not vulnerable to timing attacks """
|
""" Compares two strings and not vulnerable to timing attacks """
|
||||||
if HAVE_COMPARE_DIGEST:
|
if HAVE_COMPARE_DIGEST:
|
||||||
return hmac.compare_digest(a, b)
|
return hmac.compare_digest(a, b)
|
||||||
if len(a) != len(b):
|
result = len(a) ^ len(b)
|
||||||
return False
|
for i in xrange(len(b)):
|
||||||
result = 0
|
result |= ord(a[i%len(a)]) ^ ord(b[i])
|
||||||
for x, y in zip(a, b):
|
|
||||||
result |= ord(x) ^ ord(y)
|
|
||||||
return result == 0
|
return result == 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user