blob: 2822eb1523c1884120d2560b1aae7202ccc64a75 [file] [log] [blame]
Donald Stufft9e1a48b2013-08-09 00:32:30 -04001import textwrap
2
3from .utils import load_nist_vectors, load_nist_vectors_from_file
4
5
6def 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 Gaynorde9a3ee2013-08-09 10:42:44 -070048 b"00000000000000000000000000000000",
49 b"00000000000000000000000000000000",
50 b"f34481ec3cc627bacd5dc3fb08f273e6",
51 b"0336763e966d92595a567cc9ce537f5e",
Donald Stufft9e1a48b2013-08-09 00:32:30 -040052 ),
53 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -070054 b"00000000000000000000000000000000",
55 b"00000000000000000000000000000000",
56 b"9798c4640bad75c7c3227db910174e72",
57 b"a9a1631bf4996954ebc093957b234589",
Donald Stufft9e1a48b2013-08-09 00:32:30 -040058 ),
59 ]
60
61
62def 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 Gaynorde9a3ee2013-08-09 10:42:44 -0700104 b"00000000000000000000000000000000",
105 b"00000000000000000000000000000000",
106 b"0336763e966d92595a567cc9ce537f5e",
107 b"f34481ec3cc627bacd5dc3fb08f273e6",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400108 ),
109 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700110 b"00000000000000000000000000000000",
111 b"00000000000000000000000000000000",
112 b"a9a1631bf4996954ebc093957b234589",
113 b"9798c4640bad75c7c3227db910174e72",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400114 ),
115 ]
116
117
118def 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 Gaynorde9a3ee2013-08-09 10:42:44 -0700125 b"0000000000000000000000000000000000000000000000000000000000000000",
126 b"00000000000000000000000000000000",
127 b"014730f80ac625fe84f026c60bfd547d",
128 b"5c9d844ed46f9885085e5d6a4f94c7d7",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400129 ),
130 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700131 b"0000000000000000000000000000000000000000000000000000000000000000",
132 b"00000000000000000000000000000000",
133 b"0b24af36193ce4665f2825d7b4749c98",
134 b"a9ff75bd7cf6613d3731c77c3b6d0c04",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400135 ),
136 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700137 b"0000000000000000000000000000000000000000000000000000000000000000",
138 b"00000000000000000000000000000000",
139 b"761c1fe41a18acf20d241650611d90f1",
140 b"623a52fcea5d443e48d9181ab32c7421",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400141 ),
142 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700143 b"0000000000000000000000000000000000000000000000000000000000000000",
144 b"00000000000000000000000000000000",
145 b"8a560769d605868ad80d819bdba03771",
146 b"38f2c7ae10612415d27ca190d27da8b4",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400147 ),
148 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700149 b"0000000000000000000000000000000000000000000000000000000000000000",
150 b"00000000000000000000000000000000",
151 b"91fbef2d15a97816060bee1feaa49afe",
152 b"1bc704f1bce135ceb810341b216d7abe",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400153 ),
154 ]
155
156
157def 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 Gaynorde9a3ee2013-08-09 10:42:44 -0700164 b"0000000000000000000000000000000000000000000000000000000000000000",
165 b"00000000000000000000000000000000",
166 b"5c9d844ed46f9885085e5d6a4f94c7d7",
167 b"014730f80ac625fe84f026c60bfd547d",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400168 ),
169 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700170 b"0000000000000000000000000000000000000000000000000000000000000000",
171 b"00000000000000000000000000000000",
172 b"a9ff75bd7cf6613d3731c77c3b6d0c04",
173 b"0b24af36193ce4665f2825d7b4749c98",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400174 ),
175 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700176 b"0000000000000000000000000000000000000000000000000000000000000000",
177 b"00000000000000000000000000000000",
178 b"623a52fcea5d443e48d9181ab32c7421",
179 b"761c1fe41a18acf20d241650611d90f1",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400180 ),
181 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700182 b"0000000000000000000000000000000000000000000000000000000000000000",
183 b"00000000000000000000000000000000",
184 b"38f2c7ae10612415d27ca190d27da8b4",
185 b"8a560769d605868ad80d819bdba03771",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400186 ),
187 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700188 b"0000000000000000000000000000000000000000000000000000000000000000",
189 b"00000000000000000000000000000000",
190 b"1bc704f1bce135ceb810341b216d7abe",
191 b"91fbef2d15a97816060bee1feaa49afe",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400192 ),
193 ]