blob: 4673b49ef706cef51d2da67da71afa296b57f962 [file] [log] [blame]
Alex Gaynorf312a5c2013-08-10 15:23:38 -04001# Licensed under the Apache License, Version 2.0 (the "License");
2# you may not use this file except in compliance with the License.
3# You may obtain a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS,
9# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10# implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
Alex Gaynorc37feed2014-03-08 08:32:56 -080014from __future__ import absolute_import, division, print_function
15
Alex Stapletonfb812d62014-04-15 16:07:25 +010016import binascii
Alex Gaynorab53bc52013-11-12 09:37:59 -080017import os
Donald Stufft9e1a48b2013-08-09 00:32:30 -040018import textwrap
19
Alex Gaynor2b3f9422013-12-24 21:55:24 -080020import pretend
21
Paul Kehrer79c16e92013-10-18 17:44:36 -050022import pytest
23
Alex Stapletona39a3192014-03-14 20:03:12 +000024import cryptography
Alex Stapleton112963e2014-03-26 17:39:29 +000025from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
26
Alex Stapletona39a3192014-03-14 20:03:12 +000027import cryptography_vectors
28
Alex Gaynorafdddca2013-10-21 21:00:20 -070029from .utils import (
Paul Kehrer14951f42014-04-30 12:14:48 -050030 check_backend_support, check_for_iface, der_encode_dsa_signature,
Paul Kehrer3fc686e2014-04-30 09:07:27 -050031 load_cryptrec_vectors, load_fips_dsa_key_pair_vectors,
32 load_fips_dsa_sig_vectors, load_fips_ecdsa_key_pair_vectors,
33 load_fips_ecdsa_signing_vectors, load_hash_vectors, load_nist_vectors,
34 load_pkcs1_vectors, load_rsa_nist_vectors, load_vectors_from_file,
Alex Stapleton112963e2014-03-26 17:39:29 +000035 raises_unsupported_algorithm, select_backends
Alex Gaynorafdddca2013-10-21 21:00:20 -070036)
Donald Stufft9e1a48b2013-08-09 00:32:30 -040037
38
Alex Gaynor2b3f9422013-12-24 21:55:24 -080039class FakeInterface(object):
40 pass
41
42
Paul Kehrerc421e632014-01-18 09:22:21 -060043def test_select_one_backend():
Paul Kehrer34c075e2014-01-13 21:52:08 -050044 b1 = pretend.stub(name="b1")
45 b2 = pretend.stub(name="b2")
46 b3 = pretend.stub(name="b3")
47 backends = [b1, b2, b3]
48 name = "b2"
Paul Kehreraed9e172014-01-19 12:09:27 -060049 selected_backends = select_backends(name, backends)
50 assert len(selected_backends) == 1
51 assert selected_backends[0] == b2
Paul Kehrer34c075e2014-01-13 21:52:08 -050052
53
Paul Kehrerc421e632014-01-18 09:22:21 -060054def test_select_no_backend():
Paul Kehrer34c075e2014-01-13 21:52:08 -050055 b1 = pretend.stub(name="b1")
56 b2 = pretend.stub(name="b2")
57 b3 = pretend.stub(name="b3")
58 backends = [b1, b2, b3]
59 name = "back!"
60 with pytest.raises(ValueError):
Paul Kehrerc421e632014-01-18 09:22:21 -060061 select_backends(name, backends)
62
63
64def test_select_backends_none():
65 b1 = pretend.stub(name="b1")
66 b2 = pretend.stub(name="b2")
67 b3 = pretend.stub(name="b3")
68 backends = [b1, b2, b3]
69 name = None
Paul Kehreraed9e172014-01-19 12:09:27 -060070 selected_backends = select_backends(name, backends)
71 assert len(selected_backends) == 3
Paul Kehrerc421e632014-01-18 09:22:21 -060072
73
74def test_select_two_backends():
75 b1 = pretend.stub(name="b1")
76 b2 = pretend.stub(name="b2")
77 b3 = pretend.stub(name="b3")
78 backends = [b1, b2, b3]
79 name = "b2 ,b1 "
Paul Kehreraed9e172014-01-19 12:09:27 -060080 selected_backends = select_backends(name, backends)
81 assert len(selected_backends) == 2
82 assert selected_backends == [b1, b2]
Paul Kehrer34c075e2014-01-13 21:52:08 -050083
84
Alex Gaynor2b3f9422013-12-24 21:55:24 -080085def test_check_for_iface():
86 item = pretend.stub(keywords=["fake_name"], funcargs={"backend": True})
87 with pytest.raises(pytest.skip.Exception) as exc_info:
88 check_for_iface("fake_name", FakeInterface, item)
89 assert exc_info.value.args[0] == "True backend does not support fake_name"
90
91 item = pretend.stub(
92 keywords=["fake_name"],
93 funcargs={"backend": FakeInterface()}
94 )
95 check_for_iface("fake_name", FakeInterface, item)
96
97
Paul Kehrer60fc8da2013-12-26 20:19:34 -060098def test_check_backend_support_skip():
Paul Kehrer5a8fdf82013-12-26 20:13:45 -060099 supported = pretend.stub(
100 kwargs={"only_if": lambda backend: False, "skip_message": "Nope"}
101 )
102 item = pretend.stub(keywords={"supported": supported},
103 funcargs={"backend": True})
104 with pytest.raises(pytest.skip.Exception) as exc_info:
Paul Kehrer60fc8da2013-12-26 20:19:34 -0600105 check_backend_support(item)
Paul Kehrerf03334e2014-01-02 23:16:14 -0600106 assert exc_info.value.args[0] == "Nope (True)"
Paul Kehrer5a8fdf82013-12-26 20:13:45 -0600107
108
Paul Kehrer60fc8da2013-12-26 20:19:34 -0600109def test_check_backend_support_no_skip():
Paul Kehrer5a8fdf82013-12-26 20:13:45 -0600110 supported = pretend.stub(
111 kwargs={"only_if": lambda backend: True, "skip_message": "Nope"}
112 )
113 item = pretend.stub(keywords={"supported": supported},
114 funcargs={"backend": True})
Paul Kehrer60fc8da2013-12-26 20:19:34 -0600115 assert check_backend_support(item) is None
Paul Kehrer5a8fdf82013-12-26 20:13:45 -0600116
117
Paul Kehrer60fc8da2013-12-26 20:19:34 -0600118def test_check_backend_support_no_backend():
Paul Kehrer5a8fdf82013-12-26 20:13:45 -0600119 supported = pretend.stub(
120 kwargs={"only_if": "notalambda", "skip_message": "Nope"}
121 )
122 item = pretend.stub(keywords={"supported": supported},
123 funcargs={})
Paul Kehrerec495502013-12-27 15:51:40 -0600124 with pytest.raises(ValueError):
Paul Kehrer60fc8da2013-12-26 20:19:34 -0600125 check_backend_support(item)
Paul Kehrer5a8fdf82013-12-26 20:13:45 -0600126
127
Paul Kehrer14951f42014-04-30 12:14:48 -0500128def test_der_encode_dsa_signature_values():
129 sig = der_encode_dsa_signature(1, 1)
Paul Kehrer3fc686e2014-04-30 09:07:27 -0500130 assert sig == b"0\x06\x02\x01\x01\x02\x01\x01"
131
Paul Kehrer14951f42014-04-30 12:14:48 -0500132 sig2 = der_encode_dsa_signature(
133 1037234182290683143945502320610861668562885151617,
134 559776156650501990899426031439030258256861634312
135 )
Paul Kehrer3fc686e2014-04-30 09:07:27 -0500136 assert sig2 == (
137 b'0-\x02\x15\x00\xb5\xaf0xg\xfb\x8bT9\x00\x13\xccg\x02\r\xdf\x1f,\x0b'
138 b'\x81\x02\x14b\r;"\xabP1D\x0c>5\xea\xb6\xf4\x81)\x8f\x9e\x9f\x08'
139 )
140
Paul Kehrer14951f42014-04-30 12:14:48 -0500141 sig3 = der_encode_dsa_signature(0, 0)
Paul Kehrer3fc686e2014-04-30 09:07:27 -0500142 assert sig3 == b"0\x06\x02\x01\x00\x02\x01\x00"
143
Paul Kehrerbe8ce552014-04-30 14:12:26 -0500144 sig4 = der_encode_dsa_signature(-1, 0)
145 assert sig4 == b"0\x06\x02\x01\xFF\x02\x01\x00"
146
Paul Kehrer3fc686e2014-04-30 09:07:27 -0500147
Alex Gaynorcf5fb332013-11-11 15:39:52 -0800148def test_load_nist_vectors():
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400149 vector_data = textwrap.dedent("""
150 # CAVS 11.1
151 # Config info for aes_values
152 # AESVS GFSbox test data for CBC
153 # State : Encrypt and Decrypt
154 # Key Length : 128
155 # Generated on Fri Apr 22 15:11:33 2011
156
157 [ENCRYPT]
158
159 COUNT = 0
160 KEY = 00000000000000000000000000000000
161 IV = 00000000000000000000000000000000
162 PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6
163 CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e
164
165 COUNT = 1
166 KEY = 00000000000000000000000000000000
167 IV = 00000000000000000000000000000000
168 PLAINTEXT = 9798c4640bad75c7c3227db910174e72
169 CIPHERTEXT = a9a1631bf4996954ebc093957b234589
170
171 [DECRYPT]
172
173 COUNT = 0
174 KEY = 00000000000000000000000000000000
175 IV = 00000000000000000000000000000000
176 CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e
177 PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6
178
179 COUNT = 1
180 KEY = 00000000000000000000000000000000
181 IV = 00000000000000000000000000000000
182 CIPHERTEXT = a9a1631bf4996954ebc093957b234589
183 PLAINTEXT = 9798c4640bad75c7c3227db910174e72
184 """).splitlines()
185
Alex Gaynord3ce7032013-11-11 14:46:20 -0800186 assert load_nist_vectors(vector_data) == [
187 {
188 "key": b"00000000000000000000000000000000",
189 "iv": b"00000000000000000000000000000000",
190 "plaintext": b"f34481ec3cc627bacd5dc3fb08f273e6",
191 "ciphertext": b"0336763e966d92595a567cc9ce537f5e",
192 },
193 {
194 "key": b"00000000000000000000000000000000",
195 "iv": b"00000000000000000000000000000000",
196 "plaintext": b"9798c4640bad75c7c3227db910174e72",
197 "ciphertext": b"a9a1631bf4996954ebc093957b234589",
198 },
Alex Gaynor1fe70b12013-10-16 11:59:17 -0700199 {
200 "key": b"00000000000000000000000000000000",
201 "iv": b"00000000000000000000000000000000",
202 "plaintext": b"f34481ec3cc627bacd5dc3fb08f273e6",
203 "ciphertext": b"0336763e966d92595a567cc9ce537f5e",
204 },
205 {
206 "key": b"00000000000000000000000000000000",
207 "iv": b"00000000000000000000000000000000",
208 "plaintext": b"9798c4640bad75c7c3227db910174e72",
209 "ciphertext": b"a9a1631bf4996954ebc093957b234589",
210 },
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400211 ]
212
213
Paul Kehrer6fb1a5a2014-01-29 13:44:07 -0600214def test_load_nist_vectors_with_null_chars():
215 vector_data = textwrap.dedent("""
216 COUNT = 0
217 KEY = thing\\0withnulls
218
219 COUNT = 1
220 KEY = 00000000000000000000000000000000
221 """).splitlines()
222
223 assert load_nist_vectors(vector_data) == [
224 {
225 "key": b"thing\x00withnulls",
226 },
227 {
228 "key": b"00000000000000000000000000000000",
229 },
230 ]
231
232
Paul Kehrer1951bf62013-09-15 12:05:43 -0500233def test_load_cryptrec_vectors():
234 vector_data = textwrap.dedent("""
235 # Vectors taken from http://info.isl.ntt.co.jp/crypt/eng/camellia/
236 # Download is t_camelia.txt
237
238 # Camellia with 128-bit key
239
240 K No.001 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
241
242 P No.001 : 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
243 C No.001 : 07 92 3A 39 EB 0A 81 7D 1C 4D 87 BD B8 2D 1F 1C
244
245 P No.002 : 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
246 C No.002 : 48 CD 64 19 80 96 72 D2 34 92 60 D8 9A 08 D3 D3
247
248 K No.002 : 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
249
250 P No.001 : 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
251 C No.001 : 07 92 3A 39 EB 0A 81 7D 1C 4D 87 BD B8 2D 1F 1C
252 """).splitlines()
253
254 assert load_cryptrec_vectors(vector_data) == [
Alex Gaynor1fe70b12013-10-16 11:59:17 -0700255 {
256 "key": b"00000000000000000000000000000000",
257 "plaintext": b"80000000000000000000000000000000",
258 "ciphertext": b"07923A39EB0A817D1C4D87BDB82D1F1C",
259 },
260 {
261 "key": b"00000000000000000000000000000000",
262 "plaintext": b"40000000000000000000000000000000",
263 "ciphertext": b"48CD6419809672D2349260D89A08D3D3",
264 },
265 {
266 "key": b"10000000000000000000000000000000",
267 "plaintext": b"80000000000000000000000000000000",
268 "ciphertext": b"07923A39EB0A817D1C4D87BDB82D1F1C",
269 },
Paul Kehrer1951bf62013-09-15 12:05:43 -0500270 ]
271
272
Donald Stufft3359d7e2013-10-19 19:33:06 -0400273def test_load_cryptrec_vectors_invalid():
274 vector_data = textwrap.dedent("""
275 # Vectors taken from http://info.isl.ntt.co.jp/crypt/eng/camellia/
276 # Download is t_camelia.txt
277
278 # Camellia with 128-bit key
279
280 E No.001 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
281 """).splitlines()
282
283 with pytest.raises(ValueError):
284 load_cryptrec_vectors(vector_data)
285
286
Paul Kehrer69e06522013-10-18 17:28:39 -0500287def test_load_hash_vectors():
288 vector_data = textwrap.dedent("""
289
290 # http://tools.ietf.org/html/rfc1321
Paul Kehrer87cd0db2013-10-18 18:01:26 -0500291 [irrelevant]
Paul Kehrer69e06522013-10-18 17:28:39 -0500292
293 Len = 0
294 Msg = 00
295 MD = d41d8cd98f00b204e9800998ecf8427e
296
297 Len = 8
298 Msg = 61
299 MD = 0cc175b9c0f1b6a831c399e269772661
300
301 Len = 24
302 Msg = 616263
303 MD = 900150983cd24fb0d6963f7d28e17f72
304
305 Len = 112
306 Msg = 6d65737361676520646967657374
307 MD = f96b697d7cb7938d525a2f31aaf161d0
308 """).splitlines()
309 assert load_hash_vectors(vector_data) == [
Paul Kehrer79c16e92013-10-18 17:44:36 -0500310 (b"", "d41d8cd98f00b204e9800998ecf8427e"),
311 (b"61", "0cc175b9c0f1b6a831c399e269772661"),
312 (b"616263", "900150983cd24fb0d6963f7d28e17f72"),
313 (b"6d65737361676520646967657374", "f96b697d7cb7938d525a2f31aaf161d0"),
Paul Kehrer69e06522013-10-18 17:28:39 -0500314 ]
315
316
Paul Kehrer0317b042013-10-28 17:34:27 -0500317def test_load_hmac_vectors():
318 vector_data = textwrap.dedent("""
319Len = 224
320# "Jefe"
321Key = 4a656665
322# "what do ya want for nothing?"
323Msg = 7768617420646f2079612077616e7420666f72206e6f7468696e673f
324MD = 750c783e6ab0b503eaa86e310a5db738
325 """).splitlines()
326 assert load_hash_vectors(vector_data) == [
327 (b"7768617420646f2079612077616e7420666f72206e6f7468696e673f",
328 "750c783e6ab0b503eaa86e310a5db738",
329 b"4a656665"),
330 ]
331
332
Paul Kehrer69e06522013-10-18 17:28:39 -0500333def test_load_hash_vectors_bad_data():
334 vector_data = textwrap.dedent("""
335 # http://tools.ietf.org/html/rfc1321
336
337 Len = 0
338 Msg = 00
339 UNKNOWN=Hello World
340 """).splitlines()
341 with pytest.raises(ValueError):
342 load_hash_vectors(vector_data)
343
Alex Gaynor41172ab2013-11-12 10:00:42 -0800344
Alex Gaynorab53bc52013-11-12 09:37:59 -0800345def test_load_vectors_from_file():
346 vectors = load_vectors_from_file(
347 os.path.join("ciphers", "Blowfish", "bf-cfb.txt"),
348 load_nist_vectors,
Paul Kehrer2b758672013-10-30 09:01:38 -0500349 )
Alex Gaynorab53bc52013-11-12 09:37:59 -0800350 assert vectors == [
351 {
Alex Gaynorc2f45d52013-11-12 09:50:25 -0800352 "key": b"0123456789ABCDEFF0E1D2C3B4A59687",
353 "iv": b"FEDCBA9876543210",
Alex Gaynorab53bc52013-11-12 09:37:59 -0800354 "plaintext": (
Alex Gaynorc2f45d52013-11-12 09:50:25 -0800355 b"37363534333231204E6F77206973207468652074696D6520666F722000"
Alex Gaynorab53bc52013-11-12 09:37:59 -0800356 ),
357 "ciphertext": (
Alex Gaynorc2f45d52013-11-12 09:50:25 -0800358 b"E73214A2822139CAF26ECF6D2EB9E76E3DA3DE04D1517200519D57A6C3"
Alex Gaynorab53bc52013-11-12 09:37:59 -0800359 ),
360 }
361 ]
Paul Kehrera43b6692013-11-12 15:35:49 -0600362
363
364def test_load_nist_gcm_vectors():
365 vector_data = textwrap.dedent("""
366 [Keylen = 128]
367 [IVlen = 96]
368 [PTlen = 0]
369 [AADlen = 0]
370 [Taglen = 128]
371
372 Count = 0
373 Key = 11754cd72aec309bf52f7687212e8957
374 IV = 3c819d9a9bed087615030b65
375 PT =
376 AAD =
377 CT =
378 Tag = 250327c674aaf477aef2675748cf6971
379
380 Count = 1
381 Key = 272f16edb81a7abbea887357a58c1917
382 IV = 794ec588176c703d3d2a7a07
383 PT =
384 AAD =
385 CT =
386 Tag = b6e6f197168f5049aeda32dafbdaeb
387
388 Count = 2
389 Key = a49a5e26a2f8cb63d05546c2a62f5343
390 IV = 907763b19b9b4ab6bd4f0281
391 CT =
392 AAD =
393 Tag = a2be08210d8c470a8df6e8fbd79ec5cf
394 FAIL
395
396 Count = 3
397 Key = 5c1155084cc0ede76b3bc22e9f7574ef
398 IV = 9549e4ba69a61cad7856efc1
399 PT = d1448fa852b84408e2dad8381f363de7
400 AAD = e98e9d9c618e46fef32660976f854ee3
401 CT = f78b60ca125218493bea1c50a2e12ef4
402 Tag = d72da7f5c6cf0bca7242c71835809449
403
404 [Keylen = 128]
405 [IVlen = 96]
406 [PTlen = 0]
407 [AADlen = 0]
408 [Taglen = 120]
409
410 Count = 0
411 Key = eac258e99c55e6ae8ef1da26640613d7
412 IV = 4e8df20faaf2c8eebe922902
413 CT =
414 AAD =
415 Tag = e39aeaebe86aa309a4d062d6274339
416 PT =
417
418 Count = 1
419 Key = 3726cf02fcc6b8639a5497652c94350d
420 IV = 55fef82cde693ce76efcc193
421 CT =
422 AAD =
423 Tag = 3d68111a81ed22d2ef5bccac4fc27f
424 FAIL
425
426 Count = 2
427 Key = f202299d5fd74f03b12d2119a6c4c038
428 IV = eec51e7958c3f20a1bb71815
429 CT =
430 AAD =
431 Tag = a81886b3fb26e51fca87b267e1e157
432 FAIL
433
434 Count = 3
435 Key = fd52925f39546b4c55ffb6b20c59898c
436 IV = f5cf3227444afd905a5f6dba
437 CT =
438 AAD =
439 Tag = 1665b0f1a0b456e1664cfd3de08ccd
440 PT =
Paul Kehrerc985dbb2013-11-18 14:11:55 -0600441
442 [Keylen = 128]
443 [IVlen = 8]
444 [PTlen = 104]
445 [AADlen = 0]
446 [Taglen = 128]
447
448 Count = 0
449 Key = 58fab7632bcf10d2bcee58520bf37414
450 IV = 3c
451 CT = 15c4db4cbb451211179d57017f
452 AAD =
453 Tag = eae841d4355feeb3f786bc86625f1e5b
454 FAIL
Paul Kehrera43b6692013-11-12 15:35:49 -0600455 """).splitlines()
456 assert load_nist_vectors(vector_data) == [
457 {'aad': b'',
Paul Kehrer749ac5b2013-11-18 18:12:41 -0600458 'pt': b'',
459 'iv': b'3c819d9a9bed087615030b65',
460 'tag': b'250327c674aaf477aef2675748cf6971',
461 'key': b'11754cd72aec309bf52f7687212e8957',
462 'ct': b''},
463 {'aad': b'',
464 'pt': b'',
465 'iv': b'794ec588176c703d3d2a7a07',
466 'tag': b'b6e6f197168f5049aeda32dafbdaeb',
467 'key': b'272f16edb81a7abbea887357a58c1917',
468 'ct': b''},
469 {'aad': b'',
470 'iv': b'907763b19b9b4ab6bd4f0281',
471 'tag': b'a2be08210d8c470a8df6e8fbd79ec5cf',
472 'key': b'a49a5e26a2f8cb63d05546c2a62f5343',
473 'ct': b'',
Paul Kehrerc985dbb2013-11-18 14:11:55 -0600474 'fail': True},
Paul Kehrer749ac5b2013-11-18 18:12:41 -0600475 {'aad': b'e98e9d9c618e46fef32660976f854ee3',
476 'pt': b'd1448fa852b84408e2dad8381f363de7',
477 'iv': b'9549e4ba69a61cad7856efc1',
478 'tag': b'd72da7f5c6cf0bca7242c71835809449',
479 'key': b'5c1155084cc0ede76b3bc22e9f7574ef',
480 'ct': b'f78b60ca125218493bea1c50a2e12ef4'},
Paul Kehrerc985dbb2013-11-18 14:11:55 -0600481 {'aad': b'',
Paul Kehrera43b6692013-11-12 15:35:49 -0600482 'pt': b'',
483 'iv': b'4e8df20faaf2c8eebe922902',
484 'tag': b'e39aeaebe86aa309a4d062d6274339',
485 'key': b'eac258e99c55e6ae8ef1da26640613d7',
486 'ct': b''},
487 {'aad': b'',
488 'iv': b'55fef82cde693ce76efcc193',
489 'tag': b'3d68111a81ed22d2ef5bccac4fc27f',
490 'key': b'3726cf02fcc6b8639a5497652c94350d',
491 'ct': b'',
492 'fail': True},
493 {'aad': b'',
494 'iv': b'eec51e7958c3f20a1bb71815',
495 'tag': b'a81886b3fb26e51fca87b267e1e157',
496 'key': b'f202299d5fd74f03b12d2119a6c4c038',
497 'ct': b'',
498 'fail': True},
499 {'aad': b'',
500 'pt': b'',
501 'iv': b'f5cf3227444afd905a5f6dba',
502 'tag': b'1665b0f1a0b456e1664cfd3de08ccd',
503 'key': b'fd52925f39546b4c55ffb6b20c59898c',
504 'ct': b''},
505 {'aad': b'',
Paul Kehrer749ac5b2013-11-18 18:12:41 -0600506 'iv': b'3c',
507 'tag': b'eae841d4355feeb3f786bc86625f1e5b',
508 'key': b'58fab7632bcf10d2bcee58520bf37414',
509 'ct': b'15c4db4cbb451211179d57017f',
Paul Kehrera43b6692013-11-12 15:35:49 -0600510 'fail': True},
Paul Kehrera43b6692013-11-12 15:35:49 -0600511 ]
Alex Stapleton58f27ac2014-02-02 19:30:03 +0000512
513
514def test_load_pkcs1_vectors():
515 vector_data = textwrap.dedent("""
516 Test vectors for RSA-PSS
517 ========================
518
519 This file contains an extract of the original pss-vect.txt
520
521 Key lengths:
522
523 Key 8: 1031 bits
524 Key 9: 1536 bits
525 ===========================================================================
526
527 <snip>
528
529 # Example 8: A 1031-bit RSA key pair
530 # -----------------------------------
531
532
533 # Public key
534 # ----------
535
536 # Modulus:
537 49 53 70 a1 fb 18 54 3c 16 d3 63 1e 31 63 25 5d
538 f6 2b e6 ee e8 90 d5 f2 55 09 e4 f7 78 a8 ea 6f
539 bb bc df 85 df f6 4e 0d 97 20 03 ab 36 81 fb ba
540 6d d4 1f d5 41 82 9b 2e 58 2d e9 f2 a4 a4 e0 a2
541 d0 90 0b ef 47 53 db 3c ee 0e e0 6c 7d fa e8 b1
542 d5 3b 59 53 21 8f 9c ce ea 69 5b 08 66 8e de aa
543 dc ed 94 63 b1 d7 90 d5 eb f2 7e 91 15 b4 6c ad
544 4d 9a 2b 8e fa b0 56 1b 08 10 34 47 39 ad a0 73
545 3f
546
547 # Exponent:
548 01 00 01
549
550 # Private key
551 # -----------
552
553 # Modulus:
554 49 53 70 a1 fb 18 54 3c 16 d3 63 1e 31 63 25 5d
555 f6 2b e6 ee e8 90 d5 f2 55 09 e4 f7 78 a8 ea 6f
556 bb bc df 85 df f6 4e 0d 97 20 03 ab 36 81 fb ba
557 6d d4 1f d5 41 82 9b 2e 58 2d e9 f2 a4 a4 e0 a2
558 d0 90 0b ef 47 53 db 3c ee 0e e0 6c 7d fa e8 b1
559 d5 3b 59 53 21 8f 9c ce ea 69 5b 08 66 8e de aa
560 dc ed 94 63 b1 d7 90 d5 eb f2 7e 91 15 b4 6c ad
561 4d 9a 2b 8e fa b0 56 1b 08 10 34 47 39 ad a0 73
562 3f
563
564 # Public exponent:
565 01 00 01
566
567 # Exponent:
568 6c 66 ff e9 89 80 c3 8f cd ea b5 15 98 98 83 61
569 65 f4 b4 b8 17 c4 f6 a8 d4 86 ee 4e a9 13 0f e9
570 b9 09 2b d1 36 d1 84 f9 5f 50 4a 60 7e ac 56 58
571 46 d2 fd d6 59 7a 89 67 c7 39 6e f9 5a 6e ee bb
572 45 78 a6 43 96 6d ca 4d 8e e3 de 84 2d e6 32 79
573 c6 18 15 9c 1a b5 4a 89 43 7b 6a 61 20 e4 93 0a
574 fb 52 a4 ba 6c ed 8a 49 47 ac 64 b3 0a 34 97 cb
575 e7 01 c2 d6 26 6d 51 72 19 ad 0e c6 d3 47 db e9
576
577 # Prime 1:
578 08 da d7 f1 13 63 fa a6 23 d5 d6 d5 e8 a3 19 32
579 8d 82 19 0d 71 27 d2 84 6c 43 9b 0a b7 26 19 b0
580 a4 3a 95 32 0e 4e c3 4f c3 a9 ce a8 76 42 23 05
581 bd 76 c5 ba 7b e9 e2 f4 10 c8 06 06 45 a1 d2 9e
582 db
583
584 # Prime 2:
585 08 47 e7 32 37 6f c7 90 0f 89 8e a8 2e b2 b0 fc
586 41 85 65 fd ae 62 f7 d9 ec 4c e2 21 7b 97 99 0d
587 d2 72 db 15 7f 99 f6 3c 0d cb b9 fb ac db d4 c4
588 da db 6d f6 77 56 35 8c a4 17 48 25 b4 8f 49 70
589 6d
590
591 # Prime exponent 1:
592 05 c2 a8 3c 12 4b 36 21 a2 aa 57 ea 2c 3e fe 03
593 5e ff 45 60 f3 3d de bb 7a da b8 1f ce 69 a0 c8
594 c2 ed c1 65 20 dd a8 3d 59 a2 3b e8 67 96 3a c6
595 5f 2c c7 10 bb cf b9 6e e1 03 de b7 71 d1 05 fd
596 85
597
598 # Prime exponent 2:
599 04 ca e8 aa 0d 9f aa 16 5c 87 b6 82 ec 14 0b 8e
600 d3 b5 0b 24 59 4b 7a 3b 2c 22 0b 36 69 bb 81 9f
601 98 4f 55 31 0a 1a e7 82 36 51 d4 a0 2e 99 44 79
602 72 59 51 39 36 34 34 e5 e3 0a 7e 7d 24 15 51 e1
603 b9
604
605 # Coefficient:
606 07 d3 e4 7b f6 86 60 0b 11 ac 28 3c e8 8d bb 3f
607 60 51 e8 ef d0 46 80 e4 4c 17 1e f5 31 b8 0b 2b
608 7c 39 fc 76 63 20 e2 cf 15 d8 d9 98 20 e9 6f f3
609 0d c6 96 91 83 9c 4b 40 d7 b0 6e 45 30 7d c9 1f
610 3f
611
612 # RSA-PSS signing of 6 random messages with random salts
613 # -------------------------------------------------------
Paul Kehrerefca2802014-02-17 20:55:13 -0600614 # PSS Example 8.1
Alex Stapleton58f27ac2014-02-02 19:30:03 +0000615
Paul Kehrerefca2802014-02-17 20:55:13 -0600616 # -----------------
617
618 # Message to be signed:
619 81 33 2f 4b e6 29 48 41 5e a1 d8 99 79 2e ea cf
620 6c 6e 1d b1 da 8b e1 3b 5c ea 41 db 2f ed 46 70
621 92 e1 ff 39 89 14 c7 14 25 97 75 f5 95 f8 54 7f
622 73 56 92 a5 75 e6 92 3a f7 8f 22 c6 99 7d db 90
623 fb 6f 72 d7 bb 0d d5 74 4a 31 de cd 3d c3 68 58
624 49 83 6e d3 4a ec 59 63 04 ad 11 84 3c 4f 88 48
625 9f 20 97 35 f5 fb 7f da f7 ce c8 ad dc 58 18 16
626 8f 88 0a cb f4 90 d5 10 05 b7 a8 e8 4e 43 e5 42
627 87 97 75 71 dd 99 ee a4 b1 61 eb 2d f1 f5 10 8f
628 12 a4 14 2a 83 32 2e db 05 a7 54 87 a3 43 5c 9a
629 78 ce 53 ed 93 bc 55 08 57 d7 a9 fb
630
631 # Salt:
632 1d 65 49 1d 79 c8 64 b3 73 00 9b e6 f6 f2 46 7b
633 ac 4c 78 fa
634
635 # Signature:
636 02 62 ac 25 4b fa 77 f3 c1 ac a2 2c 51 79 f8 f0
637 40 42 2b 3c 5b af d4 0a 8f 21 cf 0f a5 a6 67 cc
638 d5 99 3d 42 db af b4 09 c5 20 e2 5f ce 2b 1e e1
639 e7 16 57 7f 1e fa 17 f3 da 28 05 2f 40 f0 41 9b
640 23 10 6d 78 45 aa f0 11 25 b6 98 e7 a4 df e9 2d
641 39 67 bb 00 c4 d0 d3 5b a3 55 2a b9 a8 b3 ee f0
642 7c 7f ec db c5 42 4a c4 db 1e 20 cb 37 d0 b2 74
643 47 69 94 0e a9 07 e1 7f bb ca 67 3b 20 52 23 80
644 c5
645
646 # PSS Example 8.2
647
648 # -----------------
649
650 # Message to be signed:
651 e2 f9 6e af 0e 05 e7 ba 32 6e cc a0 ba 7f d2 f7
652 c0 23 56 f3 ce de 9d 0f aa bf 4f cc 8e 60 a9 73
653 e5 59 5f d9 ea 08
654
655 # Salt:
656 43 5c 09 8a a9 90 9e b2 37 7f 12 48 b0 91 b6 89
657 87 ff 18 38
658
659 # Signature:
660 27 07 b9 ad 51 15 c5 8c 94 e9 32 e8 ec 0a 28 0f
661 56 33 9e 44 a1 b5 8d 4d dc ff 2f 31 2e 5f 34 dc
662 fe 39 e8 9c 6a 94 dc ee 86 db bd ae 5b 79 ba 4e
663 08 19 a9 e7 bf d9 d9 82 e7 ee 6c 86 ee 68 39 6e
664 8b 3a 14 c9 c8 f3 4b 17 8e b7 41 f9 d3 f1 21 10
665 9b f5 c8 17 2f ad a2 e7 68 f9 ea 14 33 03 2c 00
666 4a 8a a0 7e b9 90 00 0a 48 dc 94 c8 ba c8 aa be
667 2b 09 b1 aa 46 c0 a2 aa 0e 12 f6 3f bb a7 75 ba
668 7e
669
670 # <snip>
Alex Stapleton58f27ac2014-02-02 19:30:03 +0000671
672 # =============================================
673
674 # Example 9: A 1536-bit RSA key pair
675 # -----------------------------------
676
677
678 # Public key
679 # ----------
680
681 # Modulus:
682 e6 bd 69 2a c9 66 45 79 04 03 fd d0 f5 be b8 b9
683 bf 92 ed 10 00 7f c3 65 04 64 19 dd 06 c0 5c 5b
684 5b 2f 48 ec f9 89 e4 ce 26 91 09 97 9c bb 40 b4
685 a0 ad 24 d2 24 83 d1 ee 31 5a d4 cc b1 53 42 68
686 35 26 91 c5 24 f6 dd 8e 6c 29 d2 24 cf 24 69 73
687 ae c8 6c 5b f6 b1 40 1a 85 0d 1b 9a d1 bb 8c bc
688 ec 47 b0 6f 0f 8c 7f 45 d3 fc 8f 31 92 99 c5 43
689 3d db c2 b3 05 3b 47 de d2 ec d4 a4 ca ef d6 14
690 83 3d c8 bb 62 2f 31 7e d0 76 b8 05 7f e8 de 3f
691 84 48 0a d5 e8 3e 4a 61 90 4a 4f 24 8f b3 97 02
692 73 57 e1 d3 0e 46 31 39 81 5c 6f d4 fd 5a c5 b8
693 17 2a 45 23 0e cb 63 18 a0 4f 14 55 d8 4e 5a 8b
694
695 # Exponent:
696 01 00 01
697
698 # Private key
699 # -----------
700
701 # Modulus:
702 e6 bd 69 2a c9 66 45 79 04 03 fd d0 f5 be b8 b9
703 bf 92 ed 10 00 7f c3 65 04 64 19 dd 06 c0 5c 5b
704 5b 2f 48 ec f9 89 e4 ce 26 91 09 97 9c bb 40 b4
705 a0 ad 24 d2 24 83 d1 ee 31 5a d4 cc b1 53 42 68
706 35 26 91 c5 24 f6 dd 8e 6c 29 d2 24 cf 24 69 73
707 ae c8 6c 5b f6 b1 40 1a 85 0d 1b 9a d1 bb 8c bc
708 ec 47 b0 6f 0f 8c 7f 45 d3 fc 8f 31 92 99 c5 43
709 3d db c2 b3 05 3b 47 de d2 ec d4 a4 ca ef d6 14
710 83 3d c8 bb 62 2f 31 7e d0 76 b8 05 7f e8 de 3f
711 84 48 0a d5 e8 3e 4a 61 90 4a 4f 24 8f b3 97 02
712 73 57 e1 d3 0e 46 31 39 81 5c 6f d4 fd 5a c5 b8
713 17 2a 45 23 0e cb 63 18 a0 4f 14 55 d8 4e 5a 8b
714
715 # Public exponent:
716 01 00 01
717
718 # Exponent:
719 6a 7f d8 4f b8 5f ad 07 3b 34 40 6d b7 4f 8d 61
720 a6 ab c1 21 96 a9 61 dd 79 56 5e 9d a6 e5 18 7b
721 ce 2d 98 02 50 f7 35 95 75 35 92 70 d9 15 90 bb
722 0e 42 7c 71 46 0b 55 d5 14 10 b1 91 bc f3 09 fe
723 a1 31 a9 2c 8e 70 27 38 fa 71 9f 1e 00 41 f5 2e
724 40 e9 1f 22 9f 4d 96 a1 e6 f1 72 e1 55 96 b4 51
725 0a 6d ae c2 61 05 f2 be bc 53 31 6b 87 bd f2 13
726 11 66 60 70 e8 df ee 69 d5 2c 71 a9 76 ca ae 79
727 c7 2b 68 d2 85 80 dc 68 6d 9f 51 29 d2 25 f8 2b
728 3d 61 55 13 a8 82 b3 db 91 41 6b 48 ce 08 88 82
729 13 e3 7e eb 9a f8 00 d8 1c ab 32 8c e4 20 68 99
730 03 c0 0c 7b 5f d3 1b 75 50 3a 6d 41 96 84 d6 29
731
732 # Prime 1:
733 f8 eb 97 e9 8d f1 26 64 ee fd b7 61 59 6a 69 dd
734 cd 0e 76 da ec e6 ed 4b f5 a1 b5 0a c0 86 f7 92
735 8a 4d 2f 87 26 a7 7e 51 5b 74 da 41 98 8f 22 0b
736 1c c8 7a a1 fc 81 0c e9 9a 82 f2 d1 ce 82 1e dc
737 ed 79 4c 69 41 f4 2c 7a 1a 0b 8c 4d 28 c7 5e c6
738 0b 65 22 79 f6 15 4a 76 2a ed 16 5d 47 de e3 67
739
740 # Prime 2:
741 ed 4d 71 d0 a6 e2 4b 93 c2 e5 f6 b4 bb e0 5f 5f
742 b0 af a0 42 d2 04 fe 33 78 d3 65 c2 f2 88 b6 a8
743 da d7 ef e4 5d 15 3e ef 40 ca cc 7b 81 ff 93 40
744 02 d1 08 99 4b 94 a5 e4 72 8c d9 c9 63 37 5a e4
745 99 65 bd a5 5c bf 0e fe d8 d6 55 3b 40 27 f2 d8
746 62 08 a6 e6 b4 89 c1 76 12 80 92 d6 29 e4 9d 3d
747
748 # Prime exponent 1:
749 2b b6 8b dd fb 0c 4f 56 c8 55 8b ff af 89 2d 80
750 43 03 78 41 e7 fa 81 cf a6 1a 38 c5 e3 9b 90 1c
751 8e e7 11 22 a5 da 22 27 bd 6c de eb 48 14 52 c1
752 2a d3 d6 1d 5e 4f 77 6a 0a b5 56 59 1b ef e3 e5
753 9e 5a 7f dd b8 34 5e 1f 2f 35 b9 f4 ce e5 7c 32
754 41 4c 08 6a ec 99 3e 93 53 e4 80 d9 ee c6 28 9f
755
756 # Prime exponent 2:
757 4f f8 97 70 9f ad 07 97 46 49 45 78 e7 0f d8 54
758 61 30 ee ab 56 27 c4 9b 08 0f 05 ee 4a d9 f3 e4
759 b7 cb a9 d6 a5 df f1 13 a4 1c 34 09 33 68 33 f1
760 90 81 6d 8a 6b c4 2e 9b ec 56 b7 56 7d 0f 3c 9c
761 69 6d b6 19 b2 45 d9 01 dd 85 6d b7 c8 09 2e 77
762 e9 a1 cc cd 56 ee 4d ba 42 c5 fd b6 1a ec 26 69
763
764 # Coefficient:
765 77 b9 d1 13 7b 50 40 4a 98 27 29 31 6e fa fc 7d
766 fe 66 d3 4e 5a 18 26 00 d5 f3 0a 0a 85 12 05 1c
767 56 0d 08 1d 4d 0a 18 35 ec 3d 25 a6 0f 4e 4d 6a
768 a9 48 b2 bf 3d bb 5b 12 4c bb c3 48 92 55 a3 a9
769 48 37 2f 69 78 49 67 45 f9 43 e1 db 4f 18 38 2c
770 ea a5 05 df c6 57 57 bb 3f 85 7a 58 dc e5 21 56
771
Paul Kehrerefca2802014-02-17 20:55:13 -0600772 # PKCS#1 v1.5 Signature Example 2.17
Alex Stapleton58f27ac2014-02-02 19:30:03 +0000773
Paul Kehrerefca2802014-02-17 20:55:13 -0600774 # -----------------
775
776 # Message to be signed:
777 06 ad d7 5a b6 89 de 06 77 44 e6 9a 2e bd 4b 90
778 fa 93 83 00 3c d0 5f f5 36 cb f2 94 cd 21 5f 09
779 23 b7 fc 90 04 f0 aa 18 52 71 a1 d0 06 1f d0 e9
780 77 7a d1 ec 0c 71 59 1f 57 8b f7 b8 e5 a1
781
782 # Signature:
783 45 14 21 0e 54 1d 5b ad 7d d6 0a e5 49 b9 43 ac
784 c4 4f 21 39 0d f5 b6 13 18 45 5a 17 61 0d f5 b7
785 4d 84 ae d2 32 f1 7e 59 d9 1d d2 65 99 22 f8 12
786 db d4 96 81 69 03 84 b9 54 e9 ad fb 9b 1a 96 8c
787 0c bf f7 63 ec ee d6 27 50 c5 91 64 b5 e0 80 a8
788 fe f3 d5 5b fe 2a cf ad 27 52 a6 a8 45 9f a1 fa
789 b4 9a d3 78 c6 96 4b 23 ee 97 fd 10 34 61 0c 5c
790 c1 4c 61 e0 eb fb 17 11 f8 ad e9 6f e6 55 7b 38
791
792 # <snip>
Alex Stapleton58f27ac2014-02-02 19:30:03 +0000793
794 # =============================================
795
Paul Kehrerefca2802014-02-17 20:55:13 -0600796 # <snip>
Alex Stapleton58f27ac2014-02-02 19:30:03 +0000797 """).splitlines()
798
799 vectors = tuple(load_pkcs1_vectors(vector_data))
800 expected = (
801 (
802 {
803 'modulus': int(
804 '495370a1fb18543c16d3631e3163255df62be6eee890d5f25509e4f77'
805 '8a8ea6fbbbcdf85dff64e0d972003ab3681fbba6dd41fd541829b2e58'
806 '2de9f2a4a4e0a2d0900bef4753db3cee0ee06c7dfae8b1d53b5953218'
807 'f9cceea695b08668edeaadced9463b1d790d5ebf27e9115b46cad4d9a'
808 '2b8efab0561b0810344739ada0733f', 16),
809 'public_exponent': int('10001', 16),
810 'private_exponent': int(
811 '6c66ffe98980c38fcdeab5159898836165f4b4b817c4f6a8d486ee4ea'
812 '9130fe9b9092bd136d184f95f504a607eac565846d2fdd6597a8967c7'
813 '396ef95a6eeebb4578a643966dca4d8ee3de842de63279c618159c1ab'
814 '54a89437b6a6120e4930afb52a4ba6ced8a4947ac64b30a3497cbe701'
815 'c2d6266d517219ad0ec6d347dbe9', 16),
816 'p': int(
817 '8dad7f11363faa623d5d6d5e8a319328d82190d7127d2846c439b0ab7'
818 '2619b0a43a95320e4ec34fc3a9cea876422305bd76c5ba7be9e2f410c'
819 '8060645a1d29edb', 16),
820 'q': int(
821 '847e732376fc7900f898ea82eb2b0fc418565fdae62f7d9ec4ce2217b'
822 '97990dd272db157f99f63c0dcbb9fbacdbd4c4dadb6df67756358ca41'
Paul Kehrer09328bb2014-02-12 23:57:27 -0600823 '74825b48f49706d', 16),
824 'dmp1': int(
825 '05c2a83c124b3621a2aa57ea2c3efe035eff4560f33ddebb7adab81fc'
826 'e69a0c8c2edc16520dda83d59a23be867963ac65f2cc710bbcfb96ee1'
827 '03deb771d105fd85', 16),
828 'dmq1': int(
829 '04cae8aa0d9faa165c87b682ec140b8ed3b50b24594b7a3b2c220b366'
830 '9bb819f984f55310a1ae7823651d4a02e99447972595139363434e5e3'
831 '0a7e7d241551e1b9', 16),
832 'iqmp': int(
833 '07d3e47bf686600b11ac283ce88dbb3f6051e8efd04680e44c171ef53'
834 '1b80b2b7c39fc766320e2cf15d8d99820e96ff30dc69691839c4b40d7'
Paul Kehrerefca2802014-02-17 20:55:13 -0600835 'b06e45307dc91f3f', 16),
836 'examples': [
837 {
Paul Kehrer26811802014-02-19 16:32:11 -0600838 'message': b'81332f4be62948415ea1d899792eeacf6c6e1db1d'
839 b'a8be13b5cea41db2fed467092e1ff398914c71425'
840 b'9775f595f8547f735692a575e6923af78f22c6997'
841 b'ddb90fb6f72d7bb0dd5744a31decd3dc368584983'
842 b'6ed34aec596304ad11843c4f88489f209735f5fb7'
843 b'fdaf7cec8addc5818168f880acbf490d51005b7a8'
844 b'e84e43e54287977571dd99eea4b161eb2df1f5108'
845 b'f12a4142a83322edb05a75487a3435c9a78ce53ed'
846 b'93bc550857d7a9fb',
847 'salt': b'1d65491d79c864b373009be6f6f2467bac4c78fa',
848 'signature': b'0262ac254bfa77f3c1aca22c5179f8f040422b3'
849 b'c5bafd40a8f21cf0fa5a667ccd5993d42dbafb4'
850 b'09c520e25fce2b1ee1e716577f1efa17f3da280'
851 b'52f40f0419b23106d7845aaf01125b698e7a4df'
852 b'e92d3967bb00c4d0d35ba3552ab9a8b3eef07c7'
853 b'fecdbc5424ac4db1e20cb37d0b2744769940ea9'
854 b'07e17fbbca673b20522380c5'
Paul Kehrerefca2802014-02-17 20:55:13 -0600855 }, {
Paul Kehrer26811802014-02-19 16:32:11 -0600856 'message': b'e2f96eaf0e05e7ba326ecca0ba7fd2f7c02356f3c'
857 b'ede9d0faabf4fcc8e60a973e5595fd9ea08',
858 'salt': b'435c098aa9909eb2377f1248b091b68987ff1838',
859 'signature': b'2707b9ad5115c58c94e932e8ec0a280f56339e4'
860 b'4a1b58d4ddcff2f312e5f34dcfe39e89c6a94dc'
861 b'ee86dbbdae5b79ba4e0819a9e7bfd9d982e7ee6'
862 b'c86ee68396e8b3a14c9c8f34b178eb741f9d3f1'
863 b'21109bf5c8172fada2e768f9ea1433032c004a8'
864 b'aa07eb990000a48dc94c8bac8aabe2b09b1aa46'
865 b'c0a2aa0e12f63fbba775ba7e'
Paul Kehrerefca2802014-02-17 20:55:13 -0600866 }
867 ]
Alex Stapleton58f27ac2014-02-02 19:30:03 +0000868 },
869
870 {
871 'modulus': int(
872 '495370a1fb18543c16d3631e3163255df62be6eee890d5f25509e4f77'
873 '8a8ea6fbbbcdf85dff64e0d972003ab3681fbba6dd41fd541829b2e58'
874 '2de9f2a4a4e0a2d0900bef4753db3cee0ee06c7dfae8b1d53b5953218'
875 'f9cceea695b08668edeaadced9463b1d790d5ebf27e9115b46cad4d9a'
876 '2b8efab0561b0810344739ada0733f', 16),
877 'public_exponent': int('10001', 16)
878 }
879 ),
880 (
881 {
882 'modulus': int(
883 'e6bd692ac96645790403fdd0f5beb8b9bf92ed10007fc365046419dd0'
884 '6c05c5b5b2f48ecf989e4ce269109979cbb40b4a0ad24d22483d1ee31'
885 '5ad4ccb1534268352691c524f6dd8e6c29d224cf246973aec86c5bf6b'
886 '1401a850d1b9ad1bb8cbcec47b06f0f8c7f45d3fc8f319299c5433ddb'
887 'c2b3053b47ded2ecd4a4caefd614833dc8bb622f317ed076b8057fe8d'
888 'e3f84480ad5e83e4a61904a4f248fb397027357e1d30e463139815c6f'
889 'd4fd5ac5b8172a45230ecb6318a04f1455d84e5a8b', 16),
890 'public_exponent': int('10001', 16),
891 'private_exponent': int(
892 '6a7fd84fb85fad073b34406db74f8d61a6abc12196a961dd79565e9da'
893 '6e5187bce2d980250f7359575359270d91590bb0e427c71460b55d514'
894 '10b191bcf309fea131a92c8e702738fa719f1e0041f52e40e91f229f4'
895 'd96a1e6f172e15596b4510a6daec26105f2bebc53316b87bdf2131166'
896 '6070e8dfee69d52c71a976caae79c72b68d28580dc686d9f5129d225f'
897 '82b3d615513a882b3db91416b48ce08888213e37eeb9af800d81cab32'
898 '8ce420689903c00c7b5fd31b75503a6d419684d629', 16),
899 'p': int(
900 'f8eb97e98df12664eefdb761596a69ddcd0e76daece6ed4bf5a1b50ac'
901 '086f7928a4d2f8726a77e515b74da41988f220b1cc87aa1fc810ce99a'
902 '82f2d1ce821edced794c6941f42c7a1a0b8c4d28c75ec60b652279f61'
903 '54a762aed165d47dee367', 16),
904 'q': int(
905 'ed4d71d0a6e24b93c2e5f6b4bbe05f5fb0afa042d204fe3378d365c2f'
906 '288b6a8dad7efe45d153eef40cacc7b81ff934002d108994b94a5e472'
907 '8cd9c963375ae49965bda55cbf0efed8d6553b4027f2d86208a6e6b48'
Paul Kehrer09328bb2014-02-12 23:57:27 -0600908 '9c176128092d629e49d3d', 16),
909 'dmp1': int(
910 '2bb68bddfb0c4f56c8558bffaf892d8043037841e7fa81cfa61a38c5e'
911 '39b901c8ee71122a5da2227bd6cdeeb481452c12ad3d61d5e4f776a0a'
912 'b556591befe3e59e5a7fddb8345e1f2f35b9f4cee57c32414c086aec9'
913 '93e9353e480d9eec6289f', 16),
914 'dmq1': int(
915 '4ff897709fad079746494578e70fd8546130eeab5627c49b080f05ee4'
916 'ad9f3e4b7cba9d6a5dff113a41c3409336833f190816d8a6bc42e9bec'
917 '56b7567d0f3c9c696db619b245d901dd856db7c8092e77e9a1cccd56e'
918 'e4dba42c5fdb61aec2669', 16),
919 'iqmp': int(
920 '77b9d1137b50404a982729316efafc7dfe66d34e5a182600d5f30a0a8'
921 '512051c560d081d4d0a1835ec3d25a60f4e4d6aa948b2bf3dbb5b124c'
922 'bbc3489255a3a948372f6978496745f943e1db4f18382ceaa505dfc65'
Paul Kehrerefca2802014-02-17 20:55:13 -0600923 '757bb3f857a58dce52156', 16),
924 'examples': [
925 {
Paul Kehrer26811802014-02-19 16:32:11 -0600926 'message': b'06add75ab689de067744e69a2ebd4b90fa9383003'
927 b'cd05ff536cbf294cd215f0923b7fc9004f0aa1852'
928 b'71a1d0061fd0e9777ad1ec0c71591f578bf7b8e5a'
929 b'1',
930 'signature': b'4514210e541d5bad7dd60ae549b943acc44f213'
931 b'90df5b61318455a17610df5b74d84aed232f17e'
932 b'59d91dd2659922f812dbd49681690384b954e9a'
933 b'dfb9b1a968c0cbff763eceed62750c59164b5e0'
934 b'80a8fef3d55bfe2acfad2752a6a8459fa1fab49'
935 b'ad378c6964b23ee97fd1034610c5cc14c61e0eb'
936 b'fb1711f8ade96fe6557b38'
Paul Kehrerefca2802014-02-17 20:55:13 -0600937 }
938 ]
Alex Stapleton58f27ac2014-02-02 19:30:03 +0000939 },
940
941 {
942 'modulus': int(
943 'e6bd692ac96645790403fdd0f5beb8b9bf92ed10007fc365046419dd0'
944 '6c05c5b5b2f48ecf989e4ce269109979cbb40b4a0ad24d22483d1ee31'
945 '5ad4ccb1534268352691c524f6dd8e6c29d224cf246973aec86c5bf6b'
946 '1401a850d1b9ad1bb8cbcec47b06f0f8c7f45d3fc8f319299c5433ddb'
947 'c2b3053b47ded2ecd4a4caefd614833dc8bb622f317ed076b8057fe8d'
948 'e3f84480ad5e83e4a61904a4f248fb397027357e1d30e463139815c6f'
949 'd4fd5ac5b8172a45230ecb6318a04f1455d84e5a8b', 16),
950 'public_exponent': int('10001', 16)
951 }
952 )
953 )
954 assert vectors == expected
Ayrx4300f6c2014-02-09 15:15:13 +0800955
956
Paul Kehrer3fe91502014-03-29 12:08:39 -0500957def test_load_pkcs1_oaep_vectors():
958 vector_data = textwrap.dedent("""
959 Test vectors for RSA-OAEP
960 =========================
961
962 This file contains test vectors for the RSA-OAEP encryption
963
964 Key lengths:
965
966 Key 1: 1024 bits
967 # <snip>
968 ===========================================================================
969 # Example 1: A 1024-bit RSA key pair
970 # -----------------------------------
971
972
973 # Public key
974 # ----------
975
976 # Modulus:
977 a8 b3 b2 84 af 8e b5 0b 38 70 34 a8 60 f1 46 c4
978 91 9f 31 87 63 cd 6c 55 98 c8 ae 48 11 a1 e0 ab
979 c4 c7 e0 b0 82 d6 93 a5 e7 fc ed 67 5c f4 66 85
980 12 77 2c 0c bc 64 a7 42 c6 c6 30 f5 33 c8 cc 72
981 f6 2a e8 33 c4 0b f2 58 42 e9 84 bb 78 bd bf 97
982 c0 10 7d 55 bd b6 62 f5 c4 e0 fa b9 84 5c b5 14
983 8e f7 39 2d d3 aa ff 93 ae 1e 6b 66 7b b3 d4 24
984 76 16 d4 f5 ba 10 d4 cf d2 26 de 88 d3 9f 16 fb
985
986 # Exponent:
987 01 00 01
988
989 # Private key
990 # -----------
991
992 # Modulus:
993 a8 b3 b2 84 af 8e b5 0b 38 70 34 a8 60 f1 46 c4
994 91 9f 31 87 63 cd 6c 55 98 c8 ae 48 11 a1 e0 ab
995 c4 c7 e0 b0 82 d6 93 a5 e7 fc ed 67 5c f4 66 85
996 12 77 2c 0c bc 64 a7 42 c6 c6 30 f5 33 c8 cc 72
997 f6 2a e8 33 c4 0b f2 58 42 e9 84 bb 78 bd bf 97
998 c0 10 7d 55 bd b6 62 f5 c4 e0 fa b9 84 5c b5 14
999 8e f7 39 2d d3 aa ff 93 ae 1e 6b 66 7b b3 d4 24
1000 76 16 d4 f5 ba 10 d4 cf d2 26 de 88 d3 9f 16 fb
1001
1002 # Public exponent:
1003 01 00 01
1004
1005 # Exponent:
1006 53 33 9c fd b7 9f c8 46 6a 65 5c 73 16 ac a8 5c
1007 55 fd 8f 6d d8 98 fd af 11 95 17 ef 4f 52 e8 fd
1008 8e 25 8d f9 3f ee 18 0f a0 e4 ab 29 69 3c d8 3b
1009 15 2a 55 3d 4a c4 d1 81 2b 8b 9f a5 af 0e 7f 55
1010 fe 73 04 df 41 57 09 26 f3 31 1f 15 c4 d6 5a 73
1011 2c 48 31 16 ee 3d 3d 2d 0a f3 54 9a d9 bf 7c bf
1012 b7 8a d8 84 f8 4d 5b eb 04 72 4d c7 36 9b 31 de
1013 f3 7d 0c f5 39 e9 cf cd d3 de 65 37 29 ea d5 d1
1014
1015 # Prime 1:
1016 d3 27 37 e7 26 7f fe 13 41 b2 d5 c0 d1 50 a8 1b
1017 58 6f b3 13 2b ed 2f 8d 52 62 86 4a 9c b9 f3 0a
1018 f3 8b e4 48 59 8d 41 3a 17 2e fb 80 2c 21 ac f1
1019 c1 1c 52 0c 2f 26 a4 71 dc ad 21 2e ac 7c a3 9d
1020
1021 # Prime 2:
1022 cc 88 53 d1 d5 4d a6 30 fa c0 04 f4 71 f2 81 c7
1023 b8 98 2d 82 24 a4 90 ed be b3 3d 3e 3d 5c c9 3c
1024 47 65 70 3d 1d d7 91 64 2f 1f 11 6a 0d d8 52 be
1025 24 19 b2 af 72 bf e9 a0 30 e8 60 b0 28 8b 5d 77
1026
1027 # Prime exponent 1:
1028 0e 12 bf 17 18 e9 ce f5 59 9b a1 c3 88 2f e8 04
1029 6a 90 87 4e ef ce 8f 2c cc 20 e4 f2 74 1f b0 a3
1030 3a 38 48 ae c9 c9 30 5f be cb d2 d7 68 19 96 7d
1031 46 71 ac c6 43 1e 40 37 96 8d b3 78 78 e6 95 c1
1032
1033 # Prime exponent 2:
1034 95 29 7b 0f 95 a2 fa 67 d0 07 07 d6 09 df d4 fc
1035 05 c8 9d af c2 ef 6d 6e a5 5b ec 77 1e a3 33 73
1036 4d 92 51 e7 90 82 ec da 86 6e fe f1 3c 45 9e 1a
1037 63 13 86 b7 e3 54 c8 99 f5 f1 12 ca 85 d7 15 83
1038
1039 # Coefficient:
1040 4f 45 6c 50 24 93 bd c0 ed 2a b7 56 a3 a6 ed 4d
1041 67 35 2a 69 7d 42 16 e9 32 12 b1 27 a6 3d 54 11
1042 ce 6f a9 8d 5d be fd 73 26 3e 37 28 14 27 43 81
1043 81 66 ed 7d d6 36 87 dd 2a 8c a1 d2 f4 fb d8 e1
1044
1045 # RSA-OAEP encryption of 6 random messages with random seeds
1046 # -----------------------------------------------------------
1047
1048 # OAEP Example 1.1
1049 # ------------------
1050
1051 # Message:
1052 66 28 19 4e 12 07 3d b0 3b a9 4c da 9e f9 53 23
1053 97 d5 0d ba 79 b9 87 00 4a fe fe 34
1054
1055 # Seed:
1056 18 b7 76 ea 21 06 9d 69 77 6a 33 e9 6b ad 48 e1
1057 dd a0 a5 ef
1058
1059 # Encryption:
1060 35 4f e6 7b 4a 12 6d 5d 35 fe 36 c7 77 79 1a 3f
1061 7b a1 3d ef 48 4e 2d 39 08 af f7 22 fa d4 68 fb
1062 21 69 6d e9 5d 0b e9 11 c2 d3 17 4f 8a fc c2 01
1063 03 5f 7b 6d 8e 69 40 2d e5 45 16 18 c2 1a 53 5f
1064 a9 d7 bf c5 b8 dd 9f c2 43 f8 cf 92 7d b3 13 22
1065 d6 e8 81 ea a9 1a 99 61 70 e6 57 a0 5a 26 64 26
1066 d9 8c 88 00 3f 84 77 c1 22 70 94 a0 d9 fa 1e 8c
1067 40 24 30 9c e1 ec cc b5 21 00 35 d4 7a c7 2e 8a
1068
1069 # OAEP Example 1.2
1070 # ------------------
1071
1072 # Message:
1073 75 0c 40 47 f5 47 e8 e4 14 11 85 65 23 29 8a c9
1074 ba e2 45 ef af 13 97 fb e5 6f 9d d5
1075
1076 # Seed:
1077 0c c7 42 ce 4a 9b 7f 32 f9 51 bc b2 51 ef d9 25
1078 fe 4f e3 5f
1079
1080 # Encryption:
1081 64 0d b1 ac c5 8e 05 68 fe 54 07 e5 f9 b7 01 df
1082 f8 c3 c9 1e 71 6c 53 6f c7 fc ec 6c b5 b7 1c 11
1083 65 98 8d 4a 27 9e 15 77 d7 30 fc 7a 29 93 2e 3f
1084 00 c8 15 15 23 6d 8d 8e 31 01 7a 7a 09 df 43 52
1085 d9 04 cd eb 79 aa 58 3a dc c3 1e a6 98 a4 c0 52
1086 83 da ba 90 89 be 54 91 f6 7c 1a 4e e4 8d c7 4b
1087 bb e6 64 3a ef 84 66 79 b4 cb 39 5a 35 2d 5e d1
1088 15 91 2d f6 96 ff e0 70 29 32 94 6d 71 49 2b 44
1089
1090 # =============================================
1091 """).splitlines()
1092
1093 vectors = load_pkcs1_vectors(vector_data)
1094 expected = [
1095 (
1096 {
1097 'modulus': int(
1098 'a8b3b284af8eb50b387034a860f146c4919f318763cd6c5598c8ae481'
1099 '1a1e0abc4c7e0b082d693a5e7fced675cf4668512772c0cbc64a742c6'
1100 'c630f533c8cc72f62ae833c40bf25842e984bb78bdbf97c0107d55bdb'
1101 '662f5c4e0fab9845cb5148ef7392dd3aaff93ae1e6b667bb3d4247616'
1102 'd4f5ba10d4cfd226de88d39f16fb', 16),
1103 'public_exponent': int('10001', 16),
1104 'private_exponent': int(
1105 '53339cfdb79fc8466a655c7316aca85c55fd8f6dd898fdaf119517ef4'
1106 'f52e8fd8e258df93fee180fa0e4ab29693cd83b152a553d4ac4d1812b'
1107 '8b9fa5af0e7f55fe7304df41570926f3311f15c4d65a732c483116ee3'
1108 'd3d2d0af3549ad9bf7cbfb78ad884f84d5beb04724dc7369b31def37d'
1109 '0cf539e9cfcdd3de653729ead5d1', 16),
1110 'p': int(
1111 'd32737e7267ffe1341b2d5c0d150a81b586fb3132bed2f8d5262864a9'
1112 'cb9f30af38be448598d413a172efb802c21acf1c11c520c2f26a471dc'
1113 'ad212eac7ca39d', 16),
1114 'q': int(
1115 'cc8853d1d54da630fac004f471f281c7b8982d8224a490edbeb33d3e3'
1116 'd5cc93c4765703d1dd791642f1f116a0dd852be2419b2af72bfe9a030'
1117 'e860b0288b5d77', 16),
1118 'dmp1': int(
1119 '0e12bf1718e9cef5599ba1c3882fe8046a90874eefce8f2ccc20e4f27'
1120 '41fb0a33a3848aec9c9305fbecbd2d76819967d4671acc6431e403796'
1121 '8db37878e695c1', 16),
1122 'dmq1': int(
1123 '95297b0f95a2fa67d00707d609dfd4fc05c89dafc2ef6d6ea55bec771'
1124 'ea333734d9251e79082ecda866efef13c459e1a631386b7e354c899f5'
1125 'f112ca85d71583', 16),
1126 'iqmp': int(
1127 '4f456c502493bdc0ed2ab756a3a6ed4d67352a697d4216e93212b127a'
1128 '63d5411ce6fa98d5dbefd73263e3728142743818166ed7dd63687dd2a'
1129 '8ca1d2f4fbd8e1', 16),
1130 'examples': [
1131 {
1132 'message': b'6628194e12073db03ba94cda9ef9532397d50dba7'
1133 b'9b987004afefe34',
1134 'seed': b'18b776ea21069d69776a33e96bad48e1dda0a5ef',
1135 'encryption': b'354fe67b4a126d5d35fe36c777791a3f7ba13d'
1136 b'ef484e2d3908aff722fad468fb21696de95d0b'
1137 b'e911c2d3174f8afcc201035f7b6d8e69402de5'
1138 b'451618c21a535fa9d7bfc5b8dd9fc243f8cf92'
1139 b'7db31322d6e881eaa91a996170e657a05a2664'
1140 b'26d98c88003f8477c1227094a0d9fa1e8c4024'
1141 b'309ce1ecccb5210035d47ac72e8a'
1142 }, {
1143 'message': b'750c4047f547e8e41411856523298ac9bae245efa'
1144 b'f1397fbe56f9dd5',
1145 'seed': b'0cc742ce4a9b7f32f951bcb251efd925fe4fe35f',
1146 'encryption': b'640db1acc58e0568fe5407e5f9b701dff8c3c9'
1147 b'1e716c536fc7fcec6cb5b71c1165988d4a279e'
1148 b'1577d730fc7a29932e3f00c81515236d8d8e31'
1149 b'017a7a09df4352d904cdeb79aa583adcc31ea6'
1150 b'98a4c05283daba9089be5491f67c1a4ee48dc7'
1151 b'4bbbe6643aef846679b4cb395a352d5ed11591'
1152 b'2df696ffe0702932946d71492b44'
1153 }
1154 ]
1155 },
1156
1157 {
1158 'modulus': int(
1159 'a8b3b284af8eb50b387034a860f146c4919f318763cd6c5598c8ae481'
1160 '1a1e0abc4c7e0b082d693a5e7fced675cf4668512772c0cbc64a742c6'
1161 'c630f533c8cc72f62ae833c40bf25842e984bb78bdbf97c0107d55bdb'
1162 '662f5c4e0fab9845cb5148ef7392dd3aaff93ae1e6b667bb3d4247616'
1163 'd4f5ba10d4cfd226de88d39f16fb', 16),
1164 'public_exponent': int('10001', 16),
1165 }
1166 )
1167 ]
1168 assert vectors == expected
1169
1170
Ayrx4300f6c2014-02-09 15:15:13 +08001171def test_load_hotp_vectors():
1172 vector_data = textwrap.dedent("""
1173 # HOTP Test Vectors
1174 # RFC 4226 Appendix D
1175
1176 COUNT = 0
1177 COUNTER = 0
1178 INTERMEDIATE = cc93cf18508d94934c64b65d8ba7667fb7cde4b0
1179 TRUNCATED = 4c93cf18
1180 HOTP = 755224
Ayrxefc68382014-02-10 00:01:05 +08001181 SECRET = 12345678901234567890
Ayrx4300f6c2014-02-09 15:15:13 +08001182
1183 COUNT = 1
1184 COUNTER = 1
1185 INTERMEDIATE = 75a48a19d4cbe100644e8ac1397eea747a2d33ab
1186 TRUNCATED = 41397eea
1187 HOTP = 287082
Ayrxefc68382014-02-10 00:01:05 +08001188 SECRET = 12345678901234567890
1189
Ayrx4300f6c2014-02-09 15:15:13 +08001190
1191 COUNT = 2
1192 COUNTER = 2
1193 INTERMEDIATE = 0bacb7fa082fef30782211938bc1c5e70416ff44
1194 TRUNCATED = 82fef30
1195 HOTP = 359152
Ayrxefc68382014-02-10 00:01:05 +08001196 SECRET = 12345678901234567890
1197
Ayrx4300f6c2014-02-09 15:15:13 +08001198
1199 COUNT = 3
1200 COUNTER = 3
1201 INTERMEDIATE = 66c28227d03a2d5529262ff016a1e6ef76557ece
1202 TRUNCATED = 66ef7655
1203 HOTP = 969429
Ayrxefc68382014-02-10 00:01:05 +08001204 SECRET = 12345678901234567890
Ayrx4300f6c2014-02-09 15:15:13 +08001205 """).splitlines()
1206
1207 assert load_nist_vectors(vector_data) == [
1208 {
1209 "counter": b"0",
1210 "intermediate": b"cc93cf18508d94934c64b65d8ba7667fb7cde4b0",
1211 "truncated": b"4c93cf18",
1212 "hotp": b"755224",
Ayrxefc68382014-02-10 00:01:05 +08001213 "secret": b"12345678901234567890",
Ayrx4300f6c2014-02-09 15:15:13 +08001214 },
1215 {
1216 "counter": b"1",
1217 "intermediate": b"75a48a19d4cbe100644e8ac1397eea747a2d33ab",
1218 "truncated": b"41397eea",
1219 "hotp": b"287082",
Ayrxefc68382014-02-10 00:01:05 +08001220 "secret": b"12345678901234567890",
Ayrx4300f6c2014-02-09 15:15:13 +08001221 },
1222 {
1223 "counter": b"2",
1224 "intermediate": b"0bacb7fa082fef30782211938bc1c5e70416ff44",
1225 "truncated": b"82fef30",
1226 "hotp": b"359152",
Ayrxefc68382014-02-10 00:01:05 +08001227 "secret": b"12345678901234567890",
Ayrx4300f6c2014-02-09 15:15:13 +08001228 },
1229 {
1230 "counter": b"3",
1231 "intermediate": b"66c28227d03a2d5529262ff016a1e6ef76557ece",
1232 "truncated": b"66ef7655",
1233 "hotp": b"969429",
Ayrxefc68382014-02-10 00:01:05 +08001234 "secret": b"12345678901234567890",
Ayrx4300f6c2014-02-09 15:15:13 +08001235 },
1236 ]
1237
1238
1239def test_load_totp_vectors():
1240 vector_data = textwrap.dedent("""
1241 # TOTP Test Vectors
1242 # RFC 6238 Appendix B
1243
1244 COUNT = 0
1245 TIME = 59
1246 TOTP = 94287082
1247 MODE = SHA1
Ayrxefc68382014-02-10 00:01:05 +08001248 SECRET = 12345678901234567890
Ayrx4300f6c2014-02-09 15:15:13 +08001249
1250 COUNT = 1
1251 TIME = 59
1252 TOTP = 46119246
1253 MODE = SHA256
Ayrxefc68382014-02-10 00:01:05 +08001254 SECRET = 12345678901234567890
Ayrx4300f6c2014-02-09 15:15:13 +08001255
1256 COUNT = 2
1257 TIME = 59
1258 TOTP = 90693936
1259 MODE = SHA512
Ayrxefc68382014-02-10 00:01:05 +08001260 SECRET = 12345678901234567890
Ayrx4300f6c2014-02-09 15:15:13 +08001261 """).splitlines()
1262
1263 assert load_nist_vectors(vector_data) == [
1264 {
1265 "time": b"59",
1266 "totp": b"94287082",
1267 "mode": b"SHA1",
Ayrxefc68382014-02-10 00:01:05 +08001268 "secret": b"12345678901234567890",
Ayrx4300f6c2014-02-09 15:15:13 +08001269 },
1270 {
1271 "time": b"59",
1272 "totp": b"46119246",
1273 "mode": b"SHA256",
Ayrxefc68382014-02-10 00:01:05 +08001274 "secret": b"12345678901234567890",
Ayrx4300f6c2014-02-09 15:15:13 +08001275 },
1276 {
1277 "time": b"59",
1278 "totp": b"90693936",
1279 "mode": b"SHA512",
Ayrxefc68382014-02-10 00:01:05 +08001280 "secret": b"12345678901234567890",
Ayrx4300f6c2014-02-09 15:15:13 +08001281 },
1282 ]
Paul Kehrer2f2a2062014-03-10 23:30:28 -04001283
1284
1285def test_load_rsa_nist_vectors():
1286 vector_data = textwrap.dedent("""
Paul Kehrer61666eb2014-03-18 07:53:04 -04001287 # CAVS 11.4
1288 # "SigGen PKCS#1 RSASSA-PSS" information
1289 # Mod sizes selected: 1024 1536 2048 3072 4096
Paul Kehrer2f2a2062014-03-10 23:30:28 -04001290 # SHA Algorithm selected:SHA1 SHA224 SHA256 SHA384 SHA512
1291 # Salt len: 20
1292
1293 [mod = 1024]
1294
1295 n = bcb47b2e0dafcba81ff2a2b5cb115ca7e757184c9d72bcdcda707a146b3b4e29989d
1296
1297 e = 00000000000000000000000000000000000000000000000000000000000000000010001
1298 SHAAlg = SHA1
1299 Msg = 1248f62a4389f42f7b4bb131053d6c88a994db2075b912ccbe3ea7dc611714f14e
1300 S = 682cf53c1145d22a50caa9eb1a9ba70670c5915e0fdfde6457a765de2a8fe12de97
1301
1302 SHAAlg = SHA384
1303 Msg = e511903c2f1bfba245467295ac95413ac4746c984c3750a728c388aa628b0ebf
1304 S = 9c748702bbcc1f9468864cd360c8c39d007b2d8aaee833606c70f7593cf0d1519
1305
1306 [mod = 1024]
1307
1308 n = 1234567890
1309
1310 e = 0010001
1311
1312 SHAAlg = SHA512
1313 Msg = 3456781293fab829
1314 S = deadbeef0000
1315 """).splitlines()
1316
1317 vectors = load_rsa_nist_vectors(vector_data)
1318 assert vectors == [
1319 {
1320 "modulus": int("bcb47b2e0dafcba81ff2a2b5cb115ca7e757184c9d72bcdcda"
1321 "707a146b3b4e29989d", 16),
1322 "public_exponent": 65537,
Paul Kehrerdde59332014-03-16 17:57:20 -04001323 "algorithm": "SHA1",
Paul Kehrer2f2a2062014-03-10 23:30:28 -04001324 "salt_length": 20,
1325 "msg": b"1248f62a4389f42f7b4bb131053d6c88a994db2075b912ccbe3ea7dc6"
1326 b"11714f14e",
1327 "s": b"682cf53c1145d22a50caa9eb1a9ba70670c5915e0fdfde6457a765de2a8"
Paul Kehrer62707f12014-03-18 07:19:14 -04001328 b"fe12de97",
1329 "fail": False
Paul Kehrer2f2a2062014-03-10 23:30:28 -04001330 },
1331 {
1332 "modulus": int("bcb47b2e0dafcba81ff2a2b5cb115ca7e757184c9d72bcdcda"
1333 "707a146b3b4e29989d", 16),
1334 "public_exponent": 65537,
Paul Kehrerdde59332014-03-16 17:57:20 -04001335 "algorithm": "SHA384",
Paul Kehrer2f2a2062014-03-10 23:30:28 -04001336 "salt_length": 20,
1337 "msg": b"e511903c2f1bfba245467295ac95413ac4746c984c3750a728c388aa6"
1338 b"28b0ebf",
1339 "s": b"9c748702bbcc1f9468864cd360c8c39d007b2d8aaee833606c70f7593cf"
Paul Kehrer62707f12014-03-18 07:19:14 -04001340 b"0d1519",
1341 "fail": False
Paul Kehrer2f2a2062014-03-10 23:30:28 -04001342 },
1343 {
1344 "modulus": 78187493520,
1345 "public_exponent": 65537,
Paul Kehrerdde59332014-03-16 17:57:20 -04001346 "algorithm": "SHA512",
Paul Kehrer2f2a2062014-03-10 23:30:28 -04001347 "salt_length": 20,
1348 "msg": b"3456781293fab829",
Paul Kehrer62707f12014-03-18 07:19:14 -04001349 "s": b"deadbeef0000",
1350 "fail": False
1351 },
1352 ]
1353
1354
Paul Kehrerafc25182014-03-18 07:51:56 -04001355def test_load_rsa_nist_pkcs1v15_verification_vectors():
Paul Kehrer62707f12014-03-18 07:19:14 -04001356 vector_data = textwrap.dedent("""
Paul Kehrer61666eb2014-03-18 07:53:04 -04001357 # CAVS 11.0
1358 # "SigVer PKCS#1 Ver 1.5" information
1359 # Mod sizes selected: 1024 1536 2048 3072 4096
1360 # SHA Algorithm selected:SHA1 SHA224 SHA256 SHA384 SHA512
1361 # Generated on Wed Mar 02 00:13:02 2011
Paul Kehrer62707f12014-03-18 07:19:14 -04001362
1363 [mod = 1024]
1364
1365 n = be499b5e7f06c83fa0293e31465c8eb6b58af920bae52a7b5b9bfeb7aa72db126411
1366
1367 p = e7a80c5d211c06acb900939495f26d365fc2b4825b75e356f89003eaa5931e6be5c3
1368 q = d248aa248000f720258742da67b711940c8f76e1ecd52b67a6ffe1e49354d66ff84f
1369
1370 SHAAlg = SHA1
1371 e = 00000000000000000000000000000000000000000000000000000000000000000011
1372 d = 0d0f17362bdad181db4e1fe03e8de1a3208989914e14bf269558826bfa20faf4b68d
1373 Msg = 6b9cfac0ba1c7890b13e381ce752195cc1375237db2afcf6a9dcd1f95ec733a80c
1374 S = 562d87b5781c01d166fef3972669a0495c145b898a17df4743fbefb0a1582bd6ba9d
1375 SaltVal = 11223344555432167890
1376 Result = F (3 - Signature changed )
1377
1378 SHAAlg = SHA1
1379 e = 0000000000003
1380 d = bfa20faf4b68d
1381 Msg = 2a67c70ff14f9b34ddb42e6f89d5971057a0da980fc9ae70c81a84da0c0ac42737
1382 S = 2b91c6ae2b3c46ff18d5b7abe239634cb752d0acb53eea0ccd8ea8483036a50e8faf
1383 SaltVal = 11223344555432167890
1384 Result = P
1385 """).splitlines()
1386
1387 vectors = load_rsa_nist_vectors(vector_data)
1388 assert vectors == [
1389 {
1390 "modulus": int("be499b5e7f06c83fa0293e31465c8eb6b58af920bae52a7b5b"
1391 "9bfeb7aa72db126411", 16),
1392 "p": int("e7a80c5d211c06acb900939495f26d365fc2b4825b75e356f89003ea"
1393 "a5931e6be5c3", 16),
1394 "q": int("d248aa248000f720258742da67b711940c8f76e1ecd52b67a6ffe1e4"
1395 "9354d66ff84f", 16),
1396 "public_exponent": 17,
1397 "algorithm": "SHA1",
1398 "private_exponent": int("0d0f17362bdad181db4e1fe03e8de1a3208989914"
1399 "e14bf269558826bfa20faf4b68d", 16),
1400 "msg": b"6b9cfac0ba1c7890b13e381ce752195cc1375237db2afcf6a9dcd1f95"
1401 b"ec733a80c",
1402 "s": b"562d87b5781c01d166fef3972669a0495c145b898a17df4743fbefb0a15"
1403 b"82bd6ba9d",
1404 "saltval": b"11223344555432167890",
1405 "fail": True
1406 },
1407 {
1408 "modulus": int("be499b5e7f06c83fa0293e31465c8eb6b58af920bae52a7b5b"
1409 "9bfeb7aa72db126411", 16),
1410 "p": int("e7a80c5d211c06acb900939495f26d365fc2b4825b75e356f89003ea"
1411 "a5931e6be5c3", 16),
1412 "q": int("d248aa248000f720258742da67b711940c8f76e1ecd52b67a6ffe1e4"
1413 "9354d66ff84f", 16),
1414 "public_exponent": 3,
1415 "algorithm": "SHA1",
1416 "private_exponent": int("bfa20faf4b68d", 16),
1417 "msg": b"2a67c70ff14f9b34ddb42e6f89d5971057a0da980fc9ae70c81a84da0"
1418 b"c0ac42737",
1419 "s": b"2b91c6ae2b3c46ff18d5b7abe239634cb752d0acb53eea0ccd8ea848303"
1420 b"6a50e8faf",
1421 "saltval": b"11223344555432167890",
1422 "fail": False
Paul Kehrer2f2a2062014-03-10 23:30:28 -04001423 },
1424 ]
Mohammed Attia987cc702014-03-12 16:07:21 +02001425
1426
Paul Kehrerafc25182014-03-18 07:51:56 -04001427def test_load_rsa_nist_pss_verification_vectors():
1428 vector_data = textwrap.dedent("""
Paul Kehrer61666eb2014-03-18 07:53:04 -04001429 # CAVS 11.0
1430 # "SigVer PKCS#1 RSASSA-PSS" information
1431 # Mod sizes selected: 1024 1536 2048 3072 4096
Paul Kehrerafc25182014-03-18 07:51:56 -04001432 # SHA Algorithm selected:SHA1 SHA224 SHA256 SHA384 SHA512
1433 # Salt len: 10
1434 # Generated on Wed Mar 02 00:25:22 2011
1435
1436 [mod = 1024]
1437
1438 n = be499b5e7f06c83fa0293e31465c8eb6b5
1439
1440 p = e7a80c5d211c06acb900939495f26d365f
1441 q = d248aa248000f720258742da67b711940c
1442
1443 SHAAlg = SHA1
1444 e = 00000000000000011
1445 d = c8e26a88239672cf49b3422a07c4d834ba
1446 Msg = 6b9cfac0ba1c7890b13e381ce752195c
1447 S = 562d87b5781c01d166fef3972669a0495c
1448 SaltVal = 11223344555432167890
1449 Result = F (3 - Signature changed )
1450
1451 SHAAlg = SHA384
1452 e = 000003
1453 d = 0d0f17362bdad181db4e1fe03e8de1a320
1454 Msg = 2a67c70ff14f9b34ddb42e6f89d59710
1455 S = 2b91c6ae2b3c46ff18d5b7abe239634cb7
1456 SaltVal = 11223344555432167890
1457 Result = P
1458 """).splitlines()
1459
1460 vectors = load_rsa_nist_vectors(vector_data)
1461 assert vectors == [
1462 {
1463 "modulus": int("be499b5e7f06c83fa0293e31465c8eb6b5", 16),
1464 "p": int("e7a80c5d211c06acb900939495f26d365f", 16),
1465 "q": int("d248aa248000f720258742da67b711940c", 16),
1466 "public_exponent": 17,
1467 "algorithm": "SHA1",
1468 "private_exponent": int("c8e26a88239672cf49b3422a07c4d834ba", 16),
1469 "msg": b"6b9cfac0ba1c7890b13e381ce752195c",
1470 "s": b"562d87b5781c01d166fef3972669a0495c",
1471 "saltval": b"11223344555432167890",
1472 "salt_length": 10,
1473 "fail": True
1474 },
1475 {
1476 "modulus": int("be499b5e7f06c83fa0293e31465c8eb6b5", 16),
1477 "p": int("e7a80c5d211c06acb900939495f26d365f", 16),
1478 "q": int("d248aa248000f720258742da67b711940c", 16),
1479 "public_exponent": 3,
1480 "algorithm": "SHA384",
1481 "private_exponent": int("0d0f17362bdad181db4e1fe03e8de1a320", 16),
1482 "msg": b"2a67c70ff14f9b34ddb42e6f89d59710",
1483 "s": b"2b91c6ae2b3c46ff18d5b7abe239634cb7",
1484 "saltval": b"11223344555432167890",
1485 "salt_length": 10,
1486 "fail": False
1487 },
1488 ]
1489
1490
Mohammed Attia987cc702014-03-12 16:07:21 +02001491def test_load_fips_dsa_key_pair_vectors():
1492 vector_data = textwrap.dedent("""
1493 # CAVS 11.1
1494 # "KeyPair" information
1495 # Mod sizes selected: L=1024, N=160:: L=2048, N=224 :: L=2048, N=256 :: L
1496=3072, N=256
1497 # Generated on Wed May 04 08:50:52 2011
1498
1499
1500 [mod = L=1024, N=160]
1501
1502 P = d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d4b725ef341eabb47cf8a7a\
15038a41e792a156b7ce97206c4f9c5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b65223\
15046f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c7147123188f8dc551054ee162b634d60f097\
1505f719076640e20980a0093113a8bd73
1506 Q = 96c5390a8b612c0e422bb2b0ea194a3ec935a281
1507 G = 06b7861abbd35cc89e79c52f68d20875389b127361ca66822138ce4991d2b862259d6b\
15084548a6495b195aa0e0b6137ca37eb23b94074d3c3d300042bdf15762812b6333ef7b07ceba7860\
15097610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c61d39e7da8902291c4434a4e2224c3\
1510f4fd9f93cd6f4f17fc076341a7e7d9
1511
1512 X = 8185fee9cc7c0e91fd85503274f1cd5a3fd15a49
1513 Y = 6f26d98d41de7d871b6381851c9d91fa03942092ab6097e76422070edb71db44ff5682\
151480fdb1709f8fc3feab39f1f824adaeb2a298088156ac31af1aa04bf54f475bdcfdcf2f8a2dd973\
1515e922d83e76f016558617603129b21c70bf7d0e5dc9e68fe332e295b65876eb9a12fe6fca9f1a1c\
1516e80204646bf99b5771d249a6fea627
1517
1518 X = 85322d6ea73083064376099ca2f65f56e8522d9b
1519 Y = 21f8690f717c9f4dcb8f4b6971de2f15b9231fcf41b7eeb997d781f240bfdddfd2090d\
152022083c26cca39bf37c9caf1ec89518ea64845a50d747b49131ffff6a2fd11ea7bacbb93c7d0513\
15217383a06365af82225dd3713ca5a45006316f53bd12b0e260d5f79795e5a4c9f353f12867a1d320\
15222394673ada8563b71555e53f415254
1523
Mohammed Attia987cc702014-03-12 16:07:21 +02001524 [mod = L=2048, N=224]
1525
1526 P = 904ef8e31e14721910fa0969e77c99b79f190071a86026e37a887a6053960dbfb74390\
1527a6641319fe0af32c4e982934b0f1f4c5bc57534e8e56d77c36f0a99080c0d5bc9022fa34f58922\
152881d7b1009571cb5b35699303f912b276d86b1b0722fc0b1500f0ffb2e4d90867a3bdca181a9734\
1529617a8a9f991aa7c14dec1cf45ceba00600f8425440ed0c3b52c82e3aa831932a98b477da220867\
1530eb2d5e0ca34580b33b1b65e558411ed09c369f4717bf03b551787e13d9e47c267c91c697225265\
1531da157945cd8b32e84fc45b80533265239aa00a2dd3d05f5cb231b7daf724b7ecdce170360a8397\
15322e5be94626273d449f441be300a7345db387bebadad67d8060a7
1533 Q = d7d0a83e84d13032b830ed74a6a88592ec9a4cf42bf37080c6600aad
1534 G = 2050b18d3c9f39fac396c009310d6616f9309b67b59aef9aee813d6b4f12ee29ba8a6b\
1535350b11d4336d44b4641230002d870f1e6b1d8728bdd40262df0d2440999185ae077f7034c61679\
1536f4360fbb5d181569e7cb8acb04371c11ba55f1bbd777b74304b99b66d4405303e7120dc8bc4785\
1537f56e9533e65b63a0c77cce7bba0d5d6069df5edffa927c5a255a09405a008258ed93506a843366\
15382154f6f67e922d7c9788f04d4ec09581063950d9cde8e373ea59a58b2a6df6ba8663345574fabb\
1539a9ca981696d83aeac1f34f14f1a813ba900b3f0341dea23f7d3297f919a97e1ae00ac0728c93fe\
15400a88b66591baf4eb0bc6900f39ba5feb41cbbeea7eb7919aa4d3
1541
1542 X = 3f19424da3b4f0cafca3fc5019fcd225dd7e496ffdf6b77e364f45be
1543 Y = 7681ed0ac257ab7ff17c52de4638c0614749792707a0c0d23883697e34963df15c806f\
1544a6206f7fafb3269018e7703bd1e6f518d13544331a017713dbbe0cee8da6c095271fbf24edb74a\
154544e18b1d3b835622f68d31921c67c83e8479d1972ed0cb106c68188fe22c044254251ebf880b90\
154649dc3b7958ef61e1e67d2f677d2a7d2ab6b7c42b70cc5dedc3e5de7459a2dbc70c69008553d7ff\
1547b6bf81c012c8bd67bdddeaab9a4a4373027912a7c7d9cd9cfc6c81dffe0cc7a6d40c3b2065aee7\
1548be80e3c35497d64c8045bc511edaf7314c84c56bd9f0fecf62262ea5b45b49a0cffb223713bdbd\
15493ad03a25a0bb2211eba41ffcd08ab0e1ad485c29a3fc25ee8359
1550
1551 X = 241396352dd26efe0e2e184da52fe2b61d9d51b91b5009674c447854
1552 Y = 2f07a3aa9884c65288e5fef56c7b7f4445632273290bae6fcaab87c90058b2bef81ad3\
155334958657cf649ffb976d618b34ce69ef6d68c0d8bfe275cf097a301e8dd5595958e0c668c15f67\
1554b5c0b0d01983057ce61593635aab5e0564ed720b0336f055a86755c76be22df3b8487f16e2ba0b\
15555136fd30d7e3b1d30c3bd298d3acc0a1988a11756c94e9a53184d0d3edfbb649caf03eace3083d\
1556e9933921e627f4b2e011d1c79e45d8ea1eb7e4e59a1cbd8382b3238474eb949749c985200fbb25\
155741e2dce080aa881945d4d935076e48a0846dc5513bb4da8563b946af54f546455931e79c065ce7\
1558ca223a98f8fde40091d38eb2c3eb8e3b81d88374f3146b0afc42
1559
Mohammed Attia2da00132014-03-13 15:07:20 +02001560 [mod = L=2048, N=256]
Mohammed Attia987cc702014-03-12 16:07:21 +02001561
1562 P = ea1fb1af22881558ef93be8a5f8653c5a559434c49c8c2c12ace5e9c41434c9cf0a8e9\
1563498acb0f4663c08b4484eace845f6fb17dac62c98e706af0fc74e4da1c6c2b3fbf5a1d58ff82fc\
15641a66f3e8b12252c40278fff9dd7f102eed2cb5b7323ebf1908c234d935414dded7f8d244e54561\
1565b0dca39b301de8c49da9fb23df33c6182e3f983208c560fb5119fbf78ebe3e6564ee235c6a15cb\
1566b9ac247baba5a423bc6582a1a9d8a2b4f0e9e3d9dbac122f750dd754325135257488b1f6ecabf2\
15671bff2947fe0d3b2cb7ffe67f4e7fcdf1214f6053e72a5bb0dd20a0e9fe6db2df0a908c36e95e60\
1568bf49ca4368b8b892b9c79f61ef91c47567c40e1f80ac5aa66ef7
1569 Q = 8ec73f3761caf5fdfe6e4e82098bf10f898740dcb808204bf6b18f507192c19d
1570 G = e4c4eca88415b23ecf811c96e48cd24200fe916631a68a684e6ccb6b1913413d344d1d\
15718d84a333839d88eee431521f6e357c16e6a93be111a98076739cd401bab3b9d565bf4fb99e9d18\
15725b1e14d61c93700133f908bae03e28764d107dcd2ea7674217622074bb19efff482f5f5c1a86d5\
1573551b2fc68d1c6e9d8011958ef4b9c2a3a55d0d3c882e6ad7f9f0f3c61568f78d0706b10a26f23b\
15744f197c322b825002284a0aca91807bba98ece912b80e10cdf180cf99a35f210c1655fbfdd74f13\
1575b1b5046591f8403873d12239834dd6c4eceb42bf7482e1794a1601357b629ddfa971f2ed273b14\
15766ec1ca06d0adf55dd91d65c37297bda78c6d210c0bc26e558302
1577
1578 X = 405772da6e90d809e77d5de796562a2dd4dfd10ef00a83a3aba6bd818a0348a1
1579 Y = 6b32e31ab9031dc4dd0b5039a78d07826687ab087ae6de4736f5b0434e1253092e8a0b\
1580231f9c87f3fc8a4cb5634eb194bf1b638b7a7889620ce6711567e36aa36cda4604cfaa601a4591\
15818371d4ccf68d8b10a50a0460eb1dc0fff62ef5e6ee4d473e18ea4a66c196fb7e677a49b48241a0\
1582b4a97128eff30fa437050501a584f8771e7280d26d5af30784039159c11ebfea10b692fd0a5821\
15835eeb18bff117e13f08db792ed4151a218e4bed8dddfb0793225bd1e9773505166f4bd8cedbb286\
1584ea28232972da7bae836ba97329ba6b0a36508e50a52a7675e476d4d4137eae13f22a9d2fefde70\
15858ba8f34bf336c6e76331761e4b0617633fe7ec3f23672fb19d27
1586
1587 X = 0e0b95e31fda3f888059c46c3002ef8f2d6be112d0209aeb9e9545da67aeea80
1588 Y = 778082b77ddba6f56597cc74c3a612abf2ddbd85cc81430c99ab843c1f630b9db01399\
158965f563978164f9bf3a8397256be714625cd41cd7fa0067d94ea66d7e073f7125af692ad01371d4\
1590a17f4550590378f2b074030c20e36911598a1018772f61be3b24de4be5a388ccc09e15a92819c3\
15911dec50de9fde105b49eaa097b9d13d9219eeb33b628facfd1c78a7159c8430d0647c506e7e3de7\
15924763cb351eada72c00bef3c9641881e6254870c1e6599f8ca2f1bbb74f39a905e3a34e4544168e\
15936e50c9e3305fd09cab6ed4aff6fda6e0d5bf375c81ac9054406d9193b003c89272f1bd83d48250\
1594134b65c77c2b6332d38d34d9016f0e8975536ad6c348a1faedb0
1595
Mohammed Attia2da00132014-03-13 15:07:20 +02001596 [mod = L=3072, N=256]
1597
1598 P = f335666dd1339165af8b9a5e3835adfe15c158e4c3c7bd53132e7d5828c352f593a9a7\
159987760ce34b789879941f2f01f02319f6ae0b756f1a842ba54c85612ed632ee2d79ef17f06b77c6\
160041b7b080aff52a03fc2462e80abc64d223723c236deeb7d201078ec01ca1fbc1763139e25099a8\
16014ec389159c409792080736bd7caa816b92edf23f2c351f90074aa5ea2651b372f8b58a0a65554d\
1602b2561d706a63685000ac576b7e4562e262a14285a9c6370b290e4eb7757527d80b6c0fd5df831d\
160336f3d1d35f12ab060548de1605fd15f7c7aafed688b146a02c945156e284f5b71282045aba9844\
1604d48b5df2e9e7a5887121eae7d7b01db7cdf6ff917cd8eb50c6bf1d54f90cce1a491a9c74fea88f\
16057e7230b047d16b5a6027881d6f154818f06e513faf40c8814630e4e254f17a47bfe9cb519b9828\
16069935bf17673ae4c8033504a20a898d0032ee402b72d5986322f3bdfb27400561f7476cd715eaab\
1607b7338b854e51fc2fa026a5a579b6dcea1b1c0559c13d3c1136f303f4b4d25ad5b692229957
1608 Q = d3eba6521240694015ef94412e08bf3cf8d635a455a398d6f210f6169041653b
1609 G = ce84b30ddf290a9f787a7c2f1ce92c1cbf4ef400e3cd7ce4978db2104d7394b493c183\
161032c64cec906a71c3778bd93341165dee8e6cd4ca6f13afff531191194ada55ecf01ff94d6cf7c4\
1611768b82dd29cd131aaf202aefd40e564375285c01f3220af4d70b96f1395420d778228f1461f5d0\
1612b8e47357e87b1fe3286223b553e3fc9928f16ae3067ded6721bedf1d1a01bfd22b9ae85fce7782\
16130d88cdf50a6bde20668ad77a707d1c60fcc5d51c9de488610d0285eb8ff721ff141f93a9fb23c1\
1614d1f7654c07c46e58836d1652828f71057b8aff0b0778ef2ca934ea9d0f37daddade2d823a4d8e3\
161562721082e279d003b575ee59fd050d105dfd71cd63154efe431a0869178d9811f4f231dc5dcf3b\
16160ec0f2b0f9896c32ec6c7ee7d60aa97109e09224907328d4e6acd10117e45774406c4c947da802\
16170649c3168f690e0bd6e91ac67074d1d436b58ae374523deaf6c93c1e6920db4a080b744804bb07\
16183cecfe83fa9398cf150afa286dc7eb7949750cf5001ce104e9187f7e16859afa8fd0d775ae
1619
1620 X = b2764c46113983777d3e7e97589f1303806d14ad9f2f1ef033097de954b17706
1621 Y = 814824e435e1e6f38daa239aad6dad21033afce6a3ebd35c1359348a0f2418871968c2\
1622babfc2baf47742148828f8612183178f126504da73566b6bab33ba1f124c15aa461555c2451d86\
1623c94ee21c3e3fc24c55527e01b1f03adcdd8ec5cb08082803a7b6a829c3e99eeb332a2cf5c035b0\
1624ce0078d3d414d31fa47e9726be2989b8d06da2e6cd363f5a7d1515e3f4925e0b32adeae3025cc5\
1625a996f6fd27494ea408763de48f3bb39f6a06514b019899b312ec570851637b8865cff3a52bf5d5\
16264ad5a19e6e400a2d33251055d0a440b50d53f4791391dc754ad02b9eab74c46b4903f9d76f8243\
162739914db108057af7cde657d41766a99991ac8787694f4185d6f91d7627048f827b405ec67bf2fe\
162856141c4c581d8c317333624e073e5879a82437cb0c7b435c0ce434e15965db1315d64895991e6b\
1629be7dac040c42052408bbc53423fd31098248a58f8a67da3a39895cd0cc927515d044c1e3cb6a32\
163059c3d0da354cce89ea3552c59609db10ee989986527436af21d9485ddf25f90f7dff6d2bae
1631
1632 X = 52e3e040efb30e1befd909a0bdbcfd140d005b1bff094af97186080262f1904d
1633 Y = a5ae6e8f9b7a68ab0516dad4d7b7d002126f811d5a52e3d35c6d387fcb43fd19bf7792\
1634362f9c98f8348aa058bb62376685f3d0c366c520d697fcd8416947151d4bbb6f32b53528a01647\
16359e99d2cd48d1fc679027c15f0042f207984efe05c1796bca8eba678dfdd00b80418e3ea840557e\
163673b09e003882f9a68edba3431d351d1ca07a8150b018fdbdf6c2f1ab475792a3ccaa6594472a45\
1637f8dc777b60bf67de3e0f65c20d11b7d59faedf83fbce52617f500d9e514947c455274c6e900464\
1638767fb56599b81344cf6d12c25cb2b7d038d7b166b6cf30534811c15d0e8ab880a2ac06786ae2dd\
1639de61329a78d526f65245380ce877e979c5b50de66c9c30d66382c8f254653d25a1eb1d3a4897d7\
1640623399b473ce712a2184cf2da1861706c41466806aefe41b497db82aca6c31c8f4aa68c17d1d9e\
1641380b57998917655783ec96e5234a131f7299398d36f1f5f84297a55ff292f1f060958c358fed34\
16426db2de45127ca728a9417b2c54203e33e53b9a061d924395b09afab8daf3e8dd7eedcec3ac
Mohammed Attia987cc702014-03-12 16:07:21 +02001643 """).splitlines()
1644
Mohammed Attia2da00132014-03-13 15:07:20 +02001645 expected = [
1646 {'g': int('06b7861abbd35cc89e79c52f68d20875389b127361ca66822138ce499'
1647 '1d2b862259d6b4548a6495b195aa0e0b6137ca37eb23b94074d3c3d3000'
1648 '42bdf15762812b6333ef7b07ceba78607610fcc9ee68491dbc1e34cd12'
1649 '615474e52b18bc934fb00c61d39e7da8902291c4434a4e2224c3f'
1650 '4fd9f93cd6f4f17fc076341a7e7d9', 16),
1651 'p': int('d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d4b725e'
1652 'f341eabb47cf8a7a8a41e792a156b7ce97206c4f9c5ce6fc5ae791210'
1653 '2b6b502e59050b5b21ce263dddb2044b652236f4d42ab4b5d6aa73189c'
1654 'ef1ace778d7845a5c1c1c7147123188f8dc551054ee162b634d60f097f7'
1655 '19076640e20980a0093113a8bd73', 16),
1656 'q': int('96c5390a8b612c0e422bb2b0ea194a3ec935a281', 16),
1657 'x': int('8185fee9cc7c0e91fd85503274f1cd5a3fd15a49', 16),
1658 'y': int('6f26d98d41de7d871b6381851c9d91fa03942092ab6097e76422'
1659 '070edb71db44ff568280fdb1709f8fc3feab39f1f824adaeb2a29808815'
1660 '6ac31af1aa04bf54f475bdcfdcf2f8a2dd973e922d83e76f01655861760'
1661 '3129b21c70bf7d0e5dc9e68fe332e295b65876eb9a12fe6fca9f1a1ce80'
1662 '204646bf99b5771d249a6fea627', 16)},
1663 {'g': int('06b7861abbd35cc89e79c52f68d20875389b127361ca66822138ce4991d'
1664 '2b862259d6b4548a6495b195aa0e0b6137ca37eb23b94074d3c3d30004'
1665 '2bdf15762812b6333ef7b07ceba78607610fcc9ee68491dbc1e34cd126'
1666 '15474e52b18bc934fb00c61d39e7da8902291c4434a4e2224c3f4fd9'
1667 'f93cd6f4f17fc076341a7e7d9', 16),
1668 'p': int('d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d4b725ef341e'
1669 'abb47cf8a7a8a41e792a156b7ce97206c4f9c5ce6fc5ae7912102b6b50'
1670 '2e59050b5b21ce263dddb2044b652236f4d42ab4b5d6aa73189cef1a'
1671 'ce778d7845a5c1c1c7147123188f8dc551054ee162b634d6'
1672 '0f097f719076640e20980a0093113a8bd73', 16),
1673 'q': int('96c5390a8b612c0e422bb2b0ea194a3ec935a281', 16),
1674 'x': int('85322d6ea73083064376099ca2f65f56e8522d9b', 16),
1675 'y': int('21f8690f717c9f4dcb8f4b6971de2f15b9231fcf41b7eeb997d781f240'
1676 'bfdddfd2090d22083c26cca39bf37c9caf1ec89518ea64845a50d747b49'
1677 '131ffff6a2fd11ea7bacbb93c7d05137383a06365af82225dd3713c'
1678 'a5a45006316f53bd12b0e260d5f79795e5a4c9f353f12867a1d3'
1679 '202394673ada8563b71555e53f415254', 16)},
Mohammed Attia987cc702014-03-12 16:07:21 +02001680
Mohammed Attia2da00132014-03-13 15:07:20 +02001681 {'g': int('e4c4eca88415b23ecf811c96e48cd24200fe916631a68a684e6ccb6b191'
1682 '3413d344d1d8d84a333839d88eee431521f6e357c16e6a93be111a9807'
1683 '6739cd401bab3b9d565bf4fb99e9d185b1e14d61c93700133f908bae0'
1684 '3e28764d107dcd2ea7674217622074bb19efff482f5f5c1a86d5551b2'
1685 'fc68d1c6e9d8011958ef4b9c2a3a55d0d3c882e6ad7f9f0f3c61568f78'
1686 'd0706b10a26f23b4f197c322b825002284a0aca91807bba98ece912'
1687 'b80e10cdf180cf99a35f210c1655fbfdd74f13b1b5046591f8403873d'
1688 '12239834dd6c4eceb42bf7482e1794a1601357b629ddfa971f2ed273b1'
1689 '46ec1ca06d0adf55dd91d65c37297bda78c6d210c0bc26e558302', 16),
1690 'p': int('ea1fb1af22881558ef93be8a5f8653c5a559434c49c8c2c12ace'
1691 '5e9c41434c9cf0a8e9498acb0f4663c08b4484eace845f6fb17d'
1692 'ac62c98e706af0fc74e4da1c6c2b3fbf5a1d58ff82fc1a66f3e8b122'
1693 '52c40278fff9dd7f102eed2cb5b7323ebf1908c234d935414dded7f8d2'
1694 '44e54561b0dca39b301de8c49da9fb23df33c6182e3f983208c560fb5'
1695 '119fbf78ebe3e6564ee235c6a15cbb9ac247baba5a423bc6582a1a9d8a'
1696 '2b4f0e9e3d9dbac122f750dd754325135257488b1f6ecabf21bff2947'
1697 'fe0d3b2cb7ffe67f4e7fcdf1214f6053e72a5bb0dd20a0e9fe6db2df0a'
1698 '908c36e95e60bf49ca4368b8b892b9c79f61ef91c47567c40e1f80ac'
1699 '5aa66ef7', 16),
1700 'q': int('8ec73f3761caf5fdfe6e4e82098bf10f898740dcb808204bf6b1'
1701 '8f507192c19d', 16),
1702 'x': int('405772da6e90d809e77d5de796562a2dd4dfd10ef00a83a3aba6'
1703 'bd818a0348a1', 16),
1704 'y': int('6b32e31ab9031dc4dd0b5039a78d07826687ab087ae6de4736f5'
1705 'b0434e1253092e8a0b231f9c87f3fc8a4cb5634eb194bf1b638'
1706 'b7a7889620ce6711567e36aa36cda4604cfaa601a45918371d'
1707 '4ccf68d8b10a50a0460eb1dc0fff62ef5e6ee4d473e18ea4a6'
1708 '6c196fb7e677a49b48241a0b4a97128eff30fa437050501a584'
1709 'f8771e7280d26d5af30784039159c11ebfea10b692fd0a58215ee'
1710 'b18bff117e13f08db792ed4151a218e4bed8dddfb0793225bd1e97'
1711 '73505166f4bd8cedbb286ea28232972da7bae836ba97329ba6b0a36508'
1712 'e50a52a7675e476d4d4137eae13f22a9d2fefde708ba8f34bf336c6e7'
1713 '6331761e4b0617633fe7ec3f23672fb19d27', 16)},
1714 {'g': int('e4c4eca88415b23ecf811c96e48cd24200fe916631a68a684e6ccb6b191'
1715 '3413d344d1d8d84a333839d88eee431521f6e357c16e6a93be111a9807'
1716 '6739cd401bab3b9d565bf4fb99e9d185b1e14d61c93700133f908bae0'
1717 '3e28764d107dcd2ea7674217622074bb19efff482f5f5c1a86d5551b2'
1718 'fc68d1c6e9d8011958ef4b9c2a3a55d0d3c882e6ad7f9f0f3c61568f78'
1719 'd0706b10a26f23b4f197c322b825002284a0aca91807bba98ece912'
1720 'b80e10cdf180cf99a35f210c1655fbfdd74f13b1b5046591f8403873d'
1721 '12239834dd6c4eceb42bf7482e1794a1601357b629ddfa971f2ed273b1'
1722 '46ec1ca06d0adf55dd91d65c37297bda78c6d210c0bc26e558302', 16),
1723 'p': int('ea1fb1af22881558ef93be8a5f8653c5a559434c49c8c2c12ace'
1724 '5e9c41434c9cf0a8e9498acb0f4663c08b4484eace845f6fb17d'
1725 'ac62c98e706af0fc74e4da1c6c2b3fbf5a1d58ff82fc1a66f3e8b122'
1726 '52c40278fff9dd7f102eed2cb5b7323ebf1908c234d935414dded7f8d2'
1727 '44e54561b0dca39b301de8c49da9fb23df33c6182e3f983208c560fb5'
1728 '119fbf78ebe3e6564ee235c6a15cbb9ac247baba5a423bc6582a1a9d8a'
1729 '2b4f0e9e3d9dbac122f750dd754325135257488b1f6ecabf21bff2947'
1730 'fe0d3b2cb7ffe67f4e7fcdf1214f6053e72a5bb0dd20a0e9fe6db2df0a'
1731 '908c36e95e60bf49ca4368b8b892b9c79f61ef91c47567c40e1f80ac'
1732 '5aa66ef7', 16),
1733 'q': int('8ec73f3761caf5fdfe6e4e82098bf10f898740dcb808204bf6b1'
1734 '8f507192c19d', 16),
1735 'x': int('0e0b95e31fda3f888059c46c3002ef8f2d6be112d0209aeb9e95'
1736 '45da67aeea80', 16),
1737 'y': int('778082b77ddba6f56597cc74c3a612abf2ddbd85cc81430c99ab'
1738 '843c1f630b9db0139965f563978164f9bf3a8397256be714625'
1739 'cd41cd7fa0067d94ea66d7e073f7125af692ad01371d4a17f45'
1740 '50590378f2b074030c20e36911598a1018772f61be3b24de4be'
1741 '5a388ccc09e15a92819c31dec50de9fde105b49eaa097b9d13d'
1742 '9219eeb33b628facfd1c78a7159c8430d0647c506e7e3de74763c'
1743 'b351eada72c00bef3c9641881e6254870c1e6599f8ca2f1bbb74f'
1744 '39a905e3a34e4544168e6e50c9e3305fd09cab6ed4aff6fda6e0d'
1745 '5bf375c81ac9054406d9193b003c89272f1bd83d48250134b65c77'
1746 'c2b6332d38d34d9016f0e8975536ad6c348a1faedb0', 16)},
1747
1748 {'g': int('ce84b30ddf290a9f787a7c2f1ce92c1cbf4ef400e3cd7ce4978d'
1749 'b2104d7394b493c18332c64cec906a71c3778bd93341165dee8'
1750 'e6cd4ca6f13afff531191194ada55ecf01ff94d6cf7c4768b82'
1751 'dd29cd131aaf202aefd40e564375285c01f3220af4d70b96f1'
1752 '395420d778228f1461f5d0b8e47357e87b1fe3286223b553e3'
1753 'fc9928f16ae3067ded6721bedf1d1a01bfd22b9ae85fce77820d88cdf'
1754 '50a6bde20668ad77a707d1c60fcc5d51c9de488610d0285eb8ff721f'
1755 'f141f93a9fb23c1d1f7654c07c46e58836d1652828f71057b8aff0b077'
1756 '8ef2ca934ea9d0f37daddade2d823a4d8e362721082e279d003b575ee'
1757 '59fd050d105dfd71cd63154efe431a0869178d9811f4f231dc5dcf3b'
1758 '0ec0f2b0f9896c32ec6c7ee7d60aa97109e09224907328d4e6acd1011'
1759 '7e45774406c4c947da8020649c3168f690e0bd6e91ac67074d1d436b'
1760 '58ae374523deaf6c93c1e6920db4a080b744804bb073cecfe83fa939'
1761 '8cf150afa286dc7eb7949750cf5001ce104e9187f7e16859afa8fd0d'
1762 '775ae', 16),
1763 'p': int('f335666dd1339165af8b9a5e3835adfe15c158e4c3c7bd53132e7d5828'
1764 'c352f593a9a787760ce34b789879941f2f01f02319f6ae0b756f1a842'
1765 'ba54c85612ed632ee2d79ef17f06b77c641b7b080aff52a03fc2462e8'
1766 '0abc64d223723c236deeb7d201078ec01ca1fbc1763139e25099a84ec'
1767 '389159c409792080736bd7caa816b92edf23f2c351f90074aa5ea2651'
1768 'b372f8b58a0a65554db2561d706a63685000ac576b7e4562e262a1428'
1769 '5a9c6370b290e4eb7757527d80b6c0fd5df831d36f3d1d35f12ab0605'
1770 '48de1605fd15f7c7aafed688b146a02c945156e284f5b71282045aba9'
1771 '844d48b5df2e9e7a5887121eae7d7b01db7cdf6ff917cd8eb50c6bf1d'
1772 '54f90cce1a491a9c74fea88f7e7230b047d16b5a6027881d6f154818f'
1773 '06e513faf40c8814630e4e254f17a47bfe9cb519b98289935bf17673a'
1774 'e4c8033504a20a898d0032ee402b72d5986322f3bdfb27400561f7476'
1775 'cd715eaabb7338b854e51fc2fa026a5a579b6dcea1b1c0559c13d3c11'
1776 '36f303f4b4d25ad5b692229957', 16),
1777 'q': int('d3eba6521240694015ef94412e08bf3cf8d635a455a398d6f210'
1778 'f6169041653b', 16),
1779 'x': int('b2764c46113983777d3e7e97589f1303806d14ad9f2f1ef03309'
1780 '7de954b17706', 16),
1781 'y': int('814824e435e1e6f38daa239aad6dad21033afce6a3ebd35c1359348a0f2'
1782 '418871968c2babfc2baf47742148828f8612183178f126504da73566b6'
1783 'bab33ba1f124c15aa461555c2451d86c94ee21c3e3fc24c55527e'
1784 '01b1f03adcdd8ec5cb08082803a7b6a829c3e99eeb332a2cf5c035b0c'
1785 'e0078d3d414d31fa47e9726be2989b8d06da2e6cd363f5a7d1515e3f4'
1786 '925e0b32adeae3025cc5a996f6fd27494ea408763de48f3bb39f6a06'
1787 '514b019899b312ec570851637b8865cff3a52bf5d54ad5a19e6e400'
1788 'a2d33251055d0a440b50d53f4791391dc754ad02b9eab74c46b4903'
1789 'f9d76f824339914db108057af7cde657d41766a99991ac8787694f'
1790 '4185d6f91d7627048f827b405ec67bf2fe56141c4c581d8c317333'
1791 '624e073e5879a82437cb0c7b435c0ce434e15965db1315d648959'
1792 '91e6bbe7dac040c42052408bbc53423fd31098248a58f8a67da3a'
1793 '39895cd0cc927515d044c1e3cb6a3259c3d0da354cce89ea3552c'
1794 '59609db10ee989986527436af21d9485ddf25f90f7dff6d2bae', 16)},
1795 {'g': int('ce84b30ddf290a9f787a7c2f1ce92c1cbf4ef400e3cd7ce4978d'
1796 'b2104d7394b493c18332c64cec906a71c3778bd93341165dee8'
1797 'e6cd4ca6f13afff531191194ada55ecf01ff94d6cf7c4768b82'
1798 'dd29cd131aaf202aefd40e564375285c01f3220af4d70b96f1'
1799 '395420d778228f1461f5d0b8e47357e87b1fe3286223b553e3'
1800 'fc9928f16ae3067ded6721bedf1d1a01bfd22b9ae85fce77820d88cdf'
1801 '50a6bde20668ad77a707d1c60fcc5d51c9de488610d0285eb8ff721f'
1802 'f141f93a9fb23c1d1f7654c07c46e58836d1652828f71057b8aff0b077'
1803 '8ef2ca934ea9d0f37daddade2d823a4d8e362721082e279d003b575ee'
1804 '59fd050d105dfd71cd63154efe431a0869178d9811f4f231dc5dcf3b'
1805 '0ec0f2b0f9896c32ec6c7ee7d60aa97109e09224907328d4e6acd1011'
1806 '7e45774406c4c947da8020649c3168f690e0bd6e91ac67074d1d436b'
1807 '58ae374523deaf6c93c1e6920db4a080b744804bb073cecfe83fa939'
1808 '8cf150afa286dc7eb7949750cf5001ce104e9187f7e16859afa8fd0d'
1809 '775ae', 16),
1810 'p': int('f335666dd1339165af8b9a5e3835adfe15c158e4c3c7bd53132e7d5828'
1811 'c352f593a9a787760ce34b789879941f2f01f02319f6ae0b756f1a842'
1812 'ba54c85612ed632ee2d79ef17f06b77c641b7b080aff52a03fc2462e8'
1813 '0abc64d223723c236deeb7d201078ec01ca1fbc1763139e25099a84ec'
1814 '389159c409792080736bd7caa816b92edf23f2c351f90074aa5ea2651'
1815 'b372f8b58a0a65554db2561d706a63685000ac576b7e4562e262a1428'
1816 '5a9c6370b290e4eb7757527d80b6c0fd5df831d36f3d1d35f12ab0605'
1817 '48de1605fd15f7c7aafed688b146a02c945156e284f5b71282045aba9'
1818 '844d48b5df2e9e7a5887121eae7d7b01db7cdf6ff917cd8eb50c6bf1d'
1819 '54f90cce1a491a9c74fea88f7e7230b047d16b5a6027881d6f154818f'
1820 '06e513faf40c8814630e4e254f17a47bfe9cb519b98289935bf17673a'
1821 'e4c8033504a20a898d0032ee402b72d5986322f3bdfb27400561f7476'
1822 'cd715eaabb7338b854e51fc2fa026a5a579b6dcea1b1c0559c13d3c11'
1823 '36f303f4b4d25ad5b692229957', 16),
1824 'q': int('d3eba6521240694015ef94412e08bf3cf8d635a455a398d6f210'
1825 'f6169041653b', 16),
1826 'x': int('52e3e040efb30e1befd909a0bdbcfd140d005b1bff094af97186'
1827 '080262f1904d', 16),
1828 'y': int('a5ae6e8f9b7a68ab0516dad4d7b7d002126f811d5a52e3d35c6d'
1829 '387fcb43fd19bf7792362f9c98f8348aa058bb62376685f3d0c3'
1830 '66c520d697fcd8416947151d4bbb6f32b53528a016479e99d2cd'
1831 '48d1fc679027c15f0042f207984efe05c1796bca8eba678dfdd0'
1832 '0b80418e3ea840557e73b09e003882f9a68edba3431d351d1ca0'
1833 '7a8150b018fdbdf6c2f1ab475792a3ccaa6594472a45f8dc777b'
1834 '60bf67de3e0f65c20d11b7d59faedf83fbce52617f500d9e5149'
1835 '47c455274c6e900464767fb56599b81344cf6d12c25cb2b7d038'
1836 'd7b166b6cf30534811c15d0e8ab880a2ac06786ae2ddde61329a'
1837 '78d526f65245380ce877e979c5b50de66c9c30d66382c8f25465'
1838 '3d25a1eb1d3a4897d7623399b473ce712a2184cf2da1861706c4'
1839 '1466806aefe41b497db82aca6c31c8f4aa68c17d1d9e380b5799'
1840 '8917655783ec96e5234a131f7299398d36f1f5f84297a55ff292'
1841 'f1f060958c358fed346db2de45127ca728a9417b2c54203e33e5'
1842 '3b9a061d924395b09afab8daf3e8dd7eedcec3ac', 16)}
1843 ]
Mohammed Attia987cc702014-03-12 16:07:21 +02001844
1845 assert expected == load_fips_dsa_key_pair_vectors(vector_data)
Alex Stapletona39a3192014-03-14 20:03:12 +00001846
1847
Mohammed Attia0fb5d852014-04-21 10:31:15 +02001848def test_load_fips_dsa_sig_ver_vectors():
1849 vector_data = textwrap.dedent("""
1850 # CAVS 11.0
1851 # "SigVer" information
1852 # Mod sizes selected: SHA-1 L=1024, N=160,SHA-384 L=2048, N=256
1853 # Generated on Fri Apr 01 08:37:15 2011
Alex Stapleton112963e2014-03-26 17:39:29 +00001854
Mohammed Attia0fb5d852014-04-21 10:31:15 +02001855 [mod = L=1024, N=160, SHA-1]
Alex Stapleton112963e2014-03-26 17:39:29 +00001856
Mohammed Attia0fb5d852014-04-21 10:31:15 +02001857 P = dc5bf3a88b2d99e4c95cdd7a0501cc38630d425cf5c390af3429cff1f35147b795cae\
1858a923f0d3577158f8a0c89dabd1962c2c453306b5d70cacfb01430aceb54e5a5fa6f93\
185940d3bd2da612fceeb76b0ec1ebfae635a56ab141b108e00dc76eefe2edd0c514c21c4\
186057457c39065dba9d0ecb7569c247172d8438ad2827b60435b
1861 Q = e956602b83d195dbe945b3ac702fc61f81571f1d
1862 G = d7eb9ca20a3c7a079606bafc4c9261ccaba303a5dc9fe9953f197dfe548c234895baa\
186377f441ee6a2d97b909cbbd26ff7b869d24cae51b5c6edb127a4b5d75cd8b46608bfa1\
186448249dffdb59807c5d7dde3fe3080ca3a2d28312142becb1fa8e24003e21c72871081\
186574b95d5bc711e1c8d9b1076784f5dc37a964a5e51390da713
Alex Stapleton112963e2014-03-26 17:39:29 +00001866
Mohammed Attia0fb5d852014-04-21 10:31:15 +02001867 Msg = 0fe1bfee500bdb76026099b1d37553f6bdfe48c82094ef98cb309dd777330bedfaa\
18682f94c823ef74ef4074b50d8706041ac0e371c7c22dcf70263b8d60e17a86c7c379c\
1869fda8f22469e0df9d49d59439fc99891873628fff25dda5fac5ac794e948babdde96\
18708143ba05f1128f34fdad5875edc4cd71c6c24ba2060ffbd439ce2b3
1871 X = 1d93010c29ecfc432188942f46f19f44f0e1bb5d
1872 Y = 6240ea0647117c38fe705106d56db578f3e10130928452d4f3587881b8a2bc6873a8b\
1873efc3237f20914e2a91c7f07a928ee22adeed23d74ab7f82ea11f70497e578f7a9b4cb\
1874d6f10226222b0b4da2ea1e49813d6bb9882fbf675c0846bb80cc891857b89b0ef1beb\
18756cce3378a9aab5d66ad4cb9277cf447dfe1e64434749432fb
1876 R = b5af307867fb8b54390013cc67020ddf1f2c0b81
1877 S = 620d3b22ab5031440c3e35eab6f481298f9e9f08
1878 Result = P
Alex Stapleton5e4c8c32014-03-27 16:38:00 +00001879
Mohammed Attia0fb5d852014-04-21 10:31:15 +02001880 Msg = 97d50898025d2f9ba633866e968ca75e969d394edba6517204cb3dd537c2ba38778\
1881a2dc9dbc685a915e5676fcd43bc3726bc59ce3d7a9fae35565082a069c139fa37c9\
18820d922b126933db3fa6c5ef6b1edf00d174a51887bb76909c6a94fe994ecc7b7fc8f\
188326113b17f30f9d01693df99a125b4f17e184331c6b6e8ca00f54f3a
1884 X = 350e13534692a7e0c4b7d58836046c436fbb2322
1885 Y = 69974de550fe6bd3099150faea1623ad3fb6d9bf23a07215093f319725ad0877accff\
1886d291b6da18eb0cbe51676ceb0977504eb97c27c0b191883f72fb2710a9fbd8bcf13be\
18870bf854410b32f42b33ec89d3cc1cf892bcd536c4195ca9ada302ad600c3408739935d\
188877dc247529ca47f844cc86f5016a2fe962c6e20ca7c4d4e8f
1889 R = b5d05faa7005764e8dae0327c5bf1972ff7681b9
1890 S = 18ea15bd9f00475b25204cbc23f8c23e01588015
1891 Result = F (3 - R changed )
Alex Stapleton5e4c8c32014-03-27 16:38:00 +00001892
Paul Kehrer7ef2f8f2014-04-22 08:37:58 -05001893 [mod = L=2048, N=224, SHA-1]
1894
1895 # unsupported so we ignore this
1896
1897 Msg = f9d01693df99a125b4f17e184331c6b6e8ca00f54f3a
1898 X = e0c4b7d58836046c436fbb2322
1899 Y = fb6d9bf23a07215093f319725ad0877accff
1900 R = 5764e8dae0327c5bf1972ff7681b9
1901 S = 475b25204cbc23f8c23e01588015
1902 Result = F (3 - R changed )
1903
Mohammed Attia0fb5d852014-04-21 10:31:15 +02001904 [mod = L=2048, N=256, SHA-384]
Alex Stapleton5e4c8c32014-03-27 16:38:00 +00001905
Mohammed Attia0fb5d852014-04-21 10:31:15 +02001906 P = e7c1c86125db9ef417da1ced7ea0861bdad629216a3f3c745df42a46b989e59f4d984\
190725ee3c932fa3c2b6f637bdb6545bec526faa037e11f5578a4363b9fca5eba60d6a9cb\
1908aa2befd04141d989c7356285132c2eaf74f2d868521cdc0a17ae9a2546ef863027d3f\
19098cc7949631fd0e2971417a912c8b8c5c989730db6ea6e8baee0e667850429038093c8\
191051ccb6fb173bb081e0efe0bd7450e0946888f89f75e443ab93ef2da293a01622cf43c\
19116dd79625d41ba8f9ef7e3086ab39134283d8e96c89249488120fd061e4a87d34af410\
191269c0b4fd3934c31b589cbe85b68b912718d5dab859fda7082511fad1d152044905005\
1913546e19b14aa96585a55269bf2b831
1914 Q = 8e056ec9d4b7acb580087a6ed9ba3478711bb025d5b8d9c731ef9b38bd43db2f
1915 G = dc2bfb9776786ad310c8b0cdcbba3062402613c67e6959a8d8d1b05aab636528b7b1f\
1916e9cd33765f853d6dbe13d09f2681f8c7b1ed7886aaed70c7bd76dbe858ffb8bd86235\
1917ddf759244678f428c6519af593dc94eeadbd9852ba2b3d61664e8d58c29d2039af3c3\
1918d6d16f90988f6a8c824569f3d48050e30896a9e17cd0232ef01ab8790008f6973b84c\
1919763a72f4ae8b485abfb7e8efeb86808fa2b281d3e5d65d28f5992a34c077c5aa8026c\
1920b2fbc34a45f7e9bd216b10e6f12ecb172e9a6eb8f2e91316905b6add1fd22e83bc2f0\
192189f1d5e6a6e6707c18ff55ddcb7954e8bceaf0efc4e8314910c03b0e51175f344faaf\
1922ee476a373ac95743cec712b72cf2e
Alex Stapleton5e4c8c32014-03-27 16:38:00 +00001923
Mohammed Attia0fb5d852014-04-21 10:31:15 +02001924 Msg = 6cd6ccfd66bcd832189c5f0c77994210e3bf2c43416f0fe77c4e92f31c5369538dc\
19252c003f146c5ac79df43194ccf3c44d470d9f1083bd15b99b5bcf88c32d8a9021f09\
1926ea2288d7b3bf345a12aef3949c1e121b9fb371a67c2d1377364206ac839dd784835\
192761426bda0303f285aa12e9c45d3cdfc6beae3549703b187deeb3296
1928 X = 56c897b5938ad5b3d437d7e4826da586a6b3be15e893fa1aaa946f20a028b6b3
1929 Y = 38ad44489e1a5778b9689f4dcf40e2acf23840fb954e987d6e8cb629106328ac64e1f\
19303c3eba48b21176ad4afe3b733bead382ee1597e1b83e4b43424f2daaba04e5bd79e14\
193136693ac2bddb79a298f026e57e200a252efd1e848a4a2e90be6e78f5242b468b9c0c6\
1932d2615047a5a40b9ae7e57a519114db55bf3bed65e580f894b094630ca9c217f6accd0\
193391e72d2f22da620044ff372d7273f9445017fad492959e59600b7494dbe766a03e401\
193425d4e6747c76f68a5b0cdc0e7d7cee12d08c6fb7d0fb049e420a33405075ed4463296\
1935345ca695fb7feab7c1b5333ae519fcd4bb6a043f4555378969114743d4face96cad31\
1936c0e0089da4e3f61b6d7dabc088ab7
1937 R = 3b85b17be240ed658beb3652c9d93e8e9eea160d35ee2459614305802963374e
1938 S = 726800a5174a53b56dce86064109c0273cd11fcfa3c92c5cd6aa910260c0e3c7
1939 Result = F (1 - Message changed)
Alex Stapleton5e4c8c32014-03-27 16:38:00 +00001940
Mohammed Attia0fb5d852014-04-21 10:31:15 +02001941 Msg = 3ad6b0884f358dea09c31a9abc40c45a6000611fc2b907b30eac00413fd2819de70\
194215488a411609d46c499b8f7afa1b78b352ac7f8535bd805b8ff2a5eae557098c668\
1943f7ccd73af886d6823a6d456c29931ee864ed46d767382785728c2a83fcff5271007\
1944d2a67d06fa205fd7b9d1a42ea5d6dc76e5e18a9eb148cd1e8b262ae
1945 X = 2faf566a9f057960f1b50c69508f483d9966d6e35743591f3a677a9dc40e1555
1946 Y = 926425d617babe87c442b03903e32ba5bbf0cd9d602b59c4df791a4d64a6d4333ca0c\
19470d370552539197d327dcd1bbf8c454f24b03fc7805f862db34c7b066ddfddbb11dbd0\
194810b27123062d028fe041cb56a2e77488348ae0ab6705d87aac4d4e9e6600e9e706326\
1949d9979982cffa839beb9eacc3963bcca455a507e80c1c37ad4e765b2c9c0477a075e9b\
1950c584feacdf3a35a9391d4711f14e197c54022282bfed9a191213d64127f17a9c5affe\
1951c26e0c71f15d3a5b16098fec118c45bf8bb2f3b1560df0949254c1c0aeb0a16d5a95a\
195240fab8521fbe8ea77c51169b587cc3360e5733e6a23b9fded8c40724ea1f9e93614b3\
1953a6c9b4f8dbbe915b794497227ba62
1954 R = 343ea0a9e66277380f604d5880fca686bffab69ca97bfba015a102a7e23dce0e
1955 S = 6258488c770e0f5ad7b9da8bade5023fc0d17c6ec517bd08d53e6dc01ac5c2b3
1956 Result = P
1957 """).splitlines()
Alex Stapleton112963e2014-03-26 17:39:29 +00001958
Mohammed Attia0fb5d852014-04-21 10:31:15 +02001959 expected = [
1960 {
1961 'p': int('dc5bf3a88b2d99e4c95cdd7a0501cc38630d425cf5c390af3429cff1'
1962 'f35147b795caea923f0d3577158f8a0c89dabd1962c2c453306b5d70'
1963 'cacfb01430aceb54e5a5fa6f9340d3bd2da612fceeb76b0ec1ebfae6'
1964 '35a56ab141b108e00dc76eefe2edd0c514c21c457457c39065dba9d0'
1965 'ecb7569c247172d8438ad2827b60435b', 16),
1966 'q': int('e956602b83d195dbe945b3ac702fc61f81571f1d', 16),
1967 'g': int('d7eb9ca20a3c7a079606bafc4c9261ccaba303a5dc9fe9953f197dfe'
1968 '548c234895baa77f441ee6a2d97b909cbbd26ff7b869d24cae51b5c6'
1969 'edb127a4b5d75cd8b46608bfa148249dffdb59807c5d7dde3fe3080c'
1970 'a3a2d28312142becb1fa8e24003e21c7287108174b95d5bc711e1c8d'
1971 '9b1076784f5dc37a964a5e51390da713', 16),
1972 'digest_algorithm': 'SHA-1',
1973 'msg': binascii.unhexlify(
1974 b'0fe1bfee500bdb76026099b1d37553f6bdfe48c82094ef98cb309dd77733'
1975 b'0bedfaa2f94c823ef74ef4074b50d8706041ac0e371c7c22dcf70263b8d6'
1976 b'0e17a86c7c379cfda8f22469e0df9d49d59439fc99891873628fff25dda5'
1977 b'fac5ac794e948babdde968143ba05f1128f34fdad5875edc4cd71c6c24ba'
1978 b'2060ffbd439ce2b3'),
1979 'x': int('1d93010c29ecfc432188942f46f19f44f0e1bb5d', 16),
1980 'y': int('6240ea0647117c38fe705106d56db578f3e10130928452d4f3587881'
1981 'b8a2bc6873a8befc3237f20914e2a91c7f07a928ee22adeed23d74ab'
1982 '7f82ea11f70497e578f7a9b4cbd6f10226222b0b4da2ea1e49813d6b'
1983 'b9882fbf675c0846bb80cc891857b89b0ef1beb6cce3378a9aab5d66'
1984 'ad4cb9277cf447dfe1e64434749432fb', 16),
1985 'r': int('b5af307867fb8b54390013cc67020ddf1f2c0b81', 16),
1986 's': int('620d3b22ab5031440c3e35eab6f481298f9e9f08', 16),
1987 'result': 'P'},
1988 {
1989 'p': int('dc5bf3a88b2d99e4c95cdd7a0501cc38630d425cf5c390af3429cff1'
1990 'f35147b795caea923f0d3577158f8a0c89dabd1962c2c453306b5d70'
1991 'cacfb01430aceb54e5a5fa6f9340d3bd2da612fceeb76b0ec1ebfae6'
1992 '35a56ab141b108e00dc76eefe2edd0c514c21c457457c39065dba9d0'
1993 'ecb7569c247172d8438ad2827b60435b', 16),
1994 'q': int('e956602b83d195dbe945b3ac702fc61f81571f1d', 16),
1995 'g': int('d7eb9ca20a3c7a079606bafc4c9261ccaba303a5dc9fe9953f197dfe'
1996 '548c234895baa77f441ee6a2d97b909cbbd26ff7b869d24cae51b5c6'
1997 'edb127a4b5d75cd8b46608bfa148249dffdb59807c5d7dde3fe3080c'
1998 'a3a2d28312142becb1fa8e24003e21c7287108174b95d5bc711e1c8d'
1999 '9b1076784f5dc37a964a5e51390da713', 16),
2000 'digest_algorithm': 'SHA-1',
2001 'msg': binascii.unhexlify(
2002 b'97d50898025d2f9ba633866e968ca75e969d394edba6517204cb3dd537c2'
2003 b'ba38778a2dc9dbc685a915e5676fcd43bc3726bc59ce3d7a9fae35565082'
2004 b'a069c139fa37c90d922b126933db3fa6c5ef6b1edf00d174a51887bb7690'
2005 b'9c6a94fe994ecc7b7fc8f26113b17f30f9d01693df99a125b4f17e184331'
2006 b'c6b6e8ca00f54f3a'),
2007 'x': int('350e13534692a7e0c4b7d58836046c436fbb2322', 16),
2008 'y': int('69974de550fe6bd3099150faea1623ad3fb6d9bf23a07215093f3197'
2009 '25ad0877accffd291b6da18eb0cbe51676ceb0977504eb97c27c0b19'
2010 '1883f72fb2710a9fbd8bcf13be0bf854410b32f42b33ec89d3cc1cf8'
2011 '92bcd536c4195ca9ada302ad600c3408739935d77dc247529ca47f84'
2012 '4cc86f5016a2fe962c6e20ca7c4d4e8f', 16),
2013 'r': int('b5d05faa7005764e8dae0327c5bf1972ff7681b9', 16),
2014 's': int('18ea15bd9f00475b25204cbc23f8c23e01588015', 16),
2015 'result': 'F'},
2016 {
2017 'p': int('e7c1c86125db9ef417da1ced7ea0861bdad629216a3f3c745df42a4'
2018 '6b989e59f4d98425ee3c932fa3c2b6f637bdb6545bec526faa037e1'
2019 '1f5578a4363b9fca5eba60d6a9cbaa2befd04141d989c7356285132'
2020 'c2eaf74f2d868521cdc0a17ae9a2546ef863027d3f8cc7949631fd0'
2021 'e2971417a912c8b8c5c989730db6ea6e8baee0e667850429038093c'
2022 '851ccb6fb173bb081e0efe0bd7450e0946888f89f75e443ab93ef2d'
2023 'a293a01622cf43c6dd79625d41ba8f9ef7e3086ab39134283d8e96c'
2024 '89249488120fd061e4a87d34af41069c0b4fd3934c31b589cbe85b6'
2025 '8b912718d5dab859fda7082511fad1d152044905005546e19b14aa9'
2026 '6585a55269bf2b831', 16),
2027 'q': int('8e056ec9d4b7acb580087a6ed9ba3478711bb025d5b8d9c731ef9b3'
2028 '8bd43db2f', 16),
2029 'g': int('dc2bfb9776786ad310c8b0cdcbba3062402613c67e6959a8d8d1b05'
2030 'aab636528b7b1fe9cd33765f853d6dbe13d09f2681f8c7b1ed7886a'
2031 'aed70c7bd76dbe858ffb8bd86235ddf759244678f428c6519af593d'
2032 'c94eeadbd9852ba2b3d61664e8d58c29d2039af3c3d6d16f90988f6'
2033 'a8c824569f3d48050e30896a9e17cd0232ef01ab8790008f6973b84'
2034 'c763a72f4ae8b485abfb7e8efeb86808fa2b281d3e5d65d28f5992a'
2035 '34c077c5aa8026cb2fbc34a45f7e9bd216b10e6f12ecb172e9a6eb8'
2036 'f2e91316905b6add1fd22e83bc2f089f1d5e6a6e6707c18ff55ddcb'
2037 '7954e8bceaf0efc4e8314910c03b0e51175f344faafee476a373ac9'
2038 '5743cec712b72cf2e', 16),
2039 'digest_algorithm': 'SHA-384',
2040 'msg': binascii.unhexlify(
2041 b'6cd6ccfd66bcd832189c5f0c77994210e3bf2c43416f0fe77c4e92f31c5'
2042 b'369538dc2c003f146c5ac79df43194ccf3c44d470d9f1083bd15b99b5bc'
2043 b'f88c32d8a9021f09ea2288d7b3bf345a12aef3949c1e121b9fb371a67c2'
2044 b'd1377364206ac839dd78483561426bda0303f285aa12e9c45d3cdfc6bea'
2045 b'e3549703b187deeb3296'),
2046 'x': int('56c897b5938ad5b3d437d7e4826da586a6b3be15e893fa1aaa946f2'
2047 '0a028b6b3', 16),
2048 'y': int('38ad44489e1a5778b9689f4dcf40e2acf23840fb954e987d6e8cb62'
2049 '9106328ac64e1f3c3eba48b21176ad4afe3b733bead382ee1597e1b'
2050 '83e4b43424f2daaba04e5bd79e1436693ac2bddb79a298f026e57e2'
2051 '00a252efd1e848a4a2e90be6e78f5242b468b9c0c6d2615047a5a40'
2052 'b9ae7e57a519114db55bf3bed65e580f894b094630ca9c217f6accd'
2053 '091e72d2f22da620044ff372d7273f9445017fad492959e59600b74'
2054 '94dbe766a03e40125d4e6747c76f68a5b0cdc0e7d7cee12d08c6fb7'
2055 'd0fb049e420a33405075ed4463296345ca695fb7feab7c1b5333ae5'
2056 '19fcd4bb6a043f4555378969114743d4face96cad31c0e0089da4e3'
2057 'f61b6d7dabc088ab7', 16),
2058 'r': int('3b85b17be240ed658beb3652c9d93e8e9eea160d35ee24596143058'
2059 '02963374e', 16),
2060 's': int('726800a5174a53b56dce86064109c0273cd11fcfa3c92c5cd6aa910'
2061 '260c0e3c7', 16),
2062 'result': 'F'},
2063 {
2064 'p': int('e7c1c86125db9ef417da1ced7ea0861bdad629216a3f3c745df42a4'
2065 '6b989e59f4d98425ee3c932fa3c2b6f637bdb6545bec526faa037e1'
2066 '1f5578a4363b9fca5eba60d6a9cbaa2befd04141d989c7356285132'
2067 'c2eaf74f2d868521cdc0a17ae9a2546ef863027d3f8cc7949631fd0'
2068 'e2971417a912c8b8c5c989730db6ea6e8baee0e667850429038093c'
2069 '851ccb6fb173bb081e0efe0bd7450e0946888f89f75e443ab93ef2d'
2070 'a293a01622cf43c6dd79625d41ba8f9ef7e3086ab39134283d8e96c'
2071 '89249488120fd061e4a87d34af41069c0b4fd3934c31b589cbe85b6'
2072 '8b912718d5dab859fda7082511fad1d152044905005546e19b14aa9'
2073 '6585a55269bf2b831', 16),
2074 'q': int('8e056ec9d4b7acb580087a6ed9ba3478711bb025d5b8d9c731ef9b3'
2075 '8bd43db2f', 16),
2076 'g': int('dc2bfb9776786ad310c8b0cdcbba3062402613c67e6959a8d8d1b05'
2077 'aab636528b7b1fe9cd33765f853d6dbe13d09f2681f8c7b1ed7886a'
2078 'aed70c7bd76dbe858ffb8bd86235ddf759244678f428c6519af593d'
2079 'c94eeadbd9852ba2b3d61664e8d58c29d2039af3c3d6d16f90988f6'
2080 'a8c824569f3d48050e30896a9e17cd0232ef01ab8790008f6973b84'
2081 'c763a72f4ae8b485abfb7e8efeb86808fa2b281d3e5d65d28f5992a'
2082 '34c077c5aa8026cb2fbc34a45f7e9bd216b10e6f12ecb172e9a6eb8'
2083 'f2e91316905b6add1fd22e83bc2f089f1d5e6a6e6707c18ff55ddcb'
2084 '7954e8bceaf0efc4e8314910c03b0e51175f344faafee476a373ac9'
2085 '5743cec712b72cf2e', 16),
2086 'digest_algorithm': 'SHA-384',
2087 'msg': binascii.unhexlify(
2088 b'3ad6b0884f358dea09c31a9abc40c45a6000611fc2b907b30eac00413fd'
2089 b'2819de7015488a411609d46c499b8f7afa1b78b352ac7f8535bd805b8ff'
2090 b'2a5eae557098c668f7ccd73af886d6823a6d456c29931ee864ed46d7673'
2091 b'82785728c2a83fcff5271007d2a67d06fa205fd7b9d1a42ea5d6dc76e5e'
2092 b'18a9eb148cd1e8b262ae'),
2093 'x': int('2faf566a9f057960f1b50c69508f483d9966d6e35743591f3a677a9'
2094 'dc40e1555', 16),
2095 'y': int('926425d617babe87c442b03903e32ba5bbf0cd9d602b59c4df791a4d'
2096 '64a6d4333ca0c0d370552539197d327dcd1bbf8c454f24b03fc7805f'
2097 '862db34c7b066ddfddbb11dbd010b27123062d028fe041cb56a2e774'
2098 '88348ae0ab6705d87aac4d4e9e6600e9e706326d9979982cffa839be'
2099 'b9eacc3963bcca455a507e80c1c37ad4e765b2c9c0477a075e9bc584'
2100 'feacdf3a35a9391d4711f14e197c54022282bfed9a191213d64127f1'
2101 '7a9c5affec26e0c71f15d3a5b16098fec118c45bf8bb2f3b1560df09'
2102 '49254c1c0aeb0a16d5a95a40fab8521fbe8ea77c51169b587cc3360e'
2103 '5733e6a23b9fded8c40724ea1f9e93614b3a6c9b4f8dbbe915b79449'
2104 '7227ba62', 16),
2105 'r': int('343ea0a9e66277380f604d5880fca686bffab69ca97bfba015a102a'
2106 '7e23dce0e', 16),
2107 's': int('6258488c770e0f5ad7b9da8bade5023fc0d17c6ec517bd08d53e6dc'
2108 '01ac5c2b3', 16),
2109 'result': 'P'}
2110 ]
2111
Mohammed Attia3c9e1582014-04-22 14:24:44 +02002112 assert expected == load_fips_dsa_sig_vectors(vector_data)
2113
2114
2115def test_load_fips_dsa_sig_gen_vectors():
2116 vector_data = textwrap.dedent("""
2117 # CAVS 11.2
2118 # "SigGen" information for "dsa2_values"
2119 # Mod sizes selected: SHA-1 L=1024, N=160, SHA-256 L=2048, N=256
2120
2121 [mod = L=1024, N=160, SHA-1]
2122
2123 P = a8f9cd201e5e35d892f85f80e4db2599a5676a3b1d4f190330ed3256b26d0e80a0e49\
2124a8fffaaad2a24f472d2573241d4d6d6c7480c80b4c67bb4479c15ada7ea8424d2502fa01472e7\
212560241713dab025ae1b02e1703a1435f62ddf4ee4c1b664066eb22f2e3bf28bb70a2a76e4fd5eb\
2126e2d1229681b5b06439ac9c7e9d8bde283
2127 Q = f85f0f83ac4df7ea0cdf8f469bfeeaea14156495
2128 G = 2b3152ff6c62f14622b8f48e59f8af46883b38e79b8c74deeae9df131f8b856e3ad6c\
21298455dab87cc0da8ac973417ce4f7878557d6cdf40b35b4a0ca3eb310c6a95d68ce284ad4e25ea\
213028591611ee08b8444bd64b25f3f7c572410ddfb39cc728b9c936f85f419129869929cdb909a6a\
21313a99bbe089216368171bd0ba81de4fe33
2132
2133 Msg = 3b46736d559bd4e0c2c1b2553a33ad3c6cf23cac998d3d0c0e8fa4b19bca06f2f38\
21346db2dcff9dca4f40ad8f561ffc308b46c5f31a7735b5fa7e0f9e6cb512e63d7eea05538d66a75\
2135cd0d4234b5ccf6c1715ccaaf9cdc0a2228135f716ee9bdee7fc13ec27a03a6d11c5c5b3685f51\
2136900b1337153bc6c4e8f52920c33fa37f4e7
2137 Y = 313fd9ebca91574e1c2eebe1517c57e0c21b0209872140c5328761bbb2450b33f1b18\
2138b409ce9ab7c4cd8fda3391e8e34868357c199e16a6b2eba06d6749def791d79e95d3a4d09b24c\
2139392ad89dbf100995ae19c01062056bb14bce005e8731efde175f95b975089bdcdaea562b32786\
2140d96f5a31aedf75364008ad4fffebb970b
2141 R = 50ed0e810e3f1c7cb6ac62332058448bd8b284c0
2142 S = c6aded17216b46b7e4b6f2a97c1ad7cc3da83fde
2143
2144 Msg = d2bcb53b044b3e2e4b61ba2f91c0995fb83a6a97525e66441a3b489d9594238bc74\
21450bdeea0f718a769c977e2de003877b5d7dc25b182ae533db33e78f2c3ff0645f2137abc137d4e\
21467d93ccf24f60b18a820bc07c7b4b5fe08b4f9e7d21b256c18f3b9d49acc4f93e2ce6f3754c780\
21477757d2e1176042612cb32fc3f4f70700e25
2148 Y = 29bdd759aaa62d4bf16b4861c81cf42eac2e1637b9ecba512bdbc13ac12a80ae8de25\
214926b899ae5e4a231aef884197c944c732693a634d7659abc6975a773f8d3cd5a361fe2492386a3\
2150c09aaef12e4a7e73ad7dfc3637f7b093f2c40d6223a195c136adf2ea3fbf8704a675aa7817aa7\
2151ec7f9adfb2854d4e05c3ce7f76560313b
2152 R = a26c00b5750a2d27fe7435b93476b35438b4d8ab
2153 S = 61c9bfcb2938755afa7dad1d1e07c6288617bf70
2154
2155 [mod = L=2048, N=256, SHA-256]
2156
2157 P = a8adb6c0b4cf9588012e5deff1a871d383e0e2a85b5e8e03d814fe13a059705e66323\
21580a377bf7323a8fa117100200bfd5adf857393b0bbd67906c081e585410e38480ead51684dac3a\
215938f7b64c9eb109f19739a4517cd7d5d6291e8af20a3fbf17336c7bf80ee718ee087e322ee4104\
21607dabefbcc34d10b66b644ddb3160a28c0639563d71993a26543eadb7718f317bf5d9577a61565\
216161b082a10029cd44012b18de6844509fe058ba87980792285f2750969fe89c2cd6498db354563\
21628d5379d125dccf64e06c1af33a6190841d223da1513333a7c9d78462abaab31b9f96d5f34445c\
2163eb6309f2f6d2c8dde06441e87980d303ef9a1ff007e8be2f0be06cc15f
2164 Q = e71f8567447f42e75f5ef85ca20fe557ab0343d37ed09edc3f6e68604d6b9dfb
2165 G = 5ba24de9607b8998e66ce6c4f812a314c6935842f7ab54cd82b19fa104abfb5d84579\
2166a623b2574b37d22ccae9b3e415e48f5c0f9bcbdff8071d63b9bb956e547af3a8df99e5d306197\
21679652ff96b765cb3ee493643544c75dbe5bb39834531952a0fb4b0378b3fcbb4c8b5800a533039\
21682a2a04e700bb6ed7e0b85795ea38b1b962741b3f33b9dde2f4ec1354f09e2eb78e95f037a5804\
2169b6171659f88715ce1a9b0cc90c27f35ef2f10ff0c7c7a2bb0154d9b8ebe76a3d764aa879af372\
2170f4240de8347937e5a90cec9f41ff2f26b8da9a94a225d1a913717d73f10397d2183f1ba3b7b45\
2171a68f1ff1893caf69a827802f7b6a48d51da6fbefb64fd9a6c5b75c4561
2172
2173 Msg = 4e3a28bcf90d1d2e75f075d9fbe55b36c5529b17bc3a9ccaba6935c9e20548255b3\
2174dfae0f91db030c12f2c344b3a29c4151c5b209f5e319fdf1c23b190f64f1fe5b330cb7c8fa952\
2175f9d90f13aff1cb11d63181da9efc6f7e15bfed4862d1a62c7dcf3ba8bf1ff304b102b1ec3f149\
21767dddf09712cf323f5610a9d10c3d9132659
2177 Y = 5a55dceddd1134ee5f11ed85deb4d634a3643f5f36dc3a70689256469a0b651ad2288\
21780f14ab85719434f9c0e407e60ea420e2a0cd29422c4899c416359dbb1e592456f2b3cce233259\
2179c117542fd05f31ea25b015d9121c890b90e0bad033be1368d229985aac7226d1c8c2eab325ef3\
2180b2cd59d3b9f7de7dbc94af1a9339eb430ca36c26c46ecfa6c5481711496f624e188ad7540ef5d\
2181f26f8efacb820bd17a1f618acb50c9bc197d4cb7ccac45d824a3bf795c234b556b06aeb929173\
2182453252084003f69fe98045fe74002ba658f93475622f76791d9b2623d1b5fff2cc16844746efd\
21832d30a6a8134bfc4c8cc80a46107901fb973c28fc553130f3286c1489da
2184 R = 633055e055f237c38999d81c397848c38cce80a55b649d9e7905c298e2a51447
2185 S = 2bbf68317660ec1e4b154915027b0bc00ee19cfc0bf75d01930504f2ce10a8b0
2186
2187 Msg = a733b3f588d5ac9b9d4fe2f804df8c256403a9f8eef6f191fc48e1267fb5b4d546b\
2188a11e77b667844e489bf0d5f72990aeb061d01ccd7949a23def74a803b7d92d51abfadeb4885ff\
2189d8ffd58ab87548a15c087a39b8993b2fa64c9d31a594eeb7512da16955834336a234435c5a9d0\
2190dd9b15a94e116154dea63fdc8dd7a512181
2191 Y = 356ed47537fbf02cb30a8cee0537f300dff1d0c467399ce70b87a8758d5ec9dd25624\
21926fccaeb9dfe109f2a984f2ddaa87aad54ce0d31f907e504521baf4207d7073b0a4a9fc67d8ddd\
2193a99f87aed6e0367cec27f9c608af743bf1ee6e11d55a182d43b024ace534029b866f6422828bb\
219481a39aae9601ee81c7f81dd358e69f4e2edfa4654d8a65bc64311dc86aac4abc1fc7a3f651596\
219561a0d8e288eb8d665cb0adf5ac3d6ba8e9453facf7542393ae24fd50451d3828086558f7ec528\
2196e284935a53f67a1aa8e25d8ad5c4ad55d83aef883a4d9eeb6297e6a53f65049ba9e2c6b7953a7\
219760bc1dc46f78ceaaa2c02f5375dd82e708744aa40b15799eb81d7e5b1a
2198 R = bcd490568c0a89ba311bef88ea4f4b03d273e793722722327095a378dd6f3522
2199 S = 74498fc43091fcdd2d1ef0775f8286945a01cd72b805256b0451f9cbd943cf82
2200 """).splitlines()
2201
2202 expected = [
2203 {
2204 'p': int('a8f9cd201e5e35d892f85f80e4db2599a5676a3b1d4f190330ed325'
2205 '6b26d0e80a0e49a8fffaaad2a24f472d2573241d4d6d6c7480c80b4'
2206 'c67bb4479c15ada7ea8424d2502fa01472e760241713dab025ae1b0'
2207 '2e1703a1435f62ddf4ee4c1b664066eb22f2e3bf28bb70a2a76e4fd'
2208 '5ebe2d1229681b5b06439ac9c7e9d8bde283', 16),
2209 'q': int('f85f0f83ac4df7ea0cdf8f469bfeeaea14156495', 16),
2210 'g': int('2b3152ff6c62f14622b8f48e59f8af46883b38e79b8c74deeae9df1'
2211 '31f8b856e3ad6c8455dab87cc0da8ac973417ce4f7878557d6cdf40'
2212 'b35b4a0ca3eb310c6a95d68ce284ad4e25ea28591611ee08b8444bd'
2213 '64b25f3f7c572410ddfb39cc728b9c936f85f419129869929cdb909'
2214 'a6a3a99bbe089216368171bd0ba81de4fe33', 16),
2215 'digest_algorithm': 'SHA-1',
2216 'msg': binascii.unhexlify(
2217 b'3b46736d559bd4e0c2c1b2553a33ad3c6cf23cac998d3d0c0e8fa4b19bc'
2218 b'a06f2f386db2dcff9dca4f40ad8f561ffc308b46c5f31a7735b5fa7e0f9'
2219 b'e6cb512e63d7eea05538d66a75cd0d4234b5ccf6c1715ccaaf9cdc0a222'
2220 b'8135f716ee9bdee7fc13ec27a03a6d11c5c5b3685f51900b1337153bc6c'
2221 b'4e8f52920c33fa37f4e7'),
2222 'y': int('313fd9ebca91574e1c2eebe1517c57e0c21b0209872140c5328761b'
2223 'bb2450b33f1b18b409ce9ab7c4cd8fda3391e8e34868357c199e16a'
2224 '6b2eba06d6749def791d79e95d3a4d09b24c392ad89dbf100995ae1'
2225 '9c01062056bb14bce005e8731efde175f95b975089bdcdaea562b32'
2226 '786d96f5a31aedf75364008ad4fffebb970b', 16),
2227 'r': int('50ed0e810e3f1c7cb6ac62332058448bd8b284c0', 16),
2228 's': int('c6aded17216b46b7e4b6f2a97c1ad7cc3da83fde', 16)},
2229 {
2230 'p': int('a8f9cd201e5e35d892f85f80e4db2599a5676a3b1d4f190330ed325'
2231 '6b26d0e80a0e49a8fffaaad2a24f472d2573241d4d6d6c7480c80b4'
2232 'c67bb4479c15ada7ea8424d2502fa01472e760241713dab025ae1b0'
2233 '2e1703a1435f62ddf4ee4c1b664066eb22f2e3bf28bb70a2a76e4fd'
2234 '5ebe2d1229681b5b06439ac9c7e9d8bde283', 16),
2235 'q': int('f85f0f83ac4df7ea0cdf8f469bfeeaea14156495', 16),
2236 'g': int('2b3152ff6c62f14622b8f48e59f8af46883b38e79b8c74deeae9df1'
2237 '31f8b856e3ad6c8455dab87cc0da8ac973417ce4f7878557d6cdf40'
2238 'b35b4a0ca3eb310c6a95d68ce284ad4e25ea28591611ee08b8444bd'
2239 '64b25f3f7c572410ddfb39cc728b9c936f85f419129869929cdb909'
2240 'a6a3a99bbe089216368171bd0ba81de4fe33', 16),
2241 'digest_algorithm': 'SHA-1',
2242 'msg': binascii.unhexlify(
2243 b'd2bcb53b044b3e2e4b61ba2f91c0995fb83a6a97525e66441a3b489d959'
2244 b'4238bc740bdeea0f718a769c977e2de003877b5d7dc25b182ae533db33e'
2245 b'78f2c3ff0645f2137abc137d4e7d93ccf24f60b18a820bc07c7b4b5fe08'
2246 b'b4f9e7d21b256c18f3b9d49acc4f93e2ce6f3754c7807757d2e11760426'
2247 b'12cb32fc3f4f70700e25'),
2248 'y': int('29bdd759aaa62d4bf16b4861c81cf42eac2e1637b9ecba512bdbc13'
2249 'ac12a80ae8de2526b899ae5e4a231aef884197c944c732693a634d7'
2250 '659abc6975a773f8d3cd5a361fe2492386a3c09aaef12e4a7e73ad7'
2251 'dfc3637f7b093f2c40d6223a195c136adf2ea3fbf8704a675aa7817'
2252 'aa7ec7f9adfb2854d4e05c3ce7f76560313b', 16),
2253 'r': int('a26c00b5750a2d27fe7435b93476b35438b4d8ab', 16),
2254 's': int('61c9bfcb2938755afa7dad1d1e07c6288617bf70', 16)},
2255 {
2256 'p': int('a8adb6c0b4cf9588012e5deff1a871d383e0e2a85b5e8e03d814fe1'
2257 '3a059705e663230a377bf7323a8fa117100200bfd5adf857393b0bb'
2258 'd67906c081e585410e38480ead51684dac3a38f7b64c9eb109f1973'
2259 '9a4517cd7d5d6291e8af20a3fbf17336c7bf80ee718ee087e322ee4'
2260 '1047dabefbcc34d10b66b644ddb3160a28c0639563d71993a26543e'
2261 'adb7718f317bf5d9577a6156561b082a10029cd44012b18de684450'
2262 '9fe058ba87980792285f2750969fe89c2cd6498db3545638d5379d1'
2263 '25dccf64e06c1af33a6190841d223da1513333a7c9d78462abaab31'
2264 'b9f96d5f34445ceb6309f2f6d2c8dde06441e87980d303ef9a1ff00'
2265 '7e8be2f0be06cc15f', 16),
2266 'q': int('e71f8567447f42e75f5ef85ca20fe557ab0343d37ed09edc3f6e686'
2267 '04d6b9dfb', 16),
2268 'g': int('5ba24de9607b8998e66ce6c4f812a314c6935842f7ab54cd82b19fa'
2269 '104abfb5d84579a623b2574b37d22ccae9b3e415e48f5c0f9bcbdff'
2270 '8071d63b9bb956e547af3a8df99e5d3061979652ff96b765cb3ee49'
2271 '3643544c75dbe5bb39834531952a0fb4b0378b3fcbb4c8b5800a533'
2272 '0392a2a04e700bb6ed7e0b85795ea38b1b962741b3f33b9dde2f4ec'
2273 '1354f09e2eb78e95f037a5804b6171659f88715ce1a9b0cc90c27f3'
2274 '5ef2f10ff0c7c7a2bb0154d9b8ebe76a3d764aa879af372f4240de8'
2275 '347937e5a90cec9f41ff2f26b8da9a94a225d1a913717d73f10397d'
2276 '2183f1ba3b7b45a68f1ff1893caf69a827802f7b6a48d51da6fbefb'
2277 '64fd9a6c5b75c4561', 16),
2278 'digest_algorithm': 'SHA-256',
2279 'msg': binascii.unhexlify(
2280 b'4e3a28bcf90d1d2e75f075d9fbe55b36c5529b17bc3a9ccaba6935c9e20'
2281 b'548255b3dfae0f91db030c12f2c344b3a29c4151c5b209f5e319fdf1c23'
2282 b'b190f64f1fe5b330cb7c8fa952f9d90f13aff1cb11d63181da9efc6f7e1'
2283 b'5bfed4862d1a62c7dcf3ba8bf1ff304b102b1ec3f1497dddf09712cf323'
2284 b'f5610a9d10c3d9132659'),
2285 'y': int('5a55dceddd1134ee5f11ed85deb4d634a3643f5f36dc3a706892564'
2286 '69a0b651ad22880f14ab85719434f9c0e407e60ea420e2a0cd29422'
2287 'c4899c416359dbb1e592456f2b3cce233259c117542fd05f31ea25b'
2288 '015d9121c890b90e0bad033be1368d229985aac7226d1c8c2eab325'
2289 'ef3b2cd59d3b9f7de7dbc94af1a9339eb430ca36c26c46ecfa6c548'
2290 '1711496f624e188ad7540ef5df26f8efacb820bd17a1f618acb50c9'
2291 'bc197d4cb7ccac45d824a3bf795c234b556b06aeb92917345325208'
2292 '4003f69fe98045fe74002ba658f93475622f76791d9b2623d1b5fff'
2293 '2cc16844746efd2d30a6a8134bfc4c8cc80a46107901fb973c28fc5'
2294 '53130f3286c1489da', 16),
2295 'r': int('633055e055f237c38999d81c397848c38cce80a55b649d9e7905c29'
2296 '8e2a51447', 16),
2297 's': int('2bbf68317660ec1e4b154915027b0bc00ee19cfc0bf75d01930504f'
2298 '2ce10a8b0', 16)},
2299 {
2300 'p': int('a8adb6c0b4cf9588012e5deff1a871d383e0e2a85b5e8e03d814fe1'
2301 '3a059705e663230a377bf7323a8fa117100200bfd5adf857393b0bb'
2302 'd67906c081e585410e38480ead51684dac3a38f7b64c9eb109f1973'
2303 '9a4517cd7d5d6291e8af20a3fbf17336c7bf80ee718ee087e322ee4'
2304 '1047dabefbcc34d10b66b644ddb3160a28c0639563d71993a26543e'
2305 'adb7718f317bf5d9577a6156561b082a10029cd44012b18de684450'
2306 '9fe058ba87980792285f2750969fe89c2cd6498db3545638d5379d1'
2307 '25dccf64e06c1af33a6190841d223da1513333a7c9d78462abaab31'
2308 'b9f96d5f34445ceb6309f2f6d2c8dde06441e87980d303ef9a1ff00'
2309 '7e8be2f0be06cc15f', 16),
2310 'q': int('e71f8567447f42e75f5ef85ca20fe557ab0343d37ed09edc3f6e686'
2311 '04d6b9dfb', 16),
2312 'g': int('5ba24de9607b8998e66ce6c4f812a314c6935842f7ab54cd82b19fa'
2313 '104abfb5d84579a623b2574b37d22ccae9b3e415e48f5c0f9bcbdff'
2314 '8071d63b9bb956e547af3a8df99e5d3061979652ff96b765cb3ee49'
2315 '3643544c75dbe5bb39834531952a0fb4b0378b3fcbb4c8b5800a533'
2316 '0392a2a04e700bb6ed7e0b85795ea38b1b962741b3f33b9dde2f4ec'
2317 '1354f09e2eb78e95f037a5804b6171659f88715ce1a9b0cc90c27f3'
2318 '5ef2f10ff0c7c7a2bb0154d9b8ebe76a3d764aa879af372f4240de8'
2319 '347937e5a90cec9f41ff2f26b8da9a94a225d1a913717d73f10397d'
2320 '2183f1ba3b7b45a68f1ff1893caf69a827802f7b6a48d51da6fbefb'
2321 '64fd9a6c5b75c4561', 16),
2322 'digest_algorithm': 'SHA-256',
2323 'msg': binascii.unhexlify(
2324 b'a733b3f588d5ac9b9d4fe2f804df8c256403a9f8eef6f191fc48e1267fb'
2325 b'5b4d546ba11e77b667844e489bf0d5f72990aeb061d01ccd7949a23def7'
2326 b'4a803b7d92d51abfadeb4885ffd8ffd58ab87548a15c087a39b8993b2fa'
2327 b'64c9d31a594eeb7512da16955834336a234435c5a9d0dd9b15a94e11615'
2328 b'4dea63fdc8dd7a512181'),
2329 'y': int('356ed47537fbf02cb30a8cee0537f300dff1d0c467399ce70b87a87'
2330 '58d5ec9dd256246fccaeb9dfe109f2a984f2ddaa87aad54ce0d31f9'
2331 '07e504521baf4207d7073b0a4a9fc67d8ddda99f87aed6e0367cec2'
2332 '7f9c608af743bf1ee6e11d55a182d43b024ace534029b866f642282'
2333 '8bb81a39aae9601ee81c7f81dd358e69f4e2edfa4654d8a65bc6431'
2334 '1dc86aac4abc1fc7a3f65159661a0d8e288eb8d665cb0adf5ac3d6b'
2335 'a8e9453facf7542393ae24fd50451d3828086558f7ec528e284935a'
2336 '53f67a1aa8e25d8ad5c4ad55d83aef883a4d9eeb6297e6a53f65049'
2337 'ba9e2c6b7953a760bc1dc46f78ceaaa2c02f5375dd82e708744aa40'
2338 'b15799eb81d7e5b1a', 16),
2339 'r': int('bcd490568c0a89ba311bef88ea4f4b03d273e793722722327095a37'
2340 '8dd6f3522', 16),
2341 's': int('74498fc43091fcdd2d1ef0775f8286945a01cd72b805256b0451f9c'
2342 'bd943cf82', 16)}
2343 ]
2344 assert expected == load_fips_dsa_sig_vectors(vector_data)
Alex Stapletoncf048602014-04-12 12:48:59 +01002345
2346
2347def test_load_fips_ecdsa_key_pair_vectors():
2348 vector_data = textwrap.dedent("""
2349 # CAVS 11.0
2350 # "Key Pair" information
2351 # Curves selected: P-192 K-233 B-571
2352 # Generated on Wed Mar 16 16:16:42 2011
2353
2354
2355 [P-192]
2356
2357 [B.4.2 Key Pair Generation by Testing Candidates]
2358 N = 2
2359
2360 d = e5ce89a34adddf25ff3bf1ffe6803f57d0220de3118798ea
2361 Qx = 8abf7b3ceb2b02438af19543d3e5b1d573fa9ac60085840f
2362 Qy = a87f80182dcd56a6a061f81f7da393e7cffd5e0738c6b245
2363
2364 d = 7d14435714ad13ff23341cb567cc91198ff8617cc39751b2
2365 Qx = 39dc723b19527daa1e80425209c56463481b9b47c51f8cbd
2366 Qy = 432a3e84f2a16418834fabaf6b7d2341669512951f1672ad
2367
2368
2369 [K-233]
2370
2371 [B.4.2 Key Pair Generation by Testing Candidates]
2372 N = 2
2373
2374 d = 01da7422b50e3ff051f2aaaed10acea6cbf6110c517da2f4eaca8b5b87
2375 Qx = 01c7475da9a161e4b3f7d6b086494063543a979e34b8d7ac44204d47bf9f
2376 Qy = 0131cbd433f112871cc175943991b6a1350bf0cdd57ed8c831a2a7710c92
2377
2378 d = 530951158f7b1586978c196603c12d25607d2cb0557efadb23cd0ce8
2379 Qx = d37500a0391d98d3070d493e2b392a2c79dc736c097ed24b7dd5ddec44
2380 Qy = 01d996cc79f37d8dba143d4a8ad9a8a60ed7ea760aae1ddba34d883f65d9
2381
2382
2383 [B-571]
2384
2385 [B.4.2 Key Pair Generation by Testing Candidates]
2386 N = 2
2387
2388 d = 01443e93c7ef6802655f641ecbe95e75f1f15b02d2e172f49a32e22047d5c00ebe1b3f\
2389f0456374461360667dbf07bc67f7d6135ee0d1d46a226a530fefe8ebf3b926e9fbad8d57a6
2390 Qx = 053e3710d8e7d4138db0a369c97e5332c1be38a20a4a84c36f5e55ea9fd6f34545b86\
23914ea64f319e74b5ee9e4e1fa1b7c5b2db0e52467518f8c45b658824871d5d4025a6320ca06f8
2392 Qy = 03a22cfd370c4a449b936ae97ab97aab11c57686cca99d14ef184f9417fad8bedae4d\
2393f8357e3710bcda1833b30e297d4bf637938b995d231e557d13f062e81e830af5ab052208ead
2394
2395 d = 03d2bd44ca9eeee8c860a4873ed55a54bdfdf5dab4060df7292877960b85d1fd496aa3\
23963c587347213d7f6bf208a6ab4b430546e7b6ffbc3135bd12f44a28517867ca3c83a821d6f8
2397 Qx = 07a7af10f6617090bade18b2e092d0dfdc87cd616db7f2db133477a82bfe3ea421ebb\
23987d6289980819292a719eb247195529ea60ad62862de0a26c72bfc49ecc81c2f9ed704e3168f
2399 Qy = 0721496cf16f988b1aabef3368450441df8439a0ca794170f270ead56203d675b57f5\
2400a4090a3a2f602a77ff3bac1417f7e25a683f667b3b91f105016a47afad46a0367b18e2bdf0c
2401 """).splitlines()
2402
2403 expected = [
2404 {
2405 "curve": "secp192r1",
2406 "d": int("e5ce89a34adddf25ff3bf1ffe6803f57d0220de3118798ea", 16),
2407 "x": int("8abf7b3ceb2b02438af19543d3e5b1d573fa9ac60085840f", 16),
2408 "y": int("a87f80182dcd56a6a061f81f7da393e7cffd5e0738c6b245", 16)
2409 },
2410
2411 {
2412 "curve": "secp192r1",
2413 "d": int("7d14435714ad13ff23341cb567cc91198ff8617cc39751b2", 16),
2414 "x": int("39dc723b19527daa1e80425209c56463481b9b47c51f8cbd", 16),
2415 "y": int("432a3e84f2a16418834fabaf6b7d2341669512951f1672ad", 16),
2416 },
2417
2418 {
2419 "curve": "sect233k1",
2420 "d": int("1da7422b50e3ff051f2aaaed10acea6cbf6110c517da2f4e"
2421 "aca8b5b87", 16),
2422 "x": int("1c7475da9a161e4b3f7d6b086494063543a979e34b8d7ac4"
2423 "4204d47bf9f", 16),
2424 "y": int("131cbd433f112871cc175943991b6a1350bf0cdd57ed8c83"
2425 "1a2a7710c92", 16),
2426 },
2427
2428 {
2429 "curve": "sect233k1",
2430 "d": int("530951158f7b1586978c196603c12d25607d2cb0557efadb"
2431 "23cd0ce8", 16),
2432 "x": int("d37500a0391d98d3070d493e2b392a2c79dc736c097ed24b"
2433 "7dd5ddec44", 16),
2434 "y": int("1d996cc79f37d8dba143d4a8ad9a8a60ed7ea760aae1ddba"
2435 "34d883f65d9", 16),
2436 },
2437
2438 {
2439 "curve": "sect571r1",
2440 "d": int("1443e93c7ef6802655f641ecbe95e75f1f15b02d2e172f49"
2441 "a32e22047d5c00ebe1b3ff0456374461360667dbf07bc67f"
2442 "7d6135ee0d1d46a226a530fefe8ebf3b926e9fbad8d57a6", 16),
2443 "x": int("53e3710d8e7d4138db0a369c97e5332c1be38a20a4a84c36"
2444 "f5e55ea9fd6f34545b864ea64f319e74b5ee9e4e1fa1b7c5"
2445 "b2db0e52467518f8c45b658824871d5d4025a6320ca06f8", 16),
2446 "y": int("3a22cfd370c4a449b936ae97ab97aab11c57686cca99d14e"
2447 "f184f9417fad8bedae4df8357e3710bcda1833b30e297d4b"
2448 "f637938b995d231e557d13f062e81e830af5ab052208ead", 16),
2449 },
2450
2451 {
2452 "curve": "sect571r1",
2453 "d": int("3d2bd44ca9eeee8c860a4873ed55a54bdfdf5dab4060df72"
2454 "92877960b85d1fd496aa33c587347213d7f6bf208a6ab4b4"
2455 "30546e7b6ffbc3135bd12f44a28517867ca3c83a821d6f8", 16),
2456 "x": int("7a7af10f6617090bade18b2e092d0dfdc87cd616db7f2db1"
2457 "33477a82bfe3ea421ebb7d6289980819292a719eb2471955"
2458 "29ea60ad62862de0a26c72bfc49ecc81c2f9ed704e3168f", 16),
2459 "y": int("721496cf16f988b1aabef3368450441df8439a0ca794170f"
2460 "270ead56203d675b57f5a4090a3a2f602a77ff3bac1417f7"
2461 "e25a683f667b3b91f105016a47afad46a0367b18e2bdf0c", 16),
2462 },
2463 ]
2464
2465 assert expected == load_fips_ecdsa_key_pair_vectors(vector_data)
Alex Stapletonc387cf72014-04-13 13:58:02 +01002466
2467
2468def test_load_fips_ecdsa_signing_vectors():
2469 vector_data = textwrap.dedent("""
2470 # CAVS 11.2
2471 # "SigVer" information for "ecdsa_values"
2472 # Curves/SHAs selected: P-192, B-571,SHA-512
2473 # Generated on Tue Aug 16 15:27:42 2011
2474
2475 [P-192,SHA-1]
2476
2477 Msg = ebf748d748ebbca7d29fb473698a6e6b4fb10c865d4af024cc39ae3df3464ba4f1d6\
2478d40f32bf9618a91bb5986fa1a2af048a0e14dc51e5267eb05e127d689d0ac6f1a7f156ce066316\
2479b971cc7a11d0fd7a2093e27cf2d08727a4e6748cc32fd59c7810c5b9019df21cdcc0bca432c0a3\
2480eed0785387508877114359cee4a071cf
2481 d = e14f37b3d1374ff8b03f41b9b3fdd2f0ebccf275d660d7f3
2482 Qx = 07008ea40b08dbe76432096e80a2494c94982d2d5bcf98e6
2483 Qy = 76fab681d00b414ea636ba215de26d98c41bd7f2e4d65477
2484 k = cb0abc7043a10783684556fb12c4154d57bc31a289685f25
2485 R = 6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e
2486 S = 02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41
Alex Stapleton6f729492014-04-19 09:01:25 +01002487 Result = F (3 - S changed)
Alex Stapletonc387cf72014-04-13 13:58:02 +01002488
2489 Msg = 0dcb3e96d77ee64e9d0a350d31563d525755fc675f0c833504e83fc69c030181b42f\
2490e80c378e86274a93922c570d54a7a358c05755ec3ae91928e02236e81b43e596e4ccbf6a910488\
24919c388072bec4e1faeae11fe4eb24fa4f9573560dcf2e3abc703c526d46d502c7a7222583431cc8\
2492178354ae7dbb84e3479917707bce0968
2493 d = 7a0235bea3d70445f14d56f9b7fb80ec8ff4eb2f76865244
2494 Qx = 0ea3c1fa1f124f26530cbfddeb831eecc67df31e08889d1d
2495 Qy = 7215a0cce0501b47903bd8fe1179c2dfe07bd076f89f5225
2496 k = 3c646b0f03f5575e5fd463d4319817ce8bd3022eaf551cef
2497 R = a3ba51c39c43991d87dff0f34d0bec7c883299e04f60f95e
2498 S = 8a7f9c59c6d65ad390e4c19636ba92b53be5d0f848b4e1f7
2499
2500 [B-571,SHA-512]
2501
2502 Msg = 10d2e00ae57176c79cdfc746c0c887abe799ee445b151b008e3d9f81eb69be40298d\
2503df37b5c45a9b6e5ff83785d8c140cf11e6a4c3879a2845796872363da24b10f1f8d9cc48f8af20\
2504681dceb60dd62095d6d3b1779a4a805de3d74e38983b24c0748618e2f92ef7cac257ff4bd1f411\
250513f2891eb13c47930e69ddbe91f270fb
2506 d = 03e1b03ffca4399d5b439fac8f87a5cb06930f00d304193d7daf83d5947d0c1e293f74\
2507aef8e56849f16147133c37a6b3d1b1883e5d61d6b871ea036c5291d9a74541f28878cb986
2508 Qx = 3b236fc135d849d50140fdaae1045e6ae35ef61091e98f5059b30eb16acdd0deb2bc0\
2509d3544bc3a666e0014e50030134fe5466a9e4d3911ed580e28851f3747c0010888e819d3d1f
2510 Qy = 3a8b6627a587d289032bd76374d16771188d7ff281c39542c8977f6872fa932e5daa1\
25114e13792dea9ffe8e9f68d6b525ec99b81a5a60cfb0590cc6f297cfff8d7ba1a8bb81fe2e16
2512 k = 2e56a94cfbbcd293e242f0c2a2e9df289a9480e6ba52e0f00fa19bcf2a7769bd155e6b\
251379ddbd6a8646b0e69c8baea27f8034a18796e8eb4fe6e0e2358c383521d9375d2b6b437f9
2514 R = 2eb1c5c1fc93cf3c8babed12c031cf1504e094174fd335104cbe4a2abd210b5a14b1c3\
2515a455579f1ed0517c31822340e4dd3c1f967e1b4b9d071a1072afc1a199f8c548cd449a634
2516 S = 22f97bb48641235826cf4e597fa8de849402d6bd6114ad2d7fbcf53a08247e5ee921f1\
2517bd5994dffee36eedff5592bb93b8bb148214da3b7baebffbd96b4f86c55b3f6bbac142442
Alex Stapleton6f729492014-04-19 09:01:25 +01002518 Result = P (0 )
Alex Stapletonc387cf72014-04-13 13:58:02 +01002519
2520 Msg = b61a0849a28672cb536fcf61ea2eb389d02ff7a09aa391744cae6597bd56703c40c5\
25210ca2dee5f7ee796acfd47322f03d8dbe4d99dc8eec588b4e5467f123075b2d74b2a0b0bbfd3ac5\
2522487a905fad6d6ac1421c2e564c0cf15e1f0f10bc31c249b7b46edd2462a55f85560d99bde9d5b0\
25236b97817d1dbe0a67c701d6e6e7878272
2524 d = 2e09ffd8b434bb7f67d1d3ccf482164f1653c6e4ec64dec2517aa21b7a93b2b21ea1ee\
2525bb54734882f29303e489f02e3b741a87287e2dcdf3858eb6d2ec668f8b5b26f442ce513a2
2526 Qx = 36f1be8738dd7dae4486b86a08fe90424f3673e76b10e739442e15f3bfafaf841842a\
2527c98e490521b7e7bb94c127529f6ec6a42cc6f06fc80606f1210fe020ff508148f93301c9d3
2528 Qy = 4d39666ebe99fe214336ad440d776c88eb916f2f4a3433548b87d2aebed840b424d15\
2529c8341b4a0a657bf6a234d4fe78631c8e07ac1f4dc7474cd6b4545d536b7b17c160db4562d9
2530 k = 378e7801566d7b77db7a474717ab2195b02957cc264a9449d4126a7cc574728ed5a476\
25319abd5dde987ca66cfe3d45b5fc52ffd266acb8a8bb3fcb4b60f7febbf48aebe33bd3efbdd
2532 R = 3d8105f87fe3166046c08e80a28acc98a80b8b7a729623053c2a9e80afd06756edfe09\
2533bdcf3035f6829ede041b745955d219dc5d30ddd8b37f6ba0f6d2857504cdc68a1ed812a10
2534 S = 34db9998dc53527114518a7ce3783d674ca8cced823fa05e2942e7a0a20b3cc583dcd9\
253530c43f9b93079c5ee18a1f5a66e7c3527c18610f9b47a4da7e245ef803e0662e4d2ad721c
2536 """).splitlines()
2537
2538 expected = [
2539 {
2540 "curve": "secp192r1",
2541 "digest_algorithm": "SHA-1",
Alex Stapletonfb812d62014-04-15 16:07:25 +01002542 "message": binascii.unhexlify(
Alex Stapletonc387cf72014-04-13 13:58:02 +01002543 b"ebf748d748ebbca7d29fb473698a6e6b4fb10c865d4af024cc39ae3df346"
2544 b"4ba4f1d6d40f32bf9618a91bb5986fa1a2af048a0e14dc51e5267eb05e12"
2545 b"7d689d0ac6f1a7f156ce066316b971cc7a11d0fd7a2093e27cf2d08727a4"
2546 b"e6748cc32fd59c7810c5b9019df21cdcc0bca432c0a3eed0785387508877"
2547 b"114359cee4a071cf"
2548 ),
2549 "d": int("e14f37b3d1374ff8b03f41b9b3fdd2f0ebccf275d660d7f3", 16),
2550 "x": int("7008ea40b08dbe76432096e80a2494c94982d2d5bcf98e6", 16),
2551 "y": int("76fab681d00b414ea636ba215de26d98c41bd7f2e4d65477", 16),
2552 "r": int("6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e", 16),
Alex Stapleton6f729492014-04-19 09:01:25 +01002553 "s": int("02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41", 16),
2554 "fail": True
Alex Stapletonc387cf72014-04-13 13:58:02 +01002555 },
2556 {
2557 "curve": "secp192r1",
2558 "digest_algorithm": "SHA-1",
Alex Stapletonfb812d62014-04-15 16:07:25 +01002559 "message": binascii.unhexlify(
Alex Stapletonc387cf72014-04-13 13:58:02 +01002560 b"0dcb3e96d77ee64e9d0a350d31563d525755fc675f0c833504e83fc69c03"
2561 b"0181b42fe80c378e86274a93922c570d54a7a358c05755ec3ae91928e022"
2562 b"36e81b43e596e4ccbf6a9104889c388072bec4e1faeae11fe4eb24fa4f95"
2563 b"73560dcf2e3abc703c526d46d502c7a7222583431cc8178354ae7dbb84e3"
2564 b"479917707bce0968"
2565 ),
2566 "d": int("7a0235bea3d70445f14d56f9b7fb80ec8ff4eb2f76865244", 16),
2567 "x": int("ea3c1fa1f124f26530cbfddeb831eecc67df31e08889d1d", 16),
2568 "y": int("7215a0cce0501b47903bd8fe1179c2dfe07bd076f89f5225", 16),
2569 "r": int("a3ba51c39c43991d87dff0f34d0bec7c883299e04f60f95e", 16),
Alex Stapleton6f729492014-04-19 09:01:25 +01002570 "s": int("8a7f9c59c6d65ad390e4c19636ba92b53be5d0f848b4e1f7", 16),
Alex Stapletonc387cf72014-04-13 13:58:02 +01002571 },
2572 {
2573 "curve": "sect571r1",
2574 "digest_algorithm": "SHA-512",
Alex Stapletonfb812d62014-04-15 16:07:25 +01002575 "message": binascii.unhexlify(
Alex Stapletonc387cf72014-04-13 13:58:02 +01002576 b"10d2e00ae57176c79cdfc746c0c887abe799ee445b151b008e3d9f81eb69"
2577 b"be40298ddf37b5c45a9b6e5ff83785d8c140cf11e6a4c3879a2845796872"
2578 b"363da24b10f1f8d9cc48f8af20681dceb60dd62095d6d3b1779a4a805de3"
2579 b"d74e38983b24c0748618e2f92ef7cac257ff4bd1f41113f2891eb13c4793"
2580 b"0e69ddbe91f270fb"
2581 ),
2582 "d": int("3e1b03ffca4399d5b439fac8f87a5cb06930f00d304193d7daf83d59"
2583 "47d0c1e293f74aef8e56849f16147133c37a6b3d1b1883e5d61d6b87"
2584 "1ea036c5291d9a74541f28878cb986", 16),
2585 "x": int("3b236fc135d849d50140fdaae1045e6ae35ef61091e98f5059b30eb1"
2586 "6acdd0deb2bc0d3544bc3a666e0014e50030134fe5466a9e4d3911ed"
2587 "580e28851f3747c0010888e819d3d1f", 16),
2588 "y": int("3a8b6627a587d289032bd76374d16771188d7ff281c39542c8977f68"
2589 "72fa932e5daa14e13792dea9ffe8e9f68d6b525ec99b81a5a60cfb05"
2590 "90cc6f297cfff8d7ba1a8bb81fe2e16", 16),
2591 "r": int("2eb1c5c1fc93cf3c8babed12c031cf1504e094174fd335104cbe4a2a"
2592 "bd210b5a14b1c3a455579f1ed0517c31822340e4dd3c1f967e1b4b9d"
2593 "071a1072afc1a199f8c548cd449a634", 16),
2594 "s": int("22f97bb48641235826cf4e597fa8de849402d6bd6114ad2d7fbcf53a"
2595 "08247e5ee921f1bd5994dffee36eedff5592bb93b8bb148214da3b7b"
Alex Stapleton6f729492014-04-19 09:01:25 +01002596 "aebffbd96b4f86c55b3f6bbac142442", 16),
2597 "fail": False
Alex Stapletonc387cf72014-04-13 13:58:02 +01002598 },
2599 {
2600 "curve": "sect571r1",
2601 "digest_algorithm": "SHA-512",
Alex Stapleton24a2f072014-04-16 10:00:12 +01002602 "message": binascii.unhexlify(
Alex Stapletonc387cf72014-04-13 13:58:02 +01002603 b"b61a0849a28672cb536fcf61ea2eb389d02ff7a09aa391744cae6597bd56"
2604 b"703c40c50ca2dee5f7ee796acfd47322f03d8dbe4d99dc8eec588b4e5467"
2605 b"f123075b2d74b2a0b0bbfd3ac5487a905fad6d6ac1421c2e564c0cf15e1f"
2606 b"0f10bc31c249b7b46edd2462a55f85560d99bde9d5b06b97817d1dbe0a67"
2607 b"c701d6e6e7878272"
2608 ),
2609 "d": int("2e09ffd8b434bb7f67d1d3ccf482164f1653c6e4ec64dec2517aa21b"
2610 "7a93b2b21ea1eebb54734882f29303e489f02e3b741a87287e2dcdf3"
2611 "858eb6d2ec668f8b5b26f442ce513a2", 16),
2612 "x": int("36f1be8738dd7dae4486b86a08fe90424f3673e76b10e739442e15f3"
2613 "bfafaf841842ac98e490521b7e7bb94c127529f6ec6a42cc6f06fc80"
2614 "606f1210fe020ff508148f93301c9d3", 16),
2615 "y": int("4d39666ebe99fe214336ad440d776c88eb916f2f4a3433548b87d2ae"
2616 "bed840b424d15c8341b4a0a657bf6a234d4fe78631c8e07ac1f4dc74"
2617 "74cd6b4545d536b7b17c160db4562d9", 16),
2618 "r": int("3d8105f87fe3166046c08e80a28acc98a80b8b7a729623053c2a9e80"
2619 "afd06756edfe09bdcf3035f6829ede041b745955d219dc5d30ddd8b3"
2620 "7f6ba0f6d2857504cdc68a1ed812a10", 16),
2621 "s": int("34db9998dc53527114518a7ce3783d674ca8cced823fa05e2942e7a0"
2622 "a20b3cc583dcd930c43f9b93079c5ee18a1f5a66e7c3527c18610f9b"
2623 "47a4da7e245ef803e0662e4d2ad721c", 16)
2624 }
2625 ]
Alex Stapletonc387cf72014-04-13 13:58:02 +01002626 assert expected == load_fips_ecdsa_signing_vectors(vector_data)
Mohammed Attia0fb5d852014-04-21 10:31:15 +02002627
2628
2629def test_vector_version():
2630 assert cryptography.__version__ == cryptography_vectors.__version__
2631
2632
2633def test_raises_unsupported_algorithm_wrong_type():
2634 # Check that it raises if the wrong type of exception is raised.
2635 class TestException(Exception):
2636 pass
2637
2638 with pytest.raises(TestException):
2639 with raises_unsupported_algorithm(None):
2640 raise TestException
2641
2642
2643def test_raises_unsupported_algorithm_wrong_reason():
2644 # Check that it fails if the wrong reason code is raised.
2645 with pytest.raises(AssertionError):
2646 with raises_unsupported_algorithm(None):
2647 raise UnsupportedAlgorithm("An error.",
2648 _Reasons.BACKEND_MISSING_INTERFACE)
2649
2650
2651def test_raises_unsupported_no_exc():
2652 # Check that it fails if no exception is raised.
2653 with pytest.raises(pytest.fail.Exception):
2654 with raises_unsupported_algorithm(
2655 _Reasons.BACKEND_MISSING_INTERFACE
2656 ):
2657 pass
2658
2659
2660def test_raises_unsupported_algorithm():
Alex Gaynor462bd602014-04-25 07:49:08 -07002661 # Check that it doesn't assert if the right things are raised.
Mohammed Attia0fb5d852014-04-21 10:31:15 +02002662 with raises_unsupported_algorithm(
2663 _Reasons.BACKEND_MISSING_INTERFACE
2664 ) as exc_info:
2665 raise UnsupportedAlgorithm("An error.",
2666 _Reasons.BACKEND_MISSING_INTERFACE)
2667 assert exc_info.type is UnsupportedAlgorithm