diff options
-rw-r--r-- | tests/test_utils.py | 133 | ||||
-rw-r--r-- | tests/utils.py | 45 |
2 files changed, 168 insertions, 10 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py index 013d491e..f4855bb6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -580,8 +580,63 @@ def test_load_pkcs1_vectors(): # RSA-PSS signing of 6 random messages with random salts # ------------------------------------------------------- - - <snip> + # PSS Example 8.1 + + # ----------------- + + # Message to be signed: + 81 33 2f 4b e6 29 48 41 5e a1 d8 99 79 2e ea cf + 6c 6e 1d b1 da 8b e1 3b 5c ea 41 db 2f ed 46 70 + 92 e1 ff 39 89 14 c7 14 25 97 75 f5 95 f8 54 7f + 73 56 92 a5 75 e6 92 3a f7 8f 22 c6 99 7d db 90 + fb 6f 72 d7 bb 0d d5 74 4a 31 de cd 3d c3 68 58 + 49 83 6e d3 4a ec 59 63 04 ad 11 84 3c 4f 88 48 + 9f 20 97 35 f5 fb 7f da f7 ce c8 ad dc 58 18 16 + 8f 88 0a cb f4 90 d5 10 05 b7 a8 e8 4e 43 e5 42 + 87 97 75 71 dd 99 ee a4 b1 61 eb 2d f1 f5 10 8f + 12 a4 14 2a 83 32 2e db 05 a7 54 87 a3 43 5c 9a + 78 ce 53 ed 93 bc 55 08 57 d7 a9 fb + + # Salt: + 1d 65 49 1d 79 c8 64 b3 73 00 9b e6 f6 f2 46 7b + ac 4c 78 fa + + # Signature: + 02 62 ac 25 4b fa 77 f3 c1 ac a2 2c 51 79 f8 f0 + 40 42 2b 3c 5b af d4 0a 8f 21 cf 0f a5 a6 67 cc + d5 99 3d 42 db af b4 09 c5 20 e2 5f ce 2b 1e e1 + e7 16 57 7f 1e fa 17 f3 da 28 05 2f 40 f0 41 9b + 23 10 6d 78 45 aa f0 11 25 b6 98 e7 a4 df e9 2d + 39 67 bb 00 c4 d0 d3 5b a3 55 2a b9 a8 b3 ee f0 + 7c 7f ec db c5 42 4a c4 db 1e 20 cb 37 d0 b2 74 + 47 69 94 0e a9 07 e1 7f bb ca 67 3b 20 52 23 80 + c5 + + # PSS Example 8.2 + + # ----------------- + + # Message to be signed: + e2 f9 6e af 0e 05 e7 ba 32 6e cc a0 ba 7f d2 f7 + c0 23 56 f3 ce de 9d 0f aa bf 4f cc 8e 60 a9 73 + e5 59 5f d9 ea 08 + + # Salt: + 43 5c 09 8a a9 90 9e b2 37 7f 12 48 b0 91 b6 89 + 87 ff 18 38 + + # Signature: + 27 07 b9 ad 51 15 c5 8c 94 e9 32 e8 ec 0a 28 0f + 56 33 9e 44 a1 b5 8d 4d dc ff 2f 31 2e 5f 34 dc + fe 39 e8 9c 6a 94 dc ee 86 db bd ae 5b 79 ba 4e + 08 19 a9 e7 bf d9 d9 82 e7 ee 6c 86 ee 68 39 6e + 8b 3a 14 c9 c8 f3 4b 17 8e b7 41 f9 d3 f1 21 10 + 9b f5 c8 17 2f ad a2 e7 68 f9 ea 14 33 03 2c 00 + 4a 8a a0 7e b9 90 00 0a 48 dc 94 c8 ba c8 aa be + 2b 09 b1 aa 46 c0 a2 aa 0e 12 f6 3f bb a7 75 ba + 7e + + # <snip> # ============================================= @@ -683,14 +738,31 @@ def test_load_pkcs1_vectors(): 48 37 2f 69 78 49 67 45 f9 43 e1 db 4f 18 38 2c ea a5 05 df c6 57 57 bb 3f 85 7a 58 dc e5 21 56 - # RSA-PSS signing of 6 random messages with random salts - # ------------------------------------------------------- + # PKCS#1 v1.5 Signature Example 2.17 - <snip> + # ----------------- + + # Message to be signed: + 06 ad d7 5a b6 89 de 06 77 44 e6 9a 2e bd 4b 90 + fa 93 83 00 3c d0 5f f5 36 cb f2 94 cd 21 5f 09 + 23 b7 fc 90 04 f0 aa 18 52 71 a1 d0 06 1f d0 e9 + 77 7a d1 ec 0c 71 59 1f 57 8b f7 b8 e5 a1 + + # Signature: + 45 14 21 0e 54 1d 5b ad 7d d6 0a e5 49 b9 43 ac + c4 4f 21 39 0d f5 b6 13 18 45 5a 17 61 0d f5 b7 + 4d 84 ae d2 32 f1 7e 59 d9 1d d2 65 99 22 f8 12 + db d4 96 81 69 03 84 b9 54 e9 ad fb 9b 1a 96 8c + 0c bf f7 63 ec ee d6 27 50 c5 91 64 b5 e0 80 a8 + fe f3 d5 5b fe 2a cf ad 27 52 a6 a8 45 9f a1 fa + b4 9a d3 78 c6 96 4b 23 ee 97 fd 10 34 61 0c 5c + c1 4c 61 e0 eb fb 17 11 f8 ad e9 6f e6 55 7b 38 + + # <snip> # ============================================= - <snip> + # <snip> """).splitlines() vectors = tuple(load_pkcs1_vectors(vector_data)) @@ -729,7 +801,38 @@ def test_load_pkcs1_vectors(): 'iqmp': int( '07d3e47bf686600b11ac283ce88dbb3f6051e8efd04680e44c171ef53' '1b80b2b7c39fc766320e2cf15d8d99820e96ff30dc69691839c4b40d7' - 'b06e45307dc91f3f', 16) + 'b06e45307dc91f3f', 16), + 'examples': [ + { + 'msg': '81332f4be62948415ea1d899792eeacf6c6e1db1da8be' + '13b5cea41db2fed467092e1ff398914c714259775f595' + 'f8547f735692a575e6923af78f22c6997ddb90fb6f72d' + '7bb0dd5744a31decd3dc3685849836ed34aec596304ad' + '11843c4f88489f209735f5fb7fdaf7cec8addc5818168' + 'f880acbf490d51005b7a8e84e43e54287977571dd99ee' + 'a4b161eb2df1f5108f12a4142a83322edb05a75487a34' + '35c9a78ce53ed93bc550857d7a9fb', + 'salt': '1d65491d79c864b373009be6f6f2467bac4c78fa', + 'signature': '0262ac254bfa77f3c1aca22c5179f8f040422b3c' + '5bafd40a8f21cf0fa5a667ccd5993d42dbafb409' + 'c520e25fce2b1ee1e716577f1efa17f3da28052f' + '40f0419b23106d7845aaf01125b698e7a4dfe92d' + '3967bb00c4d0d35ba3552ab9a8b3eef07c7fecdb' + 'c5424ac4db1e20cb37d0b2744769940ea907e17f' + 'bbca673b20522380c5' + }, { + 'msg': 'e2f96eaf0e05e7ba326ecca0ba7fd2f7c02356f3cede9' + 'd0faabf4fcc8e60a973e5595fd9ea08', + 'salt': '435c098aa9909eb2377f1248b091b68987ff1838', + 'signature': '2707b9ad5115c58c94e932e8ec0a280f56339e44' + 'a1b58d4ddcff2f312e5f34dcfe39e89c6a94dcee' + '86dbbdae5b79ba4e0819a9e7bfd9d982e7ee6c86' + 'ee68396e8b3a14c9c8f34b178eb741f9d3f12110' + '9bf5c8172fada2e768f9ea1433032c004a8aa07e' + 'b990000a48dc94c8bac8aabe2b09b1aa46c0a2aa' + '0e12f63fbba775ba7e' + } + ] }, { @@ -785,7 +888,21 @@ def test_load_pkcs1_vectors(): '77b9d1137b50404a982729316efafc7dfe66d34e5a182600d5f30a0a8' '512051c560d081d4d0a1835ec3d25a60f4e4d6aa948b2bf3dbb5b124c' 'bbc3489255a3a948372f6978496745f943e1db4f18382ceaa505dfc65' - '757bb3f857a58dce52156', 16) + '757bb3f857a58dce52156', 16), + 'examples': [ + { + 'msg': '06add75ab689de067744e69a2ebd4b90fa9383003cd05f' + 'f536cbf294cd215f0923b7fc9004f0aa185271a1d0061f' + 'd0e9777ad1ec0c71591f578bf7b8e5a1', + 'signature': '4514210e541d5bad7dd60ae549b943acc44f2139' + '0df5b61318455a17610df5b74d84aed232f17e59' + 'd91dd2659922f812dbd49681690384b954e9adfb' + '9b1a968c0cbff763eceed62750c59164b5e080a8' + 'fef3d55bfe2acfad2752a6a8459fa1fab49ad378' + 'c6964b23ee97fd1034610c5cc14c61e0ebfb1711' + 'f8ade96fe6557b38' + } + ] }, { diff --git a/tests/utils.py b/tests/utils.py index 3c150a2e..bcd915be 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -177,15 +177,53 @@ def load_hash_vectors(vector_data): def load_pkcs1_vectors(vector_data): """ Loads data out of RSA PKCS #1 vector files. - - Currently only returns the key pairs. """ private_key_vector = None public_key_vector = None attr = None key = None + example_vector = None + examples = [] vectors = [] for line in vector_data: + if (line.startswith("# PSS Example") or + line.startswith("# PKCS#1 v1.5 Signature") + ): + if example_vector: + for key, value in six.iteritems(example_vector): + hex_str = "".join(value).replace(" ", "") + example_vector[key] = hex_str + examples.append(example_vector) + + attr = None + example_vector = collections.defaultdict(list) + + if line.startswith("# Message to be signed"): + attr = "msg" + continue + elif line.startswith("# Salt"): + attr = "salt" + continue + elif line.startswith("# Signature"): + attr = "signature" + continue + elif ( + example_vector and + line.startswith("# =============================================") + ): + for key, value in six.iteritems(example_vector): + hex_str = "".join(value).replace(" ", "") + example_vector[key] = hex_str + examples.append(example_vector) + example_vector = None + attr = None + elif example_vector and line.startswith("#"): + continue + else: + if attr is not None and example_vector is not None: + example_vector[attr].append(line.strip()) + continue + if ( line.startswith("# Example") or line.startswith("# =============================================") @@ -202,6 +240,9 @@ def load_pkcs1_vectors(vector_data): hex_str = "".join(value).replace(" ", "") private_key_vector[key] = int(hex_str, 16) + private_key_vector["examples"] = examples + examples = [] + assert ( private_key_vector['public_exponent'] == public_key_vector['public_exponent'] |