From: Sergey Matveev Date: Wed, 12 Apr 2023 12:23:12 +0000 (+0300) Subject: Fixed incorrect digest calculation X-Git-Tag: 5.12^0 X-Git-Url: http://www.git.cypherpunks.ru/?p=pygost.git;a=commitdiff_plain;h=63d5c5a81f29bfbb2e6eff3d8dc730a33ef80427 Fixed incorrect digest calculation --- diff --git a/news.texi b/news.texi index ed7795d..1dabeea 100644 --- 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 diff --git a/pygost/__init__.py b/pygost/__init__.py index 54bee02..c0695ad 100644 --- a/pygost/__init__.py +++ b/pygost/__init__.py @@ -3,4 +3,4 @@ PyGOST is free software: see the file COPYING for copying conditions. """ -__version__ = "5.11" +__version__ = "5.12" diff --git a/pygost/gost3410.py b/pygost/gost3410.py index 6e1bf84..cdb5b03 100644 --- a/pygost/gost3410.py +++ b/pygost/gost3410.py @@ -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 diff --git a/pygost/gost34112012.py b/pygost/gost34112012.py index 64ed3b6..91782de 100644 --- a/pygost/gost34112012.py +++ b/pygost/gost34112012.py @@ -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"" diff --git a/pygost/test_gost34112012.py b/pygost/test_gost34112012.py index fdec31a..c7c2df9 100644 --- a/pygost/test_gost34112012.py +++ b/pygost/test_gost34112012.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +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 """