]> Cypherpunks.ru repositories - pygost.git/blob - pygost/test_gost28147_mac.py
Unify docstring's leading space presence
[pygost.git] / pygost / test_gost28147_mac.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.gost28147_mac import MAC
20
21
22 class TestMAC(TestCase):
23     """Test vectors generated with libgcl3 library
24     """
25     k = b"This is message\xFF length\x0032 bytes"
26
27     def test_a(self):
28         self.assertSequenceEqual(
29             MAC(self.k, b"a").hexdigest(),
30             "bd5d3b5b2b7b57af",
31         )
32
33     def test_abc(self):
34         self.assertSequenceEqual(
35             MAC(self.k, b"abc").hexdigest(),
36             "28661e40805b1ff9",
37         )
38
39     def test_128U(self):
40         self.assertSequenceEqual(
41             MAC(self.k, 128 * b"U").hexdigest(),
42             "1a06d1bad74580ef",
43         )
44
45     def test_13x(self):
46         self.assertSequenceEqual(
47             MAC(self.k, 13 * b"x").hexdigest(),
48             "917ee1f1a668fbd3",
49         )
50
51     def test_parts(self):
52         m = MAC(self.k)
53         m.update(b"foo")
54         m.update(b"bar")
55         self.assertSequenceEqual(m.digest(), MAC(self.k, b"foobar").digest())
56
57     def test_copy(self):
58         m = MAC(self.k, b"foo")
59         c = m.copy()
60         m.update(b"barbaz")
61         c.update(b"bar")
62         c.update(b"baz")
63         self.assertSequenceEqual(m.digest(), c.digest())