X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pygost%2Ftest_gost3413.py;h=d62f58680ccb431ecc3fe89491cf34e9cdc9037d;hb=fbaa1fc82dbec2c3ebaf8d272600ef4f91649e08;hp=d74f14525b6c7298a708dca8401149aede1e3120;hpb=9af4461c6af50f9cf83030867e7054d1f6311b32;p=pygost.git diff --git a/pygost/test_gost3413.py b/pygost/test_gost3413.py index d74f145..d62f586 100644 --- a/pygost/test_gost3413.py +++ b/pygost/test_gost3413.py @@ -1,6 +1,6 @@ # coding: utf-8 # PyGOST -- Pure Python GOST cryptographic functions library -# Copyright (C) 2015-2021 Sergey Matveev +# Copyright (C) 2015-2024 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 @@ -36,7 +36,9 @@ from pygost.gost3413 import mac 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 @@ -747,3 +749,18 @@ A8 1C 79 A0 4F 29 66 0E A3 FD A8 74 C6 30 79 9E ), 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)