2 # PyGOST -- Pure Python GOST cryptographic functions library
3 # Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, version 3 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from os import urandom
18 from unittest import TestCase
20 from pygost.wrap import unwrap_cryptopro
21 from pygost.wrap import unwrap_gost
22 from pygost.wrap import wrap_cryptopro
23 from pygost.wrap import wrap_gost
26 class WrapGostTest(TestCase):
27 def test_symmetric(self):
28 for _ in range(1 << 8):
32 wrapped = wrap_gost(ukm, kek, cek)
33 unwrapped = unwrap_gost(kek, wrapped)
34 self.assertSequenceEqual(unwrapped, cek)
36 def test_invalid_length(self):
37 with self.assertRaises(ValueError):
38 unwrap_gost(urandom(32), urandom(41))
39 with self.assertRaises(ValueError):
40 unwrap_gost(urandom(32), urandom(45))
43 class WrapCryptoproTest(TestCase):
44 def test_symmetric(self):
45 for _ in range(1 << 8):
49 wrapped = wrap_cryptopro(ukm, kek, cek)
50 unwrapped = unwrap_cryptopro(kek, wrapped)
51 self.assertSequenceEqual(unwrapped, cek)