Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 1 | import textwrap |
| 2 | |
| 3 | from .utils import load_nist_vectors, load_nist_vectors_from_file |
| 4 | |
| 5 | |
| 6 | def test_load_nist_vectors_encrypt(): |
| 7 | vector_data = textwrap.dedent(""" |
| 8 | # CAVS 11.1 |
| 9 | # Config info for aes_values |
| 10 | # AESVS GFSbox test data for CBC |
| 11 | # State : Encrypt and Decrypt |
| 12 | # Key Length : 128 |
| 13 | # Generated on Fri Apr 22 15:11:33 2011 |
| 14 | |
| 15 | [ENCRYPT] |
| 16 | |
| 17 | COUNT = 0 |
| 18 | KEY = 00000000000000000000000000000000 |
| 19 | IV = 00000000000000000000000000000000 |
| 20 | PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6 |
| 21 | CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e |
| 22 | |
| 23 | COUNT = 1 |
| 24 | KEY = 00000000000000000000000000000000 |
| 25 | IV = 00000000000000000000000000000000 |
| 26 | PLAINTEXT = 9798c4640bad75c7c3227db910174e72 |
| 27 | CIPHERTEXT = a9a1631bf4996954ebc093957b234589 |
| 28 | |
| 29 | [DECRYPT] |
| 30 | |
| 31 | COUNT = 0 |
| 32 | KEY = 00000000000000000000000000000000 |
| 33 | IV = 00000000000000000000000000000000 |
| 34 | CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e |
| 35 | PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6 |
| 36 | |
| 37 | COUNT = 1 |
| 38 | KEY = 00000000000000000000000000000000 |
| 39 | IV = 00000000000000000000000000000000 |
| 40 | CIPHERTEXT = a9a1631bf4996954ebc093957b234589 |
| 41 | PLAINTEXT = 9798c4640bad75c7c3227db910174e72 |
| 42 | """).splitlines() |
| 43 | |
| 44 | assert load_nist_vectors(vector_data, "ENCRYPT", |
| 45 | ["key", "iv", "plaintext", "ciphertext"], |
| 46 | ) == [ |
| 47 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 48 | b"00000000000000000000000000000000", |
| 49 | b"00000000000000000000000000000000", |
| 50 | b"f34481ec3cc627bacd5dc3fb08f273e6", |
| 51 | b"0336763e966d92595a567cc9ce537f5e", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 52 | ), |
| 53 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 54 | b"00000000000000000000000000000000", |
| 55 | b"00000000000000000000000000000000", |
| 56 | b"9798c4640bad75c7c3227db910174e72", |
| 57 | b"a9a1631bf4996954ebc093957b234589", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 58 | ), |
| 59 | ] |
| 60 | |
| 61 | |
| 62 | def test_load_nist_vectors_decrypt(): |
| 63 | vector_data = textwrap.dedent(""" |
| 64 | # CAVS 11.1 |
| 65 | # Config info for aes_values |
| 66 | # AESVS GFSbox test data for CBC |
| 67 | # State : Encrypt and Decrypt |
| 68 | # Key Length : 128 |
| 69 | # Generated on Fri Apr 22 15:11:33 2011 |
| 70 | |
| 71 | [ENCRYPT] |
| 72 | |
| 73 | COUNT = 0 |
| 74 | KEY = 00000000000000000000000000000000 |
| 75 | IV = 00000000000000000000000000000000 |
| 76 | PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6 |
| 77 | CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e |
| 78 | |
| 79 | COUNT = 1 |
| 80 | KEY = 00000000000000000000000000000000 |
| 81 | IV = 00000000000000000000000000000000 |
| 82 | PLAINTEXT = 9798c4640bad75c7c3227db910174e72 |
| 83 | CIPHERTEXT = a9a1631bf4996954ebc093957b234589 |
| 84 | |
| 85 | [DECRYPT] |
| 86 | |
| 87 | COUNT = 0 |
| 88 | KEY = 00000000000000000000000000000000 |
| 89 | IV = 00000000000000000000000000000000 |
| 90 | CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e |
| 91 | PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6 |
| 92 | |
| 93 | COUNT = 1 |
| 94 | KEY = 00000000000000000000000000000000 |
| 95 | IV = 00000000000000000000000000000000 |
| 96 | CIPHERTEXT = a9a1631bf4996954ebc093957b234589 |
| 97 | PLAINTEXT = 9798c4640bad75c7c3227db910174e72 |
| 98 | """).splitlines() |
| 99 | |
| 100 | assert load_nist_vectors(vector_data, "DECRYPT", |
| 101 | ["key", "iv", "ciphertext", "plaintext"], |
| 102 | ) == [ |
| 103 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 104 | b"00000000000000000000000000000000", |
| 105 | b"00000000000000000000000000000000", |
| 106 | b"0336763e966d92595a567cc9ce537f5e", |
| 107 | b"f34481ec3cc627bacd5dc3fb08f273e6", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 108 | ), |
| 109 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 110 | b"00000000000000000000000000000000", |
| 111 | b"00000000000000000000000000000000", |
| 112 | b"a9a1631bf4996954ebc093957b234589", |
| 113 | b"9798c4640bad75c7c3227db910174e72", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 114 | ), |
| 115 | ] |
| 116 | |
| 117 | |
| 118 | def test_load_nist_vectors_from_file_encrypt(): |
| 119 | assert load_nist_vectors_from_file( |
| 120 | "AES/KAT/CBCGFSbox256.rsp", |
| 121 | "ENCRYPT", |
| 122 | ["key", "iv", "plaintext", "ciphertext"], |
| 123 | ) == [ |
| 124 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 125 | b"0000000000000000000000000000000000000000000000000000000000000000", |
| 126 | b"00000000000000000000000000000000", |
| 127 | b"014730f80ac625fe84f026c60bfd547d", |
| 128 | b"5c9d844ed46f9885085e5d6a4f94c7d7", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 129 | ), |
| 130 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 131 | b"0000000000000000000000000000000000000000000000000000000000000000", |
| 132 | b"00000000000000000000000000000000", |
| 133 | b"0b24af36193ce4665f2825d7b4749c98", |
| 134 | b"a9ff75bd7cf6613d3731c77c3b6d0c04", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 135 | ), |
| 136 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 137 | b"0000000000000000000000000000000000000000000000000000000000000000", |
| 138 | b"00000000000000000000000000000000", |
| 139 | b"761c1fe41a18acf20d241650611d90f1", |
| 140 | b"623a52fcea5d443e48d9181ab32c7421", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 141 | ), |
| 142 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 143 | b"0000000000000000000000000000000000000000000000000000000000000000", |
| 144 | b"00000000000000000000000000000000", |
| 145 | b"8a560769d605868ad80d819bdba03771", |
| 146 | b"38f2c7ae10612415d27ca190d27da8b4", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 147 | ), |
| 148 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 149 | b"0000000000000000000000000000000000000000000000000000000000000000", |
| 150 | b"00000000000000000000000000000000", |
| 151 | b"91fbef2d15a97816060bee1feaa49afe", |
| 152 | b"1bc704f1bce135ceb810341b216d7abe", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 153 | ), |
| 154 | ] |
| 155 | |
| 156 | |
| 157 | def test_load_nist_vectors_from_file_decypt(): |
| 158 | assert load_nist_vectors_from_file( |
| 159 | "AES/KAT/CBCGFSbox256.rsp", |
| 160 | "DECRYPT", |
| 161 | ["key", "iv", "ciphertext", "plaintext"], |
| 162 | ) == [ |
| 163 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 164 | b"0000000000000000000000000000000000000000000000000000000000000000", |
| 165 | b"00000000000000000000000000000000", |
| 166 | b"5c9d844ed46f9885085e5d6a4f94c7d7", |
| 167 | b"014730f80ac625fe84f026c60bfd547d", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 168 | ), |
| 169 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 170 | b"0000000000000000000000000000000000000000000000000000000000000000", |
| 171 | b"00000000000000000000000000000000", |
| 172 | b"a9ff75bd7cf6613d3731c77c3b6d0c04", |
| 173 | b"0b24af36193ce4665f2825d7b4749c98", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 174 | ), |
| 175 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 176 | b"0000000000000000000000000000000000000000000000000000000000000000", |
| 177 | b"00000000000000000000000000000000", |
| 178 | b"623a52fcea5d443e48d9181ab32c7421", |
| 179 | b"761c1fe41a18acf20d241650611d90f1", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 180 | ), |
| 181 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 182 | b"0000000000000000000000000000000000000000000000000000000000000000", |
| 183 | b"00000000000000000000000000000000", |
| 184 | b"38f2c7ae10612415d27ca190d27da8b4", |
| 185 | b"8a560769d605868ad80d819bdba03771", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 186 | ), |
| 187 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame^] | 188 | b"0000000000000000000000000000000000000000000000000000000000000000", |
| 189 | b"00000000000000000000000000000000", |
| 190 | b"1bc704f1bce135ceb810341b216d7abe", |
| 191 | b"91fbef2d15a97816060bee1feaa49afe", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 192 | ), |
| 193 | ] |