# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
-# Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
+# Copyright (C) 2015-2024 Sergey Matveev <stargrave@stargrave.org>
#
# 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
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))
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)