# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
-# Copyright (C) 2015-2021 Sergey Matveev <stargrave@stargrave.org>
+# Copyright (C) 2015-2022 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
from pygost.gost3413 import mac_acpkm_master
from pygost.gost3413 import ofb
from pygost.gost3413 import pad2
+from pygost.gost3413 import pad_iso10126
from pygost.gost3413 import unpad2
+from pygost.gost3413 import unpad_iso10126
from pygost.utils import hexdec
from pygost.utils import hexenc
from pygost.utils import strxor
),
hexdec("FBB8DCEE45BEA67C35F58C5700898E5D"),
)
+
+
+class ISO10126Test(TestCase):
+ def test_symmetric(self):
+ for _ in range(100):
+ for blocksize in (GOST3412Magma.blocksize, GOST3412Kuznechik.blocksize):
+ data = urandom(randint(0, blocksize * 3))
+ padded = pad_iso10126(data, blocksize)
+ self.assertSequenceEqual(unpad_iso10126(padded, blocksize), data)
+ with self.assertRaises(ValueError):
+ unpad_iso10126(padded[1:], blocksize)
+
+ def test_small(self):
+ with self.assertRaises(ValueError):
+ unpad_iso10126(b"foobar\x00\x09", 8)