X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pygost%2Ftest_mgm.py;h=e5065d23e8689c2dd8df6133ff5adaf9a9b61d70;hb=b8b853ca49a9dca40f446880fa809af51c611fe0;hp=903415826c7251cc932b4c1bea42c4eb6fbd0919;hpb=7e5fe8586c0f17834a8df558b7ca86c5d7accd3e;p=pygost.git diff --git a/pygost/test_mgm.py b/pygost/test_mgm.py index 9034158..e5065d2 100644 --- a/pygost/test_mgm.py +++ b/pygost/test_mgm.py @@ -1,6 +1,6 @@ # coding: utf-8 # PyGOST -- Pure Python GOST cryptographic functions library -# Copyright (C) 2015-2020 Sergey Matveev +# Copyright (C) 2015-2022 Sergey Matveev # # 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 @@ -39,7 +39,7 @@ class TestVector(TestCase): 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 @@ class TestSymmetric(TestCase): 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)