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 unittest import TestCase
21 from pygost import gost3411_94
22 from pygost.gost3411_94 import GOST341194
25 class TestCopy(TestCase):
32 self.assertEqual(m.digest(), c.digest())
35 class TestHMACPEP247(TestCase):
37 h = hmac.new(b'foo', digestmod=gost3411_94)
42 class TestVectors(TestCase):
45 GOST341194(b'', "GostR3411_94_TestParamSet").hexdigest(),
46 "8d0f49492c91f45a68ff5c05d2c2b4ab78027b9aab5ce3feff5267c49cb985ce",
51 GOST341194(b'a', "GostR3411_94_TestParamSet").hexdigest(),
52 "dd14f362cefd49f873a5c644431b87219c3449661f808ac8e9667c369e532cd4",
57 GOST341194(b'abc', "GostR3411_94_TestParamSet").hexdigest(),
58 "1dd5a4067c49703b75bc75c9290f5ecbb5eb85229e7277a2b2b14fc4484313f3",
61 def test_message_digest(self):
63 GOST341194(b'message digest', "GostR3411_94_TestParamSet").hexdigest(),
64 "4d9a88a416de2fdb72de483f27652b5869243dec59be0cb6992c8fb1ec3444ad",
69 GOST341194(128 * b'U', "GostR3411_94_TestParamSet").hexdigest(),
70 "a43357fee8a926d9522a06870a66251c553e2774a0851d0cef0c1825eda3a353",
76 b'The quick brown fox jumps over the lazy dog',
77 "GostR3411_94_TestParamSet",
79 "94421f6d370fa1d16ba7ac5e31296529c968047dca9bf4258ac59a0c41fab777",
85 b'The quick brown fox jumps over the lazy cog',
86 "GostR3411_94_TestParamSet",
88 "45c4ee4ee1d25091312135540d6702e6677f7a73b5da31e10b8bb7aadac4eba3",
94 b'This is message, length=32 bytes',
95 "GostR3411_94_TestParamSet",
97 "faff37a615a816691cff3ef8b68ca247e09525f39f8119832eb81975d366c4b1",
100 def test_rfc50(self):
103 b'Suppose the original message has length = 50 bytes',
104 "GostR3411_94_TestParamSet",
106 "0852f5623b89dd57aeb4781fe54df14eeafbc1350613763a0d770aa657ba1a47",
110 class TestVectorsCryptoPro(TestCase):
111 """ CryptoPro S-box test vectors
113 def test_empty(self):
115 GOST341194(b'', "GostR3411_94_CryptoProParamSet").hexdigest(),
116 "c056d64c2383c44a58139c9b560111ac133e43fb840f838714840ca33c5f1e98",
121 GOST341194(b'a', "GostR3411_94_CryptoProParamSet").hexdigest(),
122 "1130402fcfaaf1ef3c13e3173f105a715580f7c97900af37bf832128dd524ce7",
127 GOST341194(b'abc', "GostR3411_94_CryptoProParamSet").hexdigest(),
128 "2cd42ff986293b167e994381ed59747414dd24953677762d39d718bf6d0585b2",
131 def test_message_digest(self):
135 "GostR3411_94_CryptoProParamSet",
137 "a01b72299bc39a540fd672a99a72b4bdfe74417386986efaeb01a42add4160bc",
143 b'The quick brown fox jumps over the lazy dog',
144 "GostR3411_94_CryptoProParamSet",
146 "760a8365d570476e787254761be7656774021b1f3de56f588c501a364a290490",
152 b'This is message, length=32 bytes',
153 "GostR3411_94_CryptoProParamSet",
155 "eb48de3e89e71bcb695fc752d617fae757f34fa77fa58ee114c5bdb7f7c2ef2c",
161 b'Suppose the original message has length = 50 bytes',
162 "GostR3411_94_CryptoProParamSet",
164 "1150a63031dc611a5f5e40d93153f74ebde8216f6792c25a91cfcabc5c0c73c3",
169 GOST341194(128 * b'U', "GostR3411_94_CryptoProParamSet").hexdigest(),
170 "e8c449f608104c512710cd37fded920df1e86b211623fa27f4bb914661c74a1c",