]> Cypherpunks.ru repositories - pygost.git/blob - pygost/test_kdf.py
8622a4212dfc34b1e5d4a679a6dc4f9d156412fb
[pygost.git] / pygost / test_kdf.py
1 # coding: utf-8
2 # PyGOST -- Pure Python GOST cryptographic functions library
3 # Copyright (C) 2015-2020 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, version 3 of the License.
8 #
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.
13 #
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/>.
16
17 from unittest import TestCase
18
19 from pygost.kdf import kdf_gostr3411_2012_256
20 from pygost.kdf import kdf_tree_gostr3411_2012_256
21 from pygost.utils import hexdec
22
23
24 class TestKDFGOSTR34112012256(TestCase):
25     def runTest(self):
26         self.assertEqual(
27             kdf_gostr3411_2012_256(
28                 hexdec("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"),
29                 hexdec("26bdb878"),
30                 hexdec("af21434145656378"),
31             ),
32             hexdec("a1aa5f7de402d7b3d323f2991c8d4534013137010a83754fd0af6d7cd4922ed9"),
33         )
34
35
36 class TestKDFTREEGOSTR34112012256(TestCase):
37     def runTest(self):
38         self.assertSequenceEqual(
39             kdf_tree_gostr3411_2012_256(
40                 hexdec("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"),
41                 hexdec("26bdb878"),
42                 hexdec("af21434145656378"),
43                 1,
44             ),
45             (hexdec("a1aa5f7de402d7b3d323f2991c8d4534013137010a83754fd0af6d7cd4922ed9"),),
46         )
47         self.assertSequenceEqual(
48             kdf_tree_gostr3411_2012_256(
49                 hexdec("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"),
50                 hexdec("26bdb878"),
51                 hexdec("af21434145656378"),
52                 2,
53             ),
54             (
55                 hexdec("22b6837845c6bef65ea71672b265831086d3c76aebe6dae91cad51d83f79d16b"),
56                 hexdec("074c9330599d7f8d712fca54392f4ddde93751206b3584c8f43f9e6dc51531f9"),
57             ),
58         )