2 # PyGOST -- Pure Python GOST cryptographic functions library
3 # Copyright (C) 2015-2019 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, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 from os import urandom
19 from unittest import TestCase
21 from pygost.wrap import unwrap_cryptopro
22 from pygost.wrap import unwrap_gost
23 from pygost.wrap import wrap_cryptopro
24 from pygost.wrap import wrap_gost
27 class WrapGostTest(TestCase):
28 def test_symmetric(self):
29 for _ in range(1 << 8):
33 wrapped = wrap_gost(ukm, kek, cek)
34 unwrapped = unwrap_gost(kek, wrapped)
35 self.assertSequenceEqual(unwrapped, cek)
37 def test_invalid_length(self):
38 with self.assertRaises(ValueError):
39 unwrap_gost(urandom(32), urandom(41))
40 with self.assertRaises(ValueError):
41 unwrap_gost(urandom(32), urandom(45))
44 class WrapCryptoproTest(TestCase):
45 def test_symmetric(self):
46 for _ in range(1 << 8):
50 wrapped = wrap_cryptopro(ukm, kek, cek)
51 unwrapped = unwrap_cryptopro(kek, wrapped)
52 self.assertSequenceEqual(unwrapped, cek)