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( |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 120 | "AES/KAT/CBCGFSbox128.rsp", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 121 | "ENCRYPT", |
| 122 | ["key", "iv", "plaintext", "ciphertext"], |
| 123 | ) == [ |
| 124 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame] | 125 | b"00000000000000000000000000000000", |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 126 | b"00000000000000000000000000000000", |
| 127 | b"f34481ec3cc627bacd5dc3fb08f273e6", |
| 128 | b"0336763e966d92595a567cc9ce537f5e", |
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"00000000000000000000000000000000", |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 132 | b"00000000000000000000000000000000", |
| 133 | b"9798c4640bad75c7c3227db910174e72", |
| 134 | b"a9a1631bf4996954ebc093957b234589", |
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"00000000000000000000000000000000", |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 138 | b"00000000000000000000000000000000", |
| 139 | b"96ab5c2ff612d9dfaae8c31f30c42168", |
| 140 | b"ff4f8391a6a40ca5b25d23bedd44a597", |
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"00000000000000000000000000000000", |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 144 | b"00000000000000000000000000000000", |
| 145 | b"6a118a874519e64e9963798a503f1d35", |
| 146 | b"dc43be40be0e53712f7e2bf5ca707209", |
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"00000000000000000000000000000000", |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 150 | b"00000000000000000000000000000000", |
| 151 | b"cb9fceec81286ca3e989bd979b0cb284", |
| 152 | b"92beedab1895a94faa69b632e5cc47ce", |
| 153 | ), |
| 154 | ( |
| 155 | b"00000000000000000000000000000000", |
| 156 | b"00000000000000000000000000000000", |
| 157 | b"b26aeb1874e47ca8358ff22378f09144", |
| 158 | b"459264f4798f6a78bacb89c15ed3d601", |
| 159 | ), |
| 160 | ( |
| 161 | b"00000000000000000000000000000000", |
| 162 | b"00000000000000000000000000000000", |
| 163 | b"58c8e00b2631686d54eab84b91f0aca1", |
| 164 | b"08a4e2efec8a8e3312ca7460b9040bbf", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 165 | ), |
| 166 | ] |
| 167 | |
| 168 | |
| 169 | def test_load_nist_vectors_from_file_decypt(): |
| 170 | assert load_nist_vectors_from_file( |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 171 | "AES/KAT/CBCGFSbox128.rsp", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 172 | "DECRYPT", |
| 173 | ["key", "iv", "ciphertext", "plaintext"], |
| 174 | ) == [ |
| 175 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame] | 176 | b"00000000000000000000000000000000", |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 177 | b"00000000000000000000000000000000", |
| 178 | b"0336763e966d92595a567cc9ce537f5e", |
| 179 | b"f34481ec3cc627bacd5dc3fb08f273e6", |
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"00000000000000000000000000000000", |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 183 | b"00000000000000000000000000000000", |
| 184 | b"a9a1631bf4996954ebc093957b234589", |
| 185 | b"9798c4640bad75c7c3227db910174e72", |
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"00000000000000000000000000000000", |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 189 | b"00000000000000000000000000000000", |
| 190 | b"ff4f8391a6a40ca5b25d23bedd44a597", |
| 191 | b"96ab5c2ff612d9dfaae8c31f30c42168", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 192 | ), |
| 193 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame] | 194 | b"00000000000000000000000000000000", |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 195 | b"00000000000000000000000000000000", |
| 196 | b"dc43be40be0e53712f7e2bf5ca707209", |
| 197 | b"6a118a874519e64e9963798a503f1d35", |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 198 | ), |
| 199 | ( |
Alex Gaynor | de9a3ee | 2013-08-09 10:42:44 -0700 | [diff] [blame] | 200 | b"00000000000000000000000000000000", |
Alex Gaynor | 6c4819d | 2013-08-09 10:50:30 -0700 | [diff] [blame^] | 201 | b"00000000000000000000000000000000", |
| 202 | b"92beedab1895a94faa69b632e5cc47ce", |
| 203 | b"cb9fceec81286ca3e989bd979b0cb284", |
| 204 | ), |
| 205 | ( |
| 206 | b"00000000000000000000000000000000", |
| 207 | b"00000000000000000000000000000000", |
| 208 | b"459264f4798f6a78bacb89c15ed3d601", |
| 209 | b"b26aeb1874e47ca8358ff22378f09144" |
| 210 | ), |
| 211 | ( |
| 212 | b"00000000000000000000000000000000", |
| 213 | b"00000000000000000000000000000000", |
| 214 | b"08a4e2efec8a8e3312ca7460b9040bbf", |
| 215 | b"58c8e00b2631686d54eab84b91f0aca1" |
Donald Stufft | 9e1a48b | 2013-08-09 00:32:30 -0400 | [diff] [blame] | 216 | ), |
| 217 | ] |