2 """ PBKDF2 implementation suitable for GOST R 34.11-94/34.11-2012.
4 This implementation is based on Python 3.5.2 source code's one.
5 PyGOST does not register itself in hashlib anyway, so use it instead.
9 from pygost.utils import bytes2long
10 from pygost.utils import long2bytes
11 from pygost.utils import strxor
12 from pygost.utils import xrange # pylint: disable=redefined-builtin
15 def pbkdf2(hasher, password, salt, iterations, dklen):
16 """PBKDF2 implementation suitable for GOST R 34.11-94/34.11-2012
20 password = password + b"\x00" * (inner.block_size - len(password))
21 inner.update(strxor(password, len(password) * b"\x36"))
22 outer.update(strxor(password, len(password) * b"\x5C"))
28 ocpy.update(icpy.digest())
33 while len(dkey) < dklen:
34 prev = prf(salt + long2bytes(loop, 4))
35 rkey = bytes2long(prev)
36 for _ in xrange(iterations - 1):
38 rkey ^= bytes2long(prev)
40 dkey += long2bytes(rkey, inner.digest_size)