2 # PyGOST -- Pure Python GOST cryptographic functions library
3 # Copyright (C) 2015-2016 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.x509 import keypair_gen
22 from pygost.x509 import sign
23 from pygost.x509 import sign_digest
24 from pygost.x509 import verify
25 from pygost.x509 import verify_digest
26 from pygost.x509 import SIZE_3410_2001
27 from pygost.x509 import SIZE_3410_2012
30 class X5092001Test(TestCase):
31 def test_symmetric(self):
32 for _ in range(1 << 4):
33 prv, pub = keypair_gen(urandom(SIZE_3410_2001), mode=2001)
34 digest = urandom(SIZE_3410_2001)
35 self.assertTrue(verify_digest(
36 pub, digest, sign_digest(prv, digest, mode=2001), mode=2001
39 self.assertTrue(verify(
40 pub, data, sign(prv, data, mode=2001), mode=2001
44 class X5092012Test(TestCase):
45 def test_symmetric(self):
46 for _ in range(1 << 4):
47 prv, pub = keypair_gen(urandom(SIZE_3410_2012), mode=2012)
48 digest = urandom(SIZE_3410_2012)
49 self.assertTrue(verify_digest(
50 pub, digest, sign_digest(prv, digest, mode=2012), mode=2012,
53 self.assertTrue(verify(
54 pub, data, sign(prv, data, mode=2012), mode=2012,