]> Cypherpunks.ru repositories - pygost.git/blob - pygost/test_wrap.py
Raise copyright years
[pygost.git] / pygost / test_wrap.py
1 # coding: utf-8
2 # PyGOST -- Pure Python GOST cryptographic functions library
3 # Copyright (C) 2015-2018 Sergey Matveev <stargrave@stargrave.org>
4 #
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.
9 #
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.
14 #
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/>.
17
18 from os import urandom
19 from unittest import TestCase
20
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
25
26
27 class WrapGostTest(TestCase):
28     def test_symmetric(self):
29         for _ in range(1 << 8):
30             kek = urandom(32)
31             cek = urandom(32)
32             ukm = urandom(8)
33             wrapped = wrap_gost(ukm, kek, cek)
34             unwrapped = unwrap_gost(kek, wrapped)
35             self.assertEqual(unwrapped, cek)
36
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))
42
43
44 class WrapCryptoproTest(TestCase):
45     def test_symmetric(self):
46         for _ in range(1 << 8):
47             kek = urandom(32)
48             cek = urandom(32)
49             ukm = urandom(8)
50             wrapped = wrap_cryptopro(ukm, kek, cek)
51             unwrapped = unwrap_cryptopro(kek, wrapped)
52             self.assertEqual(unwrapped, cek)