Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify (and very very slightly speed up) the pbkdf2 implementation

  • Loading branch information...
commit 8ecba51ea0e3a70a6cb0d823acc6f660007081dc 1 parent 9b95fa7
@alex alex authored
Showing with 12 additions and 12 deletions.
  1. +12 −12 django/utils/crypto.py
View
24 django/utils/crypto.py
@@ -152,15 +152,15 @@ def pbkdf2(password, salt, iterations, dklen=0, digest=None):
outer.update(password.translate(hmac.trans_5C))
def F(i):
- def U():
- u = salt + struct.pack(b'>I', i)
- for j in xrange(int(iterations)):
- dig1, dig2 = inner.copy(), outer.copy()
- dig1.update(u)
- dig2.update(dig1.digest())
- u = dig2.digest()
- yield _bin_to_long(u)
- return _long_to_bin(reduce(operator.xor, U()), hex_format_string)
-
- T = [F(x) for x in range(1, l + 1)]
- return b''.join(T[:-1]) + T[-1][:r]
+ u = salt + struct.pack(b'>I', i)
+ result = 0
+ for j in xrange(int(iterations)):
+ dig1, dig2 = inner.copy(), outer.copy()
+ dig1.update(u)
+ dig2.update(dig1.digest())
+ u = dig2.digest()
+ result ^= _bin_to_long(u)
+ return _long_to_bin(result, hex_format_string)
+
+ T = [F(x) for x in range(1, l)]
+ return b''.join(T) + F(l)[:r]
Please sign in to comment.
Something went wrong with that request. Please try again.