]> Cypherpunks.ru repositories - pygost.git/blobdiff - pygost/gost341194.py
Raise copyright years
[pygost.git] / pygost / gost341194.py
index adc0925f6e53e32cbbb909dfc978f9b08dd87530..4bcc60128c29a0f9496fefab83af3b45ac9e7f29 100644 (file)
@@ -1,6 +1,6 @@
 # coding: utf-8
 # PyGOST -- Pure Python GOST cryptographic functions library
-# Copyright (C) 2015-2016 Sergey Matveev <stargrave@stargrave.org>
+# Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@ taken according to specification's terminology.
 """
 
 from copy import copy
+from functools import partial
 from struct import pack
 
 from pygost.gost28147 import addmod
@@ -29,10 +30,11 @@ from pygost.gost28147 import encrypt
 from pygost.gost28147 import ns2block
 from pygost.gost28147 import validate_sbox
 from pygost.iface import PEP247
+from pygost.pbkdf2 import pbkdf2 as pbkdf2_base
 from pygost.utils import hexdec
 from pygost.utils import hexenc
 from pygost.utils import strxor
-from pygost.utils import xrange
+from pygost.utils import xrange  # pylint: disable=redefined-builtin
 
 
 DEFAULT_SBOX = "GostR3411_94_TestParamSet"
@@ -159,18 +161,18 @@ class GOST341194(PEP247):
     def digest(self):
         """ Get hash of the provided data
         """
-        l = 0
+        _len = 0
         checksum = 0
         h = 32 * b"\x00"
         m = self.data
         for i in xrange(0, len(m), BLOCKSIZE):
             part = m[i:i + BLOCKSIZE][::-1]
-            l += len(part) * 8
+            _len += len(part) * 8
             checksum = addmod(checksum, int(hexenc(part), 16), 2 ** 256)
             if len(part) < BLOCKSIZE:
                 part = b"\x00" * (BLOCKSIZE - len(part)) + part
             h = _step(h, part, self.sbox)
-        h = _step(h, 24 * b"\x00" + pack(">Q", l), self.sbox)
+        h = _step(h, 24 * b"\x00" + pack(">Q", _len), self.sbox)
 
         checksum = hex(checksum)[2:].rstrip("L")
         if len(checksum) % 2 != 0:
@@ -183,3 +185,10 @@ class GOST341194(PEP247):
 
 def new(data=b"", sbox=DEFAULT_SBOX):
     return GOST341194(data, sbox)
+
+
+PBKDF2_HASHER = partial(GOST341194, sbox="GostR3411_94_CryptoProParamSet")
+
+
+def pbkdf2(password, salt, iterations, dklen):
+    return pbkdf2_base(PBKDF2_HASHER, password, salt, iterations, dklen)