news.texi | 4 ++++ pygost/__init__.py | 2 +- pygost/mgm.py | 2 +- pygost/test_mgm.py | 33 ++++++++++++++++++++++----------- diff --git a/news.texi b/news.texi index 2da75d59226f18d95269e6fe55f4c8b9798768bc889b9ba2abddabebf081910d..4ddfbb8899b0b522936e5c72677dcf77683e846f93852468fbc8e18b68f5649c 100644 --- a/news.texi +++ b/news.texi @@ -3,6 +3,10 @@ @unnumbered News @table @strong +@anchor{Release 5.7} +@item 5.7 +Fixed MGM ignoring of the set tag size. + @anchor{Release 5.6} @item 5.6 Fixed lint errors for previous release. diff --git a/pygost/__init__.py b/pygost/__init__.py index 7f8e5d3a542dc697e328e0ed0b05a527977f7d3f6adc49215769efab4e171339..2aff94fa8cab3238f06864a162679ea936adb6eda1286bc55e762036f8ff5ecc 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.6" +__version__ = "5.7" diff --git a/pygost/mgm.py b/pygost/mgm.py index 35dd4f7efaa67907ab357d45b717d0adbe7d73628e1daa17dd9d27af86d1ceab..879f05184d02c8de78875208292c06ca423e652749036c3414b9bc508e32d758 100644 --- a/pygost/mgm.py +++ b/pygost/mgm.py @@ -58,7 +58,7 @@ (defaults to blocksize if not specified) """ if bs not in (8, 16): raise ValueError("Only 64/128-bit blocksizes allowed") - self.tag_size = bs if tag_size is None else bs + self.tag_size = bs if tag_size is None else tag_size if self.tag_size < 4 or self.tag_size > bs: raise ValueError("Invalid tag_size") self.encrypter = encrypter diff --git a/pygost/test_mgm.py b/pygost/test_mgm.py index 124449b6bdd670be2c9b43b7f974631962bf3820261355a49860a0a91f564dda..6762a411209096f3d783191311b1c8d736231cda961b705cae995e9cfb0daf95 100644 --- a/pygost/test_mgm.py +++ b/pygost/test_mgm.py @@ -39,7 +39,7 @@ self.assertSequenceEqual(mgm.open(plaintext[:16], ciphertext, ad), plaintext) class TestSymmetric(TestCase): - def _itself(self, mgm, bs): + def _itself(self, mgm, bs, tag_size): for _ in range(1000): nonce = nonce_prepare(urandom(bs)) ad = urandom(randint(0, 20)) @@ -47,18 +47,29 @@ pt = urandom(randint(0, 20)) if len(ad) + len(pt) == 0: continue ct = mgm.seal(nonce, pt, ad) + self.assertEqual(len(ct) - tag_size, len(pt)) self.assertSequenceEqual(mgm.open(nonce, ct, ad), pt) def test_magma(self): - mgm = MGM( - GOST3412Magma(urandom(KEYSIZE)).encrypt, - GOST3412Magma.blocksize, - ) - self._itself(mgm, GOST3412Magma.blocksize) + for tag_size in ( + GOST3412Magma.blocksize, + GOST3412Magma.blocksize - 2, + ): + mgm = MGM( + GOST3412Magma(urandom(KEYSIZE)).encrypt, + GOST3412Magma.blocksize, + tag_size, + ) + self._itself(mgm, GOST3412Magma.blocksize, tag_size) def test_kuznechik(self): - mgm = MGM( - GOST3412Kuznechik(urandom(KEYSIZE)).encrypt, - GOST3412Kuznechik.blocksize, - ) - self._itself(mgm, GOST3412Kuznechik.blocksize) + for tag_size in ( + GOST3412Kuznechik.blocksize, + GOST3412Kuznechik.blocksize - 2, + ): + mgm = MGM( + GOST3412Kuznechik(urandom(KEYSIZE)).encrypt, + GOST3412Kuznechik.blocksize, + tag_size, + ) + self._itself(mgm, GOST3412Kuznechik.blocksize, tag_size)