blob: ada524cd366504da1849365544b0895a28fd1b76 [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(
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700120 "AES/KAT/CBCGFSbox128.rsp",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400121 "ENCRYPT",
122 ["key", "iv", "plaintext", "ciphertext"],
123 ) == [
124 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700125 b"00000000000000000000000000000000",
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700126 b"00000000000000000000000000000000",
127 b"f34481ec3cc627bacd5dc3fb08f273e6",
128 b"0336763e966d92595a567cc9ce537f5e",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400129 ),
130 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700131 b"00000000000000000000000000000000",
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700132 b"00000000000000000000000000000000",
133 b"9798c4640bad75c7c3227db910174e72",
134 b"a9a1631bf4996954ebc093957b234589",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400135 ),
136 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700137 b"00000000000000000000000000000000",
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700138 b"00000000000000000000000000000000",
139 b"96ab5c2ff612d9dfaae8c31f30c42168",
140 b"ff4f8391a6a40ca5b25d23bedd44a597",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400141 ),
142 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700143 b"00000000000000000000000000000000",
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700144 b"00000000000000000000000000000000",
145 b"6a118a874519e64e9963798a503f1d35",
146 b"dc43be40be0e53712f7e2bf5ca707209",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400147 ),
148 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700149 b"00000000000000000000000000000000",
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700150 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 Stufft9e1a48b2013-08-09 00:32:30 -0400165 ),
166 ]
167
168
169def test_load_nist_vectors_from_file_decypt():
170 assert load_nist_vectors_from_file(
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700171 "AES/KAT/CBCGFSbox128.rsp",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400172 "DECRYPT",
173 ["key", "iv", "ciphertext", "plaintext"],
174 ) == [
175 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700176 b"00000000000000000000000000000000",
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700177 b"00000000000000000000000000000000",
178 b"0336763e966d92595a567cc9ce537f5e",
179 b"f34481ec3cc627bacd5dc3fb08f273e6",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400180 ),
181 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700182 b"00000000000000000000000000000000",
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700183 b"00000000000000000000000000000000",
184 b"a9a1631bf4996954ebc093957b234589",
185 b"9798c4640bad75c7c3227db910174e72",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400186 ),
187 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700188 b"00000000000000000000000000000000",
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700189 b"00000000000000000000000000000000",
190 b"ff4f8391a6a40ca5b25d23bedd44a597",
191 b"96ab5c2ff612d9dfaae8c31f30c42168",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400192 ),
193 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700194 b"00000000000000000000000000000000",
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700195 b"00000000000000000000000000000000",
196 b"dc43be40be0e53712f7e2bf5ca707209",
197 b"6a118a874519e64e9963798a503f1d35",
Donald Stufft9e1a48b2013-08-09 00:32:30 -0400198 ),
199 (
Alex Gaynorde9a3ee2013-08-09 10:42:44 -0700200 b"00000000000000000000000000000000",
Alex Gaynor6c4819d2013-08-09 10:50:30 -0700201 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 Stufft9e1a48b2013-08-09 00:32:30 -0400216 ),
217 ]