news.texi | 5 +++++ pygost/__init__.py | 2 +- pygost/gost3410.py | 1 + pygost/gost34112012.py | 5 +++-- pygost/test_gost34112012.py | 16 ++++++++++++++++ diff --git a/news.texi b/news.texi index dbe4f8680df1e02347ffa129060f50259492b94578f4514db4aa4953e5b8e082..110503cd5e1bbc517f983e6fda843ea389281fe8d4da757bbbe825a552ac1a73 100644 --- a/news.texi +++ b/news.texi @@ -3,6 +3,11 @@ @unnumbered News @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 627cad094e6b33f9c44960db0244e5bb5318724a708d570d98090e7593d9a43e..032adc8b2e2c305420fd59ba7828193e9f85561ac7ebde32c5e3e982cf7f749d 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 bb41eb4916240d569d873cbe37a82f5eef40daabbeeaefbc7339f138dd64d224..c3c63a0f48e0c231bed9c768a85df14e5bcb9112f2ae3f53f45d1a9a50f93a2f 100644 --- a/pygost/gost3410.py +++ b/pygost/gost3410.py @@ -55,6 +55,7 @@ :param long e, d: coefficients of the equation of the elliptic curve in 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 decd962e1b6608520c95d008d6a18e587e4877a97ae3bbbfb049e0b913027f27..caa6556e2cf86d4befec228b3c3d9127146d26a899490cdf3d2efc52eac87a72 100644 --- a/pygost/gost34112012.py +++ b/pygost/gost34112012.py @@ -268,8 +268,9 @@ def update(self, data): """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 05a7113561f9b1021ca2f6616ac92bb0fb32f86a68f8b9e47d8dd4de37b76072..11843dad8224749eaba7633c315b62c954608ed1d9a1412edad1136df41cae47 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 @@ -35,6 +37,20 @@ m.update(b"foobar") c.update(b"foo") c.update(b"bar") 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):