]>
Commit | Line | Data |
---|---|---|
2b4b28dc | 1 | #!/usr/bin/perl -w |
ca8630ba | 2 | # Perl utility to run or verify FIPS 140-2 CAVP algorithm tests based on the |
2b4b28dc DSH |
3 | # pathnames of input algorithm test files actually present (the unqualified |
4 | # file names are consistent but the pathnames are not). | |
5 | # | |
6 | ||
7 | # FIPS test definitions | |
8 | # List of all the unqualified file names we expect and command lines to run | |
9 | ||
10 | # DSA tests | |
11 | my @fips_dsa_test_list = ( | |
12 | ||
13 | "DSA", | |
14 | ||
c20de038 DSH |
15 | [ "PQGGen", "fips_dssvs pqg", "path:[^C]DSA/.*PQGGen" ], |
16 | [ "KeyPair", "fips_dssvs keypair", "path:[^C]DSA/.*KeyPair" ], | |
17 | [ "SigGen", "fips_dssvs siggen", "path:[^C]DSA/.*SigGen" ], | |
18 | [ "SigVer", "fips_dssvs sigver", "path:[^C]DSA/.*SigVer" ] | |
2b4b28dc DSH |
19 | |
20 | ); | |
21 | ||
22 | my @fips_dsa_pqgver_test_list = ( | |
23 | ||
c20de038 | 24 | [ "PQGVer", "fips_dssvs pqgver", "path:[^C]DSA/.*PQGVer" ] |
49e9b978 DSH |
25 | |
26 | ); | |
27 | ||
28 | # DSA2 tests | |
29 | my @fips_dsa2_test_list = ( | |
30 | ||
31 | "DSA2", | |
32 | ||
c20de038 DSH |
33 | [ "PQGGen", "fips_dssvs pqg", "path:[^C]DSA2/.*PQGGen" ], |
34 | [ "KeyPair", "fips_dssvs keypair", "path:[^C]DSA2/.*KeyPair" ], | |
35 | [ "SigGen", "fips_dssvs siggen", "path:[^C]DSA2/.*SigGen" ], | |
36 | [ "SigVer", "fips_dssvs sigver", "path:[^C]DSA2/.*SigVer" ], | |
37 | [ "PQGVer", "fips_dssvs pqgver", "path:[^C]DSA2/.*PQGVer" ] | |
49e9b978 DSH |
38 | |
39 | ); | |
40 | ||
41 | # ECDSA and ECDSA2 tests | |
42 | my @fips_ecdsa_test_list = ( | |
43 | ||
44 | "ECDSA", | |
45 | ||
46 | [ "KeyPair", "fips_ecdsavs KeyPair", "path:/ECDSA/.*KeyPair" ], | |
47 | [ "PKV", "fips_ecdsavs PKV", "path:/ECDSA/.*PKV" ], | |
48 | [ "SigGen", "fips_ecdsavs SigGen", "path:/ECDSA/.*SigGen" ], | |
49 | [ "SigVer", "fips_ecdsavs SigVer", "path:/ECDSA/.*SigVer" ], | |
50 | ||
51 | "ECDSA2", | |
52 | ||
53 | [ "KeyPair", "fips_ecdsavs KeyPair", "path:/ECDSA2/.*KeyPair" ], | |
54 | [ "PKV", "fips_ecdsavs PKV", "path:/ECDSA2/.*PKV" ], | |
55 | [ "SigGen", "fips_ecdsavs SigGen", "path:/ECDSA2/.*SigGen" ], | |
56 | [ "SigVer", "fips_ecdsavs SigVer", "path:/ECDSA2/.*SigVer" ], | |
2b4b28dc DSH |
57 | |
58 | ); | |
59 | ||
60 | # RSA tests | |
61 | ||
62 | my @fips_rsa_test_list = ( | |
63 | ||
64 | "RSA", | |
65 | ||
66 | [ "SigGen15", "fips_rsastest" ], | |
67 | [ "SigVer15", "fips_rsavtest" ], | |
68 | [ "SigVerRSA", "fips_rsavtest -x931" ], | |
69 | [ "KeyGenRSA", "fips_rsagtest" ], | |
70 | [ "SigGenRSA", "fips_rsastest -x931" ] | |
71 | ||
72 | ); | |
73 | ||
74 | # Special cases for PSS. The filename itself is | |
75 | # not sufficient to determine the test. Addditionally we | |
76 | # need to examine the file contents to determine the salt length | |
77 | # In these cases the test filename has (saltlen) appended. | |
78 | ||
79 | # RSA PSS salt length 0 tests | |
80 | ||
81 | my @fips_rsa_pss0_test_list = ( | |
82 | ||
764ef439 | 83 | [ "SigGenPSS(0)", "fips_rsastest -saltlen 0", |
49e9b978 | 84 | 'file:^\s*#\s*salt\s+len:\s+0\s*$' ], |
764ef439 | 85 | [ "SigVerPSS(0)", "fips_rsavtest -saltlen 0", |
49e9b978 | 86 | 'file:^\s*#\s*salt\s+len:\s+0\s*$' ], |
2b4b28dc DSH |
87 | |
88 | ); | |
89 | ||
90 | # RSA PSS salt length 62 tests | |
91 | ||
92 | my @fips_rsa_pss62_test_list = ( | |
764ef439 | 93 | [ "SigGenPSS(62)", "fips_rsastest -saltlen 62", |
49e9b978 | 94 | 'file:^\s*#\s*salt\s+len:\s+62\s*$' ], |
764ef439 | 95 | [ "SigVerPSS(62)", "fips_rsavtest -saltlen 62", |
49e9b978 | 96 | 'file:^\s*#\s*salt\s+len:\s+62\s*$' ], |
2b4b28dc DSH |
97 | ); |
98 | ||
99 | # SHA tests | |
100 | ||
101 | my @fips_sha_test_list = ( | |
102 | ||
103 | "SHA", | |
104 | ||
105 | [ "SHA1LongMsg", "fips_shatest" ], | |
106 | [ "SHA1Monte", "fips_shatest" ], | |
107 | [ "SHA1ShortMsg", "fips_shatest" ], | |
108 | [ "SHA224LongMsg", "fips_shatest" ], | |
109 | [ "SHA224Monte", "fips_shatest" ], | |
110 | [ "SHA224ShortMsg", "fips_shatest" ], | |
111 | [ "SHA256LongMsg", "fips_shatest" ], | |
112 | [ "SHA256Monte", "fips_shatest" ], | |
113 | [ "SHA256ShortMsg", "fips_shatest" ], | |
114 | [ "SHA384LongMsg", "fips_shatest" ], | |
115 | [ "SHA384Monte", "fips_shatest" ], | |
116 | [ "SHA384ShortMsg", "fips_shatest" ], | |
117 | [ "SHA512LongMsg", "fips_shatest" ], | |
118 | [ "SHA512Monte", "fips_shatest" ], | |
119 | [ "SHA512ShortMsg", "fips_shatest" ] | |
120 | ||
121 | ); | |
122 | ||
123 | # HMAC | |
124 | ||
125 | my @fips_hmac_test_list = ( | |
126 | ||
127 | "HMAC", | |
128 | ||
129 | [ "HMAC", "fips_hmactest" ] | |
130 | ||
131 | ); | |
132 | ||
37942b93 RL |
133 | # CMAC |
134 | ||
135 | my @fips_cmac_test_list = ( | |
136 | ||
137 | "CMAC", | |
138 | ||
d8ba2a42 RL |
139 | [ "CMACGenAES128", "fips_cmactest -a aes128 -g" ], |
140 | [ "CMACVerAES128", "fips_cmactest -a aes128 -v" ], | |
141 | [ "CMACGenAES192", "fips_cmactest -a aes192 -g" ], | |
142 | [ "CMACVerAES192", "fips_cmactest -a aes192 -v" ], | |
143 | [ "CMACGenAES256", "fips_cmactest -a aes256 -g" ], | |
144 | [ "CMACVerAES256", "fips_cmactest -a aes256 -v" ], | |
145 | [ "CMACGenTDES3", "fips_cmactest -a tdes3 -g" ], | |
146 | [ "CMACVerTDES3", "fips_cmactest -a tdes3 -v" ], | |
37942b93 RL |
147 | |
148 | ); | |
149 | ||
2b4b28dc DSH |
150 | # RAND tests, AES version |
151 | ||
152 | my @fips_rand_aes_test_list = ( | |
153 | ||
154 | "RAND (AES)", | |
155 | ||
156 | [ "ANSI931_AES128MCT", "fips_rngvs mct" ], | |
157 | [ "ANSI931_AES192MCT", "fips_rngvs mct" ], | |
158 | [ "ANSI931_AES256MCT", "fips_rngvs mct" ], | |
159 | [ "ANSI931_AES128VST", "fips_rngvs vst" ], | |
160 | [ "ANSI931_AES192VST", "fips_rngvs vst" ], | |
161 | [ "ANSI931_AES256VST", "fips_rngvs vst" ] | |
162 | ||
163 | ); | |
164 | ||
165 | # RAND tests, DES2 version | |
166 | ||
167 | my @fips_rand_des2_test_list = ( | |
168 | ||
169 | "RAND (DES2)", | |
170 | ||
171 | [ "ANSI931_TDES2MCT", "fips_rngvs mct" ], | |
172 | [ "ANSI931_TDES2VST", "fips_rngvs vst" ] | |
173 | ||
174 | ); | |
175 | ||
176 | # AES tests | |
177 | ||
178 | my @fips_aes_test_list = ( | |
179 | ||
180 | "AES", | |
181 | ||
182 | [ "CBCGFSbox128", "fips_aesavs -f" ], | |
183 | [ "CBCGFSbox192", "fips_aesavs -f" ], | |
184 | [ "CBCGFSbox256", "fips_aesavs -f" ], | |
185 | [ "CBCKeySbox128", "fips_aesavs -f" ], | |
186 | [ "CBCKeySbox192", "fips_aesavs -f" ], | |
187 | [ "CBCKeySbox256", "fips_aesavs -f" ], | |
188 | [ "CBCMCT128", "fips_aesavs -f" ], | |
189 | [ "CBCMCT192", "fips_aesavs -f" ], | |
190 | [ "CBCMCT256", "fips_aesavs -f" ], | |
191 | [ "CBCMMT128", "fips_aesavs -f" ], | |
192 | [ "CBCMMT192", "fips_aesavs -f" ], | |
193 | [ "CBCMMT256", "fips_aesavs -f" ], | |
194 | [ "CBCVarKey128", "fips_aesavs -f" ], | |
195 | [ "CBCVarKey192", "fips_aesavs -f" ], | |
196 | [ "CBCVarKey256", "fips_aesavs -f" ], | |
197 | [ "CBCVarTxt128", "fips_aesavs -f" ], | |
198 | [ "CBCVarTxt192", "fips_aesavs -f" ], | |
199 | [ "CBCVarTxt256", "fips_aesavs -f" ], | |
200 | [ "CFB128GFSbox128", "fips_aesavs -f" ], | |
201 | [ "CFB128GFSbox192", "fips_aesavs -f" ], | |
202 | [ "CFB128GFSbox256", "fips_aesavs -f" ], | |
203 | [ "CFB128KeySbox128", "fips_aesavs -f" ], | |
204 | [ "CFB128KeySbox192", "fips_aesavs -f" ], | |
205 | [ "CFB128KeySbox256", "fips_aesavs -f" ], | |
206 | [ "CFB128MCT128", "fips_aesavs -f" ], | |
207 | [ "CFB128MCT192", "fips_aesavs -f" ], | |
208 | [ "CFB128MCT256", "fips_aesavs -f" ], | |
209 | [ "CFB128MMT128", "fips_aesavs -f" ], | |
210 | [ "CFB128MMT192", "fips_aesavs -f" ], | |
211 | [ "CFB128MMT256", "fips_aesavs -f" ], | |
212 | [ "CFB128VarKey128", "fips_aesavs -f" ], | |
213 | [ "CFB128VarKey192", "fips_aesavs -f" ], | |
214 | [ "CFB128VarKey256", "fips_aesavs -f" ], | |
215 | [ "CFB128VarTxt128", "fips_aesavs -f" ], | |
216 | [ "CFB128VarTxt192", "fips_aesavs -f" ], | |
217 | [ "CFB128VarTxt256", "fips_aesavs -f" ], | |
218 | [ "CFB8GFSbox128", "fips_aesavs -f" ], | |
219 | [ "CFB8GFSbox192", "fips_aesavs -f" ], | |
220 | [ "CFB8GFSbox256", "fips_aesavs -f" ], | |
221 | [ "CFB8KeySbox128", "fips_aesavs -f" ], | |
222 | [ "CFB8KeySbox192", "fips_aesavs -f" ], | |
223 | [ "CFB8KeySbox256", "fips_aesavs -f" ], | |
224 | [ "CFB8MCT128", "fips_aesavs -f" ], | |
225 | [ "CFB8MCT192", "fips_aesavs -f" ], | |
226 | [ "CFB8MCT256", "fips_aesavs -f" ], | |
227 | [ "CFB8MMT128", "fips_aesavs -f" ], | |
228 | [ "CFB8MMT192", "fips_aesavs -f" ], | |
229 | [ "CFB8MMT256", "fips_aesavs -f" ], | |
230 | [ "CFB8VarKey128", "fips_aesavs -f" ], | |
231 | [ "CFB8VarKey192", "fips_aesavs -f" ], | |
232 | [ "CFB8VarKey256", "fips_aesavs -f" ], | |
233 | [ "CFB8VarTxt128", "fips_aesavs -f" ], | |
234 | [ "CFB8VarTxt192", "fips_aesavs -f" ], | |
235 | [ "CFB8VarTxt256", "fips_aesavs -f" ], | |
236 | ||
237 | [ "ECBGFSbox128", "fips_aesavs -f" ], | |
238 | [ "ECBGFSbox192", "fips_aesavs -f" ], | |
239 | [ "ECBGFSbox256", "fips_aesavs -f" ], | |
240 | [ "ECBKeySbox128", "fips_aesavs -f" ], | |
241 | [ "ECBKeySbox192", "fips_aesavs -f" ], | |
242 | [ "ECBKeySbox256", "fips_aesavs -f" ], | |
243 | [ "ECBMCT128", "fips_aesavs -f" ], | |
244 | [ "ECBMCT192", "fips_aesavs -f" ], | |
245 | [ "ECBMCT256", "fips_aesavs -f" ], | |
246 | [ "ECBMMT128", "fips_aesavs -f" ], | |
247 | [ "ECBMMT192", "fips_aesavs -f" ], | |
248 | [ "ECBMMT256", "fips_aesavs -f" ], | |
249 | [ "ECBVarKey128", "fips_aesavs -f" ], | |
250 | [ "ECBVarKey192", "fips_aesavs -f" ], | |
251 | [ "ECBVarKey256", "fips_aesavs -f" ], | |
252 | [ "ECBVarTxt128", "fips_aesavs -f" ], | |
253 | [ "ECBVarTxt192", "fips_aesavs -f" ], | |
254 | [ "ECBVarTxt256", "fips_aesavs -f" ], | |
255 | [ "OFBGFSbox128", "fips_aesavs -f" ], | |
256 | [ "OFBGFSbox192", "fips_aesavs -f" ], | |
257 | [ "OFBGFSbox256", "fips_aesavs -f" ], | |
258 | [ "OFBKeySbox128", "fips_aesavs -f" ], | |
259 | [ "OFBKeySbox192", "fips_aesavs -f" ], | |
260 | [ "OFBKeySbox256", "fips_aesavs -f" ], | |
261 | [ "OFBMCT128", "fips_aesavs -f" ], | |
262 | [ "OFBMCT192", "fips_aesavs -f" ], | |
263 | [ "OFBMCT256", "fips_aesavs -f" ], | |
264 | [ "OFBMMT128", "fips_aesavs -f" ], | |
265 | [ "OFBMMT192", "fips_aesavs -f" ], | |
266 | [ "OFBMMT256", "fips_aesavs -f" ], | |
267 | [ "OFBVarKey128", "fips_aesavs -f" ], | |
268 | [ "OFBVarKey192", "fips_aesavs -f" ], | |
269 | [ "OFBVarKey256", "fips_aesavs -f" ], | |
270 | [ "OFBVarTxt128", "fips_aesavs -f" ], | |
271 | [ "OFBVarTxt192", "fips_aesavs -f" ], | |
272 | [ "OFBVarTxt256", "fips_aesavs -f" ] | |
273 | ||
274 | ); | |
275 | ||
276 | my @fips_aes_cfb1_test_list = ( | |
277 | ||
278 | # AES CFB1 tests | |
279 | ||
280 | [ "CFB1GFSbox128", "fips_aesavs -f" ], | |
281 | [ "CFB1GFSbox192", "fips_aesavs -f" ], | |
282 | [ "CFB1GFSbox256", "fips_aesavs -f" ], | |
283 | [ "CFB1KeySbox128", "fips_aesavs -f" ], | |
284 | [ "CFB1KeySbox192", "fips_aesavs -f" ], | |
285 | [ "CFB1KeySbox256", "fips_aesavs -f" ], | |
286 | [ "CFB1MCT128", "fips_aesavs -f" ], | |
287 | [ "CFB1MCT192", "fips_aesavs -f" ], | |
288 | [ "CFB1MCT256", "fips_aesavs -f" ], | |
289 | [ "CFB1MMT128", "fips_aesavs -f" ], | |
290 | [ "CFB1MMT192", "fips_aesavs -f" ], | |
291 | [ "CFB1MMT256", "fips_aesavs -f" ], | |
292 | [ "CFB1VarKey128", "fips_aesavs -f" ], | |
293 | [ "CFB1VarKey192", "fips_aesavs -f" ], | |
294 | [ "CFB1VarKey256", "fips_aesavs -f" ], | |
295 | [ "CFB1VarTxt128", "fips_aesavs -f" ], | |
296 | [ "CFB1VarTxt192", "fips_aesavs -f" ], | |
297 | [ "CFB1VarTxt256", "fips_aesavs -f" ] | |
298 | ||
299 | ); | |
300 | ||
84c7a8f7 DSH |
301 | my @fips_aes_ccm_test_list = ( |
302 | ||
303 | # AES CCM tests | |
304 | ||
305 | "AES CCM", | |
306 | ||
307 | [ "DVPT128", "fips_gcmtest -ccm" ], | |
308 | [ "DVPT192", "fips_gcmtest -ccm" ], | |
309 | [ "DVPT256", "fips_gcmtest -ccm" ], | |
310 | [ "VADT128", "fips_gcmtest -ccm" ], | |
311 | [ "VADT192", "fips_gcmtest -ccm" ], | |
312 | [ "VADT256", "fips_gcmtest -ccm" ], | |
313 | [ "VNT128", "fips_gcmtest -ccm" ], | |
314 | [ "VNT192", "fips_gcmtest -ccm" ], | |
315 | [ "VNT256", "fips_gcmtest -ccm" ], | |
316 | [ "VPT128", "fips_gcmtest -ccm" ], | |
317 | [ "VPT192", "fips_gcmtest -ccm" ], | |
318 | [ "VPT256", "fips_gcmtest -ccm" ], | |
319 | [ "VTT128", "fips_gcmtest -ccm" ], | |
320 | [ "VTT192", "fips_gcmtest -ccm" ], | |
321 | [ "VTT256", "fips_gcmtest -ccm" ] | |
322 | ||
323 | ); | |
324 | ||
8da18ea1 DSH |
325 | my @fips_aes_gcm_test_list = ( |
326 | ||
327 | # AES GCM tests | |
328 | ||
329 | "AES GCM", | |
330 | ||
331 | [ "gcmDecrypt128", "fips_gcmtest -decrypt" ], | |
332 | [ "gcmDecrypt192", "fips_gcmtest -decrypt" ], | |
333 | [ "gcmDecrypt256", "fips_gcmtest -decrypt" ], | |
49e9b978 DSH |
334 | [ "gcmEncryptIntIV128", "fips_gcmtest -encrypt" ], |
335 | [ "gcmEncryptIntIV192", "fips_gcmtest -encrypt" ], | |
336 | [ "gcmEncryptIntIV256", "fips_gcmtest -encrypt" ], | |
8da18ea1 DSH |
337 | |
338 | ); | |
339 | ||
da9ead8d DSH |
340 | my @fips_aes_xts_test_list = ( |
341 | # AES XTS tests | |
342 | ||
343 | "AES XTS", | |
344 | ||
345 | [ "XTSGenAES128", "fips_gcmtest -xts" ], | |
346 | [ "XTSGenAES256", "fips_gcmtest -xts" ], | |
347 | ||
348 | ); | |
349 | ||
2b4b28dc DSH |
350 | # Triple DES tests |
351 | ||
352 | my @fips_des3_test_list = ( | |
353 | ||
354 | "Triple DES", | |
355 | ||
356 | [ "TCBCinvperm", "fips_desmovs -f" ], | |
357 | [ "TCBCMMT1", "fips_desmovs -f" ], | |
358 | [ "TCBCMMT2", "fips_desmovs -f" ], | |
359 | [ "TCBCMMT3", "fips_desmovs -f" ], | |
360 | [ "TCBCMonte1", "fips_desmovs -f" ], | |
361 | [ "TCBCMonte2", "fips_desmovs -f" ], | |
362 | [ "TCBCMonte3", "fips_desmovs -f" ], | |
363 | [ "TCBCpermop", "fips_desmovs -f" ], | |
364 | [ "TCBCsubtab", "fips_desmovs -f" ], | |
365 | [ "TCBCvarkey", "fips_desmovs -f" ], | |
366 | [ "TCBCvartext", "fips_desmovs -f" ], | |
367 | [ "TCFB64invperm", "fips_desmovs -f" ], | |
368 | [ "TCFB64MMT1", "fips_desmovs -f" ], | |
369 | [ "TCFB64MMT2", "fips_desmovs -f" ], | |
370 | [ "TCFB64MMT3", "fips_desmovs -f" ], | |
371 | [ "TCFB64Monte1", "fips_desmovs -f" ], | |
372 | [ "TCFB64Monte2", "fips_desmovs -f" ], | |
373 | [ "TCFB64Monte3", "fips_desmovs -f" ], | |
374 | [ "TCFB64permop", "fips_desmovs -f" ], | |
375 | [ "TCFB64subtab", "fips_desmovs -f" ], | |
376 | [ "TCFB64varkey", "fips_desmovs -f" ], | |
377 | [ "TCFB64vartext", "fips_desmovs -f" ], | |
378 | [ "TCFB8invperm", "fips_desmovs -f" ], | |
379 | [ "TCFB8MMT1", "fips_desmovs -f" ], | |
380 | [ "TCFB8MMT2", "fips_desmovs -f" ], | |
381 | [ "TCFB8MMT3", "fips_desmovs -f" ], | |
382 | [ "TCFB8Monte1", "fips_desmovs -f" ], | |
383 | [ "TCFB8Monte2", "fips_desmovs -f" ], | |
384 | [ "TCFB8Monte3", "fips_desmovs -f" ], | |
385 | [ "TCFB8permop", "fips_desmovs -f" ], | |
386 | [ "TCFB8subtab", "fips_desmovs -f" ], | |
387 | [ "TCFB8varkey", "fips_desmovs -f" ], | |
388 | [ "TCFB8vartext", "fips_desmovs -f" ], | |
389 | [ "TECBinvperm", "fips_desmovs -f" ], | |
390 | [ "TECBMMT1", "fips_desmovs -f" ], | |
391 | [ "TECBMMT2", "fips_desmovs -f" ], | |
392 | [ "TECBMMT3", "fips_desmovs -f" ], | |
393 | [ "TECBMonte1", "fips_desmovs -f" ], | |
394 | [ "TECBMonte2", "fips_desmovs -f" ], | |
395 | [ "TECBMonte3", "fips_desmovs -f" ], | |
396 | [ "TECBpermop", "fips_desmovs -f" ], | |
397 | [ "TECBsubtab", "fips_desmovs -f" ], | |
398 | [ "TECBvarkey", "fips_desmovs -f" ], | |
399 | [ "TECBvartext", "fips_desmovs -f" ], | |
400 | [ "TOFBinvperm", "fips_desmovs -f" ], | |
401 | [ "TOFBMMT1", "fips_desmovs -f" ], | |
402 | [ "TOFBMMT2", "fips_desmovs -f" ], | |
403 | [ "TOFBMMT3", "fips_desmovs -f" ], | |
404 | [ "TOFBMonte1", "fips_desmovs -f" ], | |
405 | [ "TOFBMonte2", "fips_desmovs -f" ], | |
406 | [ "TOFBMonte3", "fips_desmovs -f" ], | |
407 | [ "TOFBpermop", "fips_desmovs -f" ], | |
408 | [ "TOFBsubtab", "fips_desmovs -f" ], | |
409 | [ "TOFBvarkey", "fips_desmovs -f" ], | |
410 | [ "TOFBvartext", "fips_desmovs -f" ] | |
411 | ||
412 | ); | |
413 | ||
414 | my @fips_des3_cfb1_test_list = ( | |
415 | ||
416 | # DES3 CFB1 tests | |
417 | ||
418 | [ "TCFB1invperm", "fips_desmovs -f" ], | |
419 | [ "TCFB1MMT1", "fips_desmovs -f" ], | |
420 | [ "TCFB1MMT2", "fips_desmovs -f" ], | |
421 | [ "TCFB1MMT3", "fips_desmovs -f" ], | |
422 | [ "TCFB1Monte1", "fips_desmovs -f" ], | |
423 | [ "TCFB1Monte2", "fips_desmovs -f" ], | |
424 | [ "TCFB1Monte3", "fips_desmovs -f" ], | |
425 | [ "TCFB1permop", "fips_desmovs -f" ], | |
426 | [ "TCFB1subtab", "fips_desmovs -f" ], | |
427 | [ "TCFB1varkey", "fips_desmovs -f" ], | |
428 | [ "TCFB1vartext", "fips_desmovs -f" ], | |
429 | ||
430 | ); | |
431 | ||
84c7a8f7 DSH |
432 | my @fips_drbg_test_list = ( |
433 | ||
434 | # SP800-90 DRBG tests | |
435 | "SP800-90 DRBG", | |
436 | [ "CTR_DRBG", "fips_drbgvs" ], | |
7fdcb457 | 437 | [ "Dual_EC_DRBG", "fips_drbgvs" ], |
49e9b978 DSH |
438 | [ "Hash_DRBG", "fips_drbgvs" ], |
439 | [ "HMAC_DRBG", "fips_drbgvs" ] | |
7aaa88e5 DSH |
440 | |
441 | ); | |
442 | ||
443 | my @fips_dh_test_list = ( | |
444 | ||
445 | # DH | |
446 | "DH Ephemeral Primitives Only", | |
447 | [ "KASValidityTest_FFCEphem_NOKC_ZZOnly_init", "fips_dhvs dhver" ], | |
448 | [ "KASValidityTest_FFCEphem_NOKC_ZZOnly_resp", "fips_dhvs dhver" ], | |
449 | ||
450 | ); | |
451 | ||
452 | my @fips_ecdh_test_list = ( | |
453 | ||
454 | # ECDH | |
455 | "ECDH Ephemeral Primitives Only", | |
00220f81 | 456 | [ "KAS_ECC_CDH_PrimitiveTest", "fips_ecdhvs ecdhgen" ], |
49e9b978 DSH |
457 | # [ "KASValidityTest_ECCEphemeralUnified_NOKC_ZZOnly_init", |
458 | # "fips_ecdhvs ecdhver" ], | |
459 | # [ "KASValidityTest_ECCEphemeralUnified_NOKC_ZZOnly_resp", | |
460 | # "fips_ecdhvs ecdhver" ], | |
84c7a8f7 DSH |
461 | |
462 | ); | |
463 | ||
464 | ||
2b4b28dc DSH |
465 | # Verification special cases. |
466 | # In most cases the output of a test is deterministic and | |
467 | # it can be compared to a known good result. A few involve | |
468 | # the genration and use of random keys and the output will | |
469 | # be different each time. In thoses cases we perform special tests | |
470 | # to simply check their consistency. For example signature generation | |
471 | # output will be run through signature verification to see if all outputs | |
472 | # show as valid. | |
473 | # | |
474 | ||
475 | my %verify_special = ( | |
e15acd9d DSH |
476 | "DSA:PQGGen" => "fips_dssvs pqgver", |
477 | "DSA:KeyPair" => "fips_dssvs keyver", | |
478 | "DSA:SigGen" => "fips_dssvs sigver", | |
479 | "DSA2:PQGGen" => "fips_dssvs pqgver", | |
480 | "DSA2:KeyPair" => "fips_dssvs keyver", | |
481 | "DSA2:SigGen" => "fips_dssvs sigver", | |
482 | "ECDSA:KeyPair" => "fips_ecdsavs PKV", | |
483 | "ECDSA:SigGen" => "fips_ecdsavs SigVer", | |
484 | "ECDSA2:KeyPair" => "fips_ecdsavs PKV", | |
485 | "ECDSA2:SigGen" => "fips_ecdsavs SigVer", | |
486 | "RSA:SigGen15" => "fips_rsavtest", | |
487 | "RSA:SigGenRSA" => "fips_rsavtest -x931", | |
488 | "RSA:SigGenPSS(0)" => "fips_rsavtest -saltlen 0", | |
489 | "RSA:SigGenPSS(62)" => "fips_rsavtest -saltlen 62", | |
98bc8067 | 490 | "ECDH Ephemeral Primitives Only:KAS_ECC_CDH_PrimitiveTest" => "skip" |
2b4b28dc DSH |
491 | ); |
492 | ||
493 | my $win32 = $^O =~ m/mswin/i; | |
494 | my $onedir = 0; | |
495 | my $filter = ""; | |
496 | my $tvdir; | |
497 | my $tprefix; | |
2b4b28dc DSH |
498 | my $debug = 0; |
499 | my $quiet = 0; | |
500 | my $notest = 0; | |
501 | my $verify = 1; | |
b38fd40d | 502 | my $rspdir = "resp"; |
2b4b28dc DSH |
503 | my $ignore_missing = 0; |
504 | my $ignore_bogus = 0; | |
505 | my $bufout = ''; | |
506 | my $list_tests = 0; | |
ca8630ba DSH |
507 | my $minimal_script = 0; |
508 | my $outfile = ''; | |
84c7a8f7 | 509 | my $no_warn_missing = 0; |
79796269 | 510 | my $no_warn_bogus = 0; |
1eb89396 DSH |
511 | my $rmcmd = "rm -rf"; |
512 | my $mkcmd = "mkdir"; | |
98bc8067 | 513 | my $cmpall = 0; |
2b4b28dc DSH |
514 | |
515 | my %fips_enabled = ( | |
516 | dsa => 1, | |
49e9b978 DSH |
517 | dsa2 => 2, |
518 | "dsa-pqgver" => 2, | |
519 | ecdsa => 2, | |
2b4b28dc | 520 | rsa => 1, |
e15acd9d | 521 | "rsa-pss0" => 2, |
2b4b28dc DSH |
522 | "rsa-pss62" => 1, |
523 | sha => 1, | |
524 | hmac => 1, | |
49e9b978 | 525 | cmac => 2, |
2b4b28dc DSH |
526 | "rand-aes" => 1, |
527 | "rand-des2" => 0, | |
528 | aes => 1, | |
49e9b978 | 529 | "aes-cfb1" => 2, |
2b4b28dc | 530 | des3 => 1, |
49e9b978 DSH |
531 | "des3-cfb1" => 2, |
532 | drbg => 2, | |
533 | "aes-ccm" => 2, | |
534 | "aes-xts" => 2, | |
535 | "aes-gcm" => 2, | |
7aaa88e5 | 536 | dh => 0, |
49e9b978 | 537 | ecdh => 2, |
e15acd9d | 538 | v2 => 1, |
2b4b28dc DSH |
539 | ); |
540 | ||
541 | foreach (@ARGV) { | |
542 | if ( $_ eq "--win32" ) { | |
543 | $win32 = 1; | |
544 | } | |
545 | elsif ( $_ eq "--onedir" ) { | |
546 | $onedir = 1; | |
547 | } | |
548 | elsif ( $_ eq "--debug" ) { | |
549 | $debug = 1; | |
550 | } | |
84c7a8f7 DSH |
551 | elsif ( $_ eq "--quiet-missing" ) { |
552 | $ignore_missing = 1; | |
553 | $no_warn_missing = 1; | |
554 | } | |
2b4b28dc DSH |
555 | elsif ( $_ eq "--ignore-missing" ) { |
556 | $ignore_missing = 1; | |
557 | } | |
79796269 DSH |
558 | elsif ( $_ eq "--quiet-bogus" ) { |
559 | $ignore_bogus = 1; | |
560 | $no_warn_bogus = 1; | |
561 | } | |
2b4b28dc DSH |
562 | elsif ( $_ eq "--ignore-bogus" ) { |
563 | $ignore_bogus = 1; | |
564 | } | |
ca8630ba DSH |
565 | elsif ( $_ eq "--minimal-script" ) { |
566 | $minimal_script = 1; | |
567 | } | |
568 | elsif (/--generate-script=(.*)$/) { | |
569 | $outfile = $1; | |
570 | $verify = 0; | |
571 | } elsif ( $_ eq "--generate" ) { | |
2b4b28dc DSH |
572 | $verify = 0; |
573 | } | |
98bc8067 DSH |
574 | elsif ( $_ eq "--compare-all" ) { |
575 | $cmpall = 1; | |
576 | } | |
2b4b28dc DSH |
577 | elsif ( $_ eq "--notest" ) { |
578 | $notest = 1; | |
579 | } | |
580 | elsif ( $_ eq "--quiet" ) { | |
581 | $quiet = 1; | |
582 | } | |
583 | elsif (/--dir=(.*)$/) { | |
584 | $tvdir = $1; | |
585 | } | |
586 | elsif (/--rspdir=(.*)$/) { | |
587 | $rspdir = $1; | |
588 | } | |
589 | elsif (/--tprefix=(.*)$/) { | |
590 | $tprefix = $1; | |
591 | } | |
a846a7ff DSH |
592 | elsif (/^--disable-all$/) { |
593 | foreach (keys %fips_enabled) { | |
594 | $fips_enabled{$_} = 0; | |
595 | } | |
596 | } | |
2b4b28dc DSH |
597 | elsif (/^--(enable|disable)-(.*)$/) { |
598 | if ( !exists $fips_enabled{$2} ) { | |
599 | print STDERR "Unknown test $2\n"; | |
79796269 | 600 | exit(1); |
2b4b28dc DSH |
601 | } |
602 | if ( $1 eq "enable" ) { | |
603 | $fips_enabled{$2} = 1; | |
604 | } | |
605 | else { | |
606 | $fips_enabled{$2} = 0; | |
607 | } | |
608 | } | |
609 | elsif (/--filter=(.*)$/) { | |
610 | $filter = $1; | |
611 | } | |
1eb89396 DSH |
612 | elsif (/--rm=(.*)$/) { |
613 | $rmcmd = $1; | |
614 | } | |
615 | elsif (/--script-tprefix=(.*)$/) { | |
616 | $stprefix = $1; | |
617 | } | |
618 | elsif (/--mkdir=(.*)$/) { | |
619 | $mkcmd = $1; | |
620 | } | |
2b4b28dc DSH |
621 | elsif (/^--list-tests$/) { |
622 | $list_tests = 1; | |
623 | } | |
624 | else { | |
625 | Help(); | |
626 | exit(1); | |
627 | } | |
628 | } | |
629 | ||
630 | my @fips_test_list; | |
631 | ||
49e9b978 DSH |
632 | |
633 | if (!$fips_enabled{"v2"}) { | |
634 | foreach (keys %fips_enabled) { | |
635 | $fips_enabled{$_} = 0 if $fips_enabled{$_} == 2; | |
636 | } | |
637 | } | |
638 | ||
2b4b28dc DSH |
639 | push @fips_test_list, @fips_dsa_test_list if $fips_enabled{"dsa"}; |
640 | push @fips_test_list, @fips_dsa_pqgver_test_list if $fips_enabled{"dsa-pqgver"}; | |
af70f1a3 | 641 | push @fips_test_list, @fips_dsa2_test_list if $fips_enabled{"dsa2"}; |
49e9b978 | 642 | push @fips_test_list, @fips_ecdsa_test_list if $fips_enabled{"ecdsa"}; |
2b4b28dc DSH |
643 | push @fips_test_list, @fips_rsa_test_list if $fips_enabled{"rsa"}; |
644 | push @fips_test_list, @fips_rsa_pss0_test_list if $fips_enabled{"rsa-pss0"}; | |
645 | push @fips_test_list, @fips_rsa_pss62_test_list if $fips_enabled{"rsa-pss62"}; | |
646 | push @fips_test_list, @fips_sha_test_list if $fips_enabled{"sha"}; | |
647 | push @fips_test_list, @fips_hmac_test_list if $fips_enabled{"hmac"}; | |
37942b93 | 648 | push @fips_test_list, @fips_cmac_test_list if $fips_enabled{"cmac"}; |
2b4b28dc DSH |
649 | push @fips_test_list, @fips_rand_aes_test_list if $fips_enabled{"rand-aes"}; |
650 | push @fips_test_list, @fips_rand_des2_test_list if $fips_enabled{"rand-des2"}; | |
651 | push @fips_test_list, @fips_aes_test_list if $fips_enabled{"aes"}; | |
652 | push @fips_test_list, @fips_aes_cfb1_test_list if $fips_enabled{"aes-cfb1"}; | |
653 | push @fips_test_list, @fips_des3_test_list if $fips_enabled{"des3"}; | |
654 | push @fips_test_list, @fips_des3_cfb1_test_list if $fips_enabled{"des3-cfb1"}; | |
84c7a8f7 DSH |
655 | push @fips_test_list, @fips_drbg_test_list if $fips_enabled{"drbg"}; |
656 | push @fips_test_list, @fips_aes_ccm_test_list if $fips_enabled{"aes-ccm"}; | |
8da18ea1 | 657 | push @fips_test_list, @fips_aes_gcm_test_list if $fips_enabled{"aes-gcm"}; |
da9ead8d | 658 | push @fips_test_list, @fips_aes_xts_test_list if $fips_enabled{"aes-xts"}; |
7aaa88e5 DSH |
659 | push @fips_test_list, @fips_dh_test_list if $fips_enabled{"dh"}; |
660 | push @fips_test_list, @fips_ecdh_test_list if $fips_enabled{"ecdh"}; | |
2b4b28dc DSH |
661 | |
662 | if ($list_tests) { | |
663 | my ( $test, $en ); | |
664 | print "=====TEST LIST=====\n"; | |
665 | foreach $test ( sort keys %fips_enabled ) { | |
666 | $en = $fips_enabled{$test}; | |
667 | $test =~ tr/[a-z]/[A-Z]/; | |
668 | printf "%-10s %s\n", $test, $en ? "enabled" : "disabled"; | |
669 | } | |
670 | exit(0); | |
671 | } | |
672 | ||
673 | foreach (@fips_test_list) { | |
674 | next unless ref($_); | |
ca8630ba DSH |
675 | my $nm = $$_[0]; |
676 | $$_[3] = ""; | |
677 | $$_[4] = ""; | |
2b4b28dc DSH |
678 | } |
679 | ||
680 | $tvdir = "." unless defined $tvdir; | |
681 | ||
682 | if ($win32) { | |
683 | if ( !defined $tprefix ) { | |
684 | if ($onedir) { | |
685 | $tprefix = ".\\"; | |
686 | } | |
687 | else { | |
688 | $tprefix = "..\\out32dll\\"; | |
689 | } | |
690 | } | |
691 | } | |
692 | else { | |
693 | if ($onedir) { | |
694 | $tprefix = "./" unless defined $tprefix; | |
2b4b28dc DSH |
695 | } |
696 | else { | |
697 | $tprefix = "../test/" unless defined $tprefix; | |
2b4b28dc DSH |
698 | } |
699 | } | |
700 | ||
ca8630ba | 701 | sanity_check_exe( $win32, $tprefix) if $outfile eq ""; |
2b4b28dc DSH |
702 | |
703 | find_files( $filter, $tvdir ); | |
704 | ||
705 | sanity_check_files(); | |
706 | ||
707 | my ( $runerr, $cmperr, $cmpok, $scheckrunerr, $scheckerr, $scheckok, $skipcnt ) | |
708 | = ( 0, 0, 0, 0, 0, 0, 0 ); | |
709 | ||
710 | exit(0) if $notest; | |
ca8630ba DSH |
711 | print "Outputting commands to $outfile\n" if $outfile ne ""; |
712 | run_tests( $verify, $win32, $tprefix, $filter, $tvdir, $outfile ); | |
2b4b28dc DSH |
713 | |
714 | if ($verify) { | |
715 | print "ALGORITHM TEST VERIFY SUMMARY REPORT:\n"; | |
716 | print "Tests skipped due to missing files: $skipcnt\n"; | |
717 | print "Algorithm test program execution failures: $runerr\n"; | |
718 | print "Test comparisons successful: $cmpok\n"; | |
719 | print "Test comparisons failed: $cmperr\n"; | |
720 | print "Test sanity checks successful: $scheckok\n"; | |
721 | print "Test sanity checks failed: $scheckerr\n"; | |
722 | print "Sanity check program execution failures: $scheckrunerr\n"; | |
723 | ||
724 | if ( $runerr || $cmperr || $scheckrunerr || $scheckerr ) { | |
725 | print "***TEST FAILURE***\n"; | |
726 | } | |
727 | else { | |
728 | print "***ALL TESTS SUCCESSFUL***\n"; | |
729 | } | |
730 | } | |
ca8630ba | 731 | elsif ($outfile eq "") { |
2b4b28dc DSH |
732 | print "ALGORITHM TEST SUMMARY REPORT:\n"; |
733 | print "Tests skipped due to missing files: $skipcnt\n"; | |
734 | print "Algorithm test program execution failures: $runerr\n"; | |
735 | ||
736 | if ($runerr) { | |
737 | print "***TEST FAILURE***\n"; | |
738 | } | |
739 | else { | |
740 | print "***ALL TESTS SUCCESSFUL***\n"; | |
741 | } | |
742 | } | |
743 | ||
744 | #-------------------------------- | |
745 | sub Help { | |
746 | ( my $cmd ) = ( $0 =~ m#([^/]+)$# ); | |
747 | print <<EOF; | |
ca8630ba | 748 | $cmd: generate run CAVP algorithm tests |
e1db7c4e DSH |
749 | --debug Enable debug output |
750 | --dir=<dirname> Optional root for *.req file search | |
751 | --filter=<regexp> Regex for input files of interest | |
752 | --onedir <dirname> Assume all components in current directory | |
753 | --rspdir=<dirname> Name of subdirectories containing *.rsp files, default "resp" | |
754 | --tprefix=<prefix> Pathname prefix for directory containing test programs | |
755 | --ignore-bogus Ignore duplicate or bogus files | |
756 | --ignore-missing Ignore missing test files | |
757 | --quiet Shhh.... | |
758 | --quiet-bogus Skip unrecognized file warnings | |
759 | --quiet-missing Skip missing request file warnings | |
760 | --generate Generate algorithm test output | |
761 | --generate-script=<filename> Generate script to call algorithm programs | |
762 | --minimal-script Simplest possible output for --generate-script | |
763 | --win32 Win32 environment | |
764 | --compare-all Verify unconditionally for all tests | |
765 | --list-tests Show individual tests | |
766 | --mkdir=<cmd> Specify "mkdir" command | |
767 | --notest Exit before running tests | |
768 | --rm=<cmd> Specify "rm" command | |
769 | --script-tprefix Pathname prefix for --generate-script output | |
770 | --enable-<alg> Enable algorithm set <alg>. | |
771 | --disable-<alg> Disable algorithm set <alg>. | |
2b4b28dc DSH |
772 | Where <alg> can be one of: |
773 | EOF | |
774 | ||
775 | while (my ($key, $value) = each %fips_enabled) | |
776 | { | |
777 | printf "\t\t%-20s(%s by default)\n", $key , | |
49e9b978 | 778 | $value == 1 ? "enabled" : "disabled"; |
2b4b28dc DSH |
779 | } |
780 | } | |
781 | ||
782 | # Sanity check to see if all necessary executables exist | |
783 | ||
784 | sub sanity_check_exe { | |
ca8630ba | 785 | my ( $win32, $tprefix, ) = @_; |
2b4b28dc DSH |
786 | my %exe_list; |
787 | my $bad = 0; | |
2b4b28dc DSH |
788 | foreach (@fips_test_list) { |
789 | next unless ref($_); | |
790 | my $cmd = $_->[1]; | |
791 | $cmd =~ s/ .*$//; | |
792 | $cmd = $tprefix . $cmd; | |
793 | $cmd .= ".exe" if $win32; | |
794 | $exe_list{$cmd} = 1; | |
795 | } | |
796 | ||
797 | foreach ( sort keys %exe_list ) { | |
798 | if ( !-f $_ ) { | |
799 | print STDERR "ERROR: can't find executable $_\n"; | |
800 | $bad = 1; | |
801 | } | |
802 | } | |
803 | if ($bad) { | |
804 | print STDERR "FATAL ERROR: executables missing\n"; | |
805 | exit(1); | |
806 | } | |
807 | elsif ($debug) { | |
808 | print STDERR "Executable sanity check passed OK\n"; | |
809 | } | |
810 | } | |
811 | ||
812 | # Search for all request and response files | |
813 | ||
814 | sub find_files { | |
815 | my ( $filter, $dir ) = @_; | |
764ef439 | 816 | my ( $dirh, $testname, $tref ); |
2b4b28dc DSH |
817 | opendir( $dirh, $dir ); |
818 | while ( $_ = readdir($dirh) ) { | |
819 | next if ( $_ eq "." || $_ eq ".." ); | |
820 | $_ = "$dir/$_"; | |
821 | if ( -f "$_" ) { | |
822 | if (/\/([^\/]*)\.rsp$/) { | |
764ef439 | 823 | $tref = find_test($1, $_); |
764ef439 | 824 | if ( defined $tref ) { |
ca8630ba | 825 | $testname = $$tref[0]; |
764ef439 DSH |
826 | if ( $$tref[4] eq "" ) { |
827 | $$tref[4] = $_; | |
2b4b28dc DSH |
828 | } |
829 | else { | |
830 | print STDERR | |
831 | "WARNING: duplicate response file $_ for test $testname\n"; | |
832 | $nbogus++; | |
833 | } | |
834 | } | |
835 | else { | |
79796269 | 836 | print STDERR "WARNING: bogus file $_\n" unless $no_warn_bogus; |
2b4b28dc DSH |
837 | $nbogus++; |
838 | } | |
839 | } | |
840 | next unless /$filter.*\.req$/i; | |
841 | if (/\/([^\/]*)\.req$/) { | |
764ef439 | 842 | $tref = find_test($1, $_); |
764ef439 | 843 | if ( defined $tref ) { |
ca8630ba | 844 | $testname = $$tref[0]; |
764ef439 DSH |
845 | if ( $$tref[3] eq "" ) { |
846 | $$tref[3] = $_; | |
2b4b28dc DSH |
847 | } |
848 | else { | |
849 | print STDERR | |
850 | "WARNING: duplicate request file $_ for test $testname\n"; | |
851 | $nbogus++; | |
852 | } | |
853 | ||
854 | } | |
855 | elsif ( !/SHAmix\.req$/ ) { | |
79796269 | 856 | print STDERR "WARNING: unrecognized filename $_\n" unless $no_warn_bogus; |
2b4b28dc DSH |
857 | $nbogus++; |
858 | } | |
859 | } | |
860 | } | |
861 | elsif ( -d "$_" ) { | |
862 | find_files( $filter, $_ ); | |
863 | } | |
864 | } | |
865 | closedir($dirh); | |
866 | } | |
764ef439 DSH |
867 | # |
868 | # Find test based on filename. | |
869 | # In ambiguous cases search file contents for a match | |
870 | # | |
2b4b28dc | 871 | |
764ef439 | 872 | sub find_test { |
2b4b28dc | 873 | my ( $test, $path ) = @_; |
764ef439 DSH |
874 | foreach $tref (@fips_test_list) { |
875 | next unless ref($tref); | |
49e9b978 DSH |
876 | my ( $tst, $cmd, $excmd, $req, $resp ) = @$tref; |
877 | my $regexp; | |
764ef439 | 878 | $tst =~ s/\(.*$//; |
49e9b978 DSH |
879 | $test =~ s/_186-2//; |
880 | if (defined $excmd) { | |
881 | if ($excmd =~ /^path:(.*)$/) { | |
882 | my $fmatch = $1; | |
883 | return $tref if ($path =~ /$fmatch/); | |
884 | next; | |
885 | } | |
886 | elsif ($excmd =~ /^file:(.*)$/) { | |
887 | $regexp = $1; | |
888 | } | |
889 | } | |
890 | if ($test eq $tst) { | |
764ef439 DSH |
891 | return $tref if (!defined $regexp); |
892 | my $found = 0; | |
893 | my $line; | |
894 | open( IN, $path ) || die "Can't Open File $path"; | |
895 | while ($line = <IN>) { | |
896 | if ($line =~ /$regexp/i) { | |
897 | $found = 1; | |
898 | last; | |
899 | } | |
900 | } | |
901 | close IN; | |
902 | return $tref if $found == 1; | |
903 | } | |
2b4b28dc | 904 | } |
764ef439 | 905 | return undef; |
2b4b28dc DSH |
906 | } |
907 | ||
908 | sub sanity_check_files { | |
909 | my $bad = 0; | |
910 | foreach (@fips_test_list) { | |
911 | next unless ref($_); | |
764ef439 | 912 | my ( $tst, $cmd, $regexp, $req, $resp ) = @$_; |
2b4b28dc DSH |
913 | |
914 | #print STDERR "FILES $tst, $cmd, $req, $resp\n"; | |
915 | if ( $req eq "" ) { | |
84c7a8f7 | 916 | print STDERR "WARNING: missing request file for $tst\n" unless $no_warn_missing; |
2b4b28dc DSH |
917 | $bad = 1; |
918 | next; | |
919 | } | |
920 | if ( $verify && $resp eq "" ) { | |
921 | print STDERR "WARNING: no response file for test $tst\n"; | |
922 | $bad = 1; | |
923 | } | |
924 | elsif ( !$verify && $resp ne "" ) { | |
925 | print STDERR "WARNING: response file $resp will be overwritten\n"; | |
926 | } | |
927 | } | |
928 | if ($bad) { | |
929 | print STDERR "ERROR: test vector file set not complete\n"; | |
930 | exit(1) unless $ignore_missing; | |
931 | } | |
932 | if ($nbogus) { | |
933 | print STDERR | |
934 | "ERROR: $nbogus bogus or duplicate request and response files\n"; | |
935 | exit(1) unless $ignore_bogus; | |
936 | } | |
937 | if ( $debug && !$nbogus && !$bad ) { | |
938 | print STDERR "test vector file set complete\n"; | |
939 | } | |
940 | } | |
941 | ||
942 | sub run_tests { | |
ca8630ba | 943 | my ( $verify, $win32, $tprefix, $filter, $tvdir, $outfile ) = @_; |
2b4b28dc DSH |
944 | my ( $tname, $tref ); |
945 | my $bad = 0; | |
ca8630ba | 946 | my $lastdir = ""; |
41a846c6 | 947 | $stprefix = $tprefix unless defined $stprefix; |
ca8630ba DSH |
948 | if ($outfile ne "") { |
949 | open OUT, ">$outfile" || die "Can't open $outfile"; | |
950 | } | |
951 | if ($outfile ne "" && !$minimal_script) { | |
952 | if ($win32) { | |
953 | print OUT <<\END; | |
954 | @echo off | |
955 | rem Test vector run script | |
956 | rem Auto generated by fipsalgtest.pl script | |
957 | rem Do not edit | |
958 | ||
959 | echo Running Algorithm Tests | |
960 | ||
961 | END | |
962 | } else { | |
1eb89396 | 963 | print OUT <<END; |
ca8630ba DSH |
964 | #!/bin/sh |
965 | ||
966 | # Test vector run script | |
967 | # Auto generated by fipsalgtest.pl script | |
968 | # Do not edit | |
969 | ||
970 | echo Running Algorithm Tests | |
971 | ||
1eb89396 DSH |
972 | RM="$rmcmd"; |
973 | MKDIR="$mkcmd"; | |
974 | TPREFIX=$stprefix | |
975 | ||
ca8630ba DSH |
976 | END |
977 | } | |
978 | ||
979 | } | |
980 | ||
e15acd9d DSH |
981 | my $ttype = ""; |
982 | ||
2b4b28dc DSH |
983 | foreach (@fips_test_list) { |
984 | if ( !ref($_) ) { | |
ca8630ba DSH |
985 | if ($outfile ne "") { |
986 | print "Generating script for $_ tests\n"; | |
987 | print OUT "\n\n\necho \"Running $_ tests\"\n" unless $minimal_script; | |
988 | } else { | |
989 | print "Running $_ tests\n" unless $quiet; | |
990 | } | |
e15acd9d | 991 | $ttype = $_; |
2b4b28dc DSH |
992 | next; |
993 | } | |
764ef439 | 994 | my ( $tname, $tcmd, $regexp, $req, $rsp ) = @$_; |
2b4b28dc DSH |
995 | my $out = $rsp; |
996 | if ($verify) { | |
997 | $out =~ s/\.rsp$/.tst/; | |
998 | } | |
999 | if ( $req eq "" ) { | |
1000 | print STDERR | |
84c7a8f7 | 1001 | "WARNING: Request file for $tname missing: test skipped\n" unless $no_warn_missing; |
2b4b28dc DSH |
1002 | $skipcnt++; |
1003 | next; | |
1004 | } | |
1005 | if ( $verify && $rsp eq "" ) { | |
1006 | print STDERR | |
1007 | "WARNING: Response file for $tname missing: test skipped\n"; | |
1008 | $skipcnt++; | |
1009 | next; | |
1010 | } | |
1011 | elsif ( !$verify ) { | |
1012 | if ( $rsp ne "" ) { | |
1013 | print STDERR "WARNING: Response file for $tname deleted\n"; | |
1014 | unlink $rsp; | |
1015 | } | |
1016 | $out = $req; | |
1017 | $out =~ s|/req/(\S+)\.req|/$rspdir/$1.rsp|; | |
1018 | my $outdir = $out; | |
1019 | $outdir =~ s|/[^/]*$||; | |
ca8630ba DSH |
1020 | if ($outfile ne "") { |
1021 | if ($win32) { | |
1022 | $outdir =~ tr|/|\\|; | |
1023 | $req =~ tr|/|\\|; | |
1024 | $out =~ tr|/|\\|; | |
1025 | } | |
1026 | if ($outdir ne $lastdir && !$minimal_script) { | |
1027 | if ($win32) { | |
1028 | print OUT <<END | |
1029 | if exist \"$outdir\" rd /s /q "$outdir" | |
1030 | md \"$outdir\" | |
1031 | ||
1032 | END | |
1033 | } else { | |
1034 | print OUT <<END | |
c4d16287 | 1035 | \$RM \"$outdir\" |
1eb89396 | 1036 | \$MKDIR \"$outdir\" |
ca8630ba DSH |
1037 | |
1038 | END | |
1039 | } | |
1040 | $lastdir = $outdir; | |
1041 | } | |
1042 | } elsif ( !-d $outdir ) { | |
2b4b28dc DSH |
1043 | print STDERR "DEBUG: Creating directory $outdir\n" if $debug; |
1044 | mkdir($outdir) || die "Can't create directory $outdir"; | |
1045 | } | |
1046 | } | |
1eb89396 | 1047 | my $cmd = "$tcmd \"$req\" \"$out\""; |
2b4b28dc | 1048 | print STDERR "DEBUG: running test $tname\n" if ( $debug && !$verify ); |
ca8630ba | 1049 | if ($outfile ne "") { |
41a846c6 DSH |
1050 | if ($minimal_script) { |
1051 | print OUT "$stprefix$cmd\n"; | |
1052 | } else { | |
1053 | print OUT "echo \" running $tname test\"\n" unless $minimal_script; | |
1054 | print OUT "\${TPREFIX}$cmd\n"; | |
1055 | } | |
ca8630ba | 1056 | } else { |
1eb89396 | 1057 | $cmd = "$tprefix$cmd"; |
ca8630ba DSH |
1058 | system($cmd); |
1059 | if ( $? != 0 ) { | |
1060 | print STDERR | |
1061 | "WARNING: error executing test $tname for command: $cmd\n"; | |
1062 | $runerr++; | |
1063 | next; | |
1064 | } | |
2b4b28dc DSH |
1065 | } |
1066 | if ($verify) { | |
98bc8067 | 1067 | if ( exists $verify_special{"$ttype:$tname"} && !$cmpall) { |
2b4b28dc DSH |
1068 | my $vout = $rsp; |
1069 | $vout =~ s/\.rsp$/.ver/; | |
e15acd9d | 1070 | $tcmd = $verify_special{"$ttype:$tname"}; |
98bc8067 DSH |
1071 | if ($tcmd eq "skip") { |
1072 | print STDERR "DEBUG: No verify possible: skipped.\n" if $debug; | |
1073 | $scheckok++; | |
1074 | next; | |
1075 | } | |
ca8630ba | 1076 | $cmd = "$tprefix$tcmd "; |
c34a652e | 1077 | $cmd .= "\"$out\" \"$vout\""; |
2b4b28dc DSH |
1078 | system($cmd); |
1079 | if ( $? != 0 ) { | |
1080 | print STDERR | |
1081 | "WARNING: error executing verify test $tname $cmd\n"; | |
1082 | $scheckrunerr++; | |
1083 | next; | |
1084 | } | |
1085 | my ( $fcount, $pcount ) = ( 0, 0 ); | |
1086 | open VER, "$vout"; | |
1087 | while (<VER>) { | |
1088 | if (/^Result\s*=\s*(\S*)\s*$/i) | |
1089 | ||
1090 | { | |
1091 | if ( $1 eq "F" ) { | |
1092 | $fcount++; | |
1093 | } | |
1094 | else { | |
1095 | $pcount++; | |
1096 | } | |
1097 | } | |
1098 | } | |
1099 | close VER; | |
1100 | ||
1101 | unlink $vout; | |
1102 | if ( $fcount || $debug ) { | |
1103 | print STDERR "DEBUG: $tname, Pass=$pcount, Fail=$fcount\n"; | |
1104 | } | |
1105 | if ( $fcount || !$pcount ) { | |
1106 | $scheckerr++; | |
1107 | } | |
1108 | else { | |
1109 | $scheckok++; | |
1110 | } | |
1111 | ||
1112 | } | |
1113 | elsif ( !cmp_file( $tname, $rsp, $out ) ) { | |
1114 | $cmperr++; | |
1115 | } | |
1116 | else { | |
1117 | $cmpok++; | |
1118 | } | |
1119 | unlink $out; | |
1120 | } | |
1121 | } | |
ca8630ba DSH |
1122 | if ($outfile ne "") { |
1123 | print OUT "\n\necho All Tests Completed\n" unless $minimal_script; | |
1124 | close OUT; | |
1125 | } | |
2b4b28dc DSH |
1126 | } |
1127 | ||
1128 | sub cmp_file { | |
1129 | my ( $tname, $rsp, $tst ) = @_; | |
1130 | my ( $rspf, $tstf ); | |
1131 | my ( $rspline, $tstline ); | |
288fe07a | 1132 | my $monte = 0; |
2b4b28dc DSH |
1133 | if ( !open( $rspf, $rsp ) ) { |
1134 | print STDERR "ERROR: can't open request file $rsp\n"; | |
1135 | return 0; | |
1136 | } | |
1137 | if ( !open( $tstf, $tst ) ) { | |
1138 | print STDERR "ERROR: can't open output file $tst\n"; | |
1139 | return 0; | |
1140 | } | |
288fe07a | 1141 | $monte = 1 if ($rsp =~ /Monte[123]/); |
2b4b28dc DSH |
1142 | for ( ; ; ) { |
1143 | $rspline = next_line($rspf); | |
1144 | $tstline = next_line($tstf); | |
1145 | if ( !defined($rspline) && !defined($tstline) ) { | |
1146 | print STDERR "DEBUG: $tname file comparison OK\n" if $debug; | |
1147 | return 1; | |
1148 | } | |
288fe07a DSH |
1149 | # Workaround for old broken DES3 MCT format which added bogus |
1150 | # extra lines: after [ENCRYPT] or [DECRYPT] skip until first | |
1151 | # COUNT line. | |
1152 | if ($monte) { | |
1153 | if ($rspline =~ /CRYPT/) { | |
1154 | do { | |
1155 | $rspline = next_line($rspf); | |
1156 | } while (defined($rspline) && $rspline !~ /COUNT/); | |
1157 | } | |
1158 | if ($tstline =~ /CRYPT/) { | |
1159 | do { | |
1160 | $tstline = next_line($tstf); | |
1161 | } while (defined($tstline) && $tstline !~ /COUNT/); | |
1162 | } | |
1163 | } | |
2b4b28dc DSH |
1164 | if ( !defined($rspline) ) { |
1165 | print STDERR "ERROR: $tname EOF on $rsp\n"; | |
1166 | return 0; | |
1167 | } | |
1168 | if ( !defined($tstline) ) { | |
1169 | print STDERR "ERROR: $tname EOF on $tst\n"; | |
1170 | return 0; | |
1171 | } | |
1172 | ||
1173 | # Workaround for bug in RAND des2 test output */ | |
1174 | if ( $tstline =~ /^Key2 =/ && $rspline =~ /^Key1 =/ ) { | |
1175 | $rspline =~ s/^Key1/Key2/; | |
1176 | } | |
1177 | ||
1178 | if ( $tstline ne $rspline ) { | |
1179 | print STDERR "ERROR: $tname mismatch:\n"; | |
1180 | print STDERR "\t \"$tstline\" != \"$rspline\"\n"; | |
1181 | return 0; | |
1182 | } | |
1183 | } | |
1184 | return 1; | |
1185 | } | |
1186 | ||
1187 | sub next_line { | |
1188 | my ($in) = @_; | |
1189 | ||
1190 | while (<$in>) { | |
1191 | chomp; | |
1192 | ||
1193 | # Delete comments | |
1194 | s/#.*$//; | |
1195 | ||
1196 | # Ignore blank lines | |
1197 | next if (/^\s*$/); | |
1198 | ||
1199 | # Translate multiple space into one | |
1200 | s/\s+/ /g; | |
1201 | # Delete trailing whitespace | |
1202 | s/\s+$//; | |
2ecc1505 DSH |
1203 | # Remove leading zeroes |
1204 | s/= 00/= /; | |
1205 | # Translate to upper case | |
1206 | return uc $_; | |
2b4b28dc DSH |
1207 | } |
1208 | return undef; | |
1209 | } |