mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
[1.6.x] Fixed #21138 -- Increased the performance of our PBKDF2 implementation.
Thanks go to Michael Gebetsroither for pointing out this issue and help on
the patch.
Backport of 68540fe4df from master.
This commit is contained in:
@@ -123,9 +123,8 @@ def _fast_hmac(key, msg, digest):
|
|||||||
This function operates on bytes.
|
This function operates on bytes.
|
||||||
"""
|
"""
|
||||||
dig1, dig2 = digest(), digest()
|
dig1, dig2 = digest(), digest()
|
||||||
if len(key) > dig1.block_size:
|
if len(key) != dig1.block_size:
|
||||||
key = digest(key).digest()
|
raise ValueError('Key size needs to match the block_size of the digest.')
|
||||||
key += b'\x00' * (dig1.block_size - len(key))
|
|
||||||
dig1.update(key.translate(hmac.trans_36))
|
dig1.update(key.translate(hmac.trans_36))
|
||||||
dig1.update(msg)
|
dig1.update(msg)
|
||||||
dig2.update(key.translate(hmac.trans_5C))
|
dig2.update(key.translate(hmac.trans_5C))
|
||||||
@@ -161,6 +160,11 @@ def pbkdf2(password, salt, iterations, dklen=0, digest=None):
|
|||||||
|
|
||||||
hex_format_string = "%%0%ix" % (hlen * 2)
|
hex_format_string = "%%0%ix" % (hlen * 2)
|
||||||
|
|
||||||
|
inner_digest_size = digest().block_size
|
||||||
|
if len(password) > inner_digest_size:
|
||||||
|
password = digest(password).digest()
|
||||||
|
password += b'\x00' * (inner_digest_size - len(password))
|
||||||
|
|
||||||
def F(i):
|
def F(i):
|
||||||
def U():
|
def U():
|
||||||
u = salt + struct.pack(b'>I', i)
|
u = salt + struct.pack(b'>I', i)
|
||||||
|
|||||||
Reference in New Issue
Block a user