]> Cypherpunks.ru repositories - pygost.git/commitdiff
Fixed incorrect digest calculation 5.12
authorSergey Matveev <stargrave@stargrave.org>
Wed, 12 Apr 2023 12:23:12 +0000 (15:23 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 12 Apr 2023 12:23:12 +0000 (15:23 +0300)
news.texi
pygost/__init__.py
pygost/gost3410.py
pygost/gost34112012.py
pygost/test_gost34112012.py

index ed7795dc2fdd3a9ca6fb2d46c626b9ece153de29..1dabeea1f461c607d1b44f6049eb86f1287159a8 100644 (file)
--- a/news.texi
+++ b/news.texi
@@ -3,6 +3,11 @@
 
 @table @strong
 
+@anchor{Release 5.12}
+@item 5.12
+Fixed incorrect digest calculation when using @code{GOST34112012*.update()}
+method.
+
 @anchor{Release 5.11}
 @item 5.11
 @code{gost34112012}'s @code{update()}/@code{digest()} methods are
index 54bee02b49c87621769e4740a73d59b85285db9f..c0695ad7d1b42bec17e338d31a0fe047bf643eee 100644 (file)
@@ -3,4 +3,4 @@
 PyGOST is free software: see the file COPYING for copying conditions.
 """
 
-__version__ = "5.11"
+__version__ = "5.12"
index 6e1bf845f9eb9e396ab82ab771e3a19eb8627a5a..cdb5b039eb1dd876604c74d4c63135721c1a3fd5 100644 (file)
@@ -55,6 +55,7 @@ class GOST3410Curve(object):
                       the twisted Edwards form
     :param str name: human-readable curve name
     """
+
     def __init__(self, p, q, a, b, x, y, cofactor=1, e=None, d=None, name=None):
         self.p = p
         self.q = q
index 64ed3b6de6fbfe4ba1209656cd521ccf18d31525..91782de66365658f6212ee4392e58205fec8b3d1 100644 (file)
@@ -268,8 +268,9 @@ class GOST34112012(PEP247):
         """Update state with the new data
         """
         if len(self.buf) > 0:
-            self.buf += data[:BLOCKSIZE - len(self.buf)]
-            data = data[BLOCKSIZE - len(self.buf):]
+            chunk_len = BLOCKSIZE - len(self.buf)
+            self.buf += data[:chunk_len]
+            data = data[chunk_len:]
             if len(self.buf) == BLOCKSIZE:
                 self._update_block(self.buf)
                 self.buf = b""
index fdec31af902c003065167b1460bfe55177f9b9db..c7c2df9220e4200200c53ccf8f7d52a175813ca5 100644 (file)
@@ -14,6 +14,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from os import urandom
+from random import randint
 from unittest import skip
 from unittest import TestCase
 import hmac
@@ -37,6 +39,20 @@ class TestCopy(TestCase):
         self.assertSequenceEqual(m.digest(), c.digest())
 
 
+class TestSymmetric(TestCase):
+    def runTest(self):
+        chunks = []
+        for _ in range(randint(1, 10)):
+            chunks.append(urandom(randint(20, 80)))
+        m = GOST34112012256()
+        for chunk in chunks:
+            m.update(chunk)
+        self.assertSequenceEqual(
+            m.hexdigest(),
+            GOST34112012256(b"".join(chunks)).hexdigest(),
+        )
+
+
 class TestHMAC(TestCase):
     """RFC 7836
     """