1 #!/usr/local/bin/perl -w
2 # Quick & dirty utility to generate a script for executing the
3 # FIPS 140-2 CMVP algorithm tests based on the pathnames of
4 # input algorithm test files actually present (the unqualified
5 # file names are consistent but the pathnames are not).
8 # List of all the unqualified file names we expect.
11 # FIPS test definitions
15 "PQGGen" => "fips_dssvs pqg",
16 "KeyPair" => "fips_dssvs keypair",
17 "SigGen" => "fips_dssvs siggen",
18 "SigVer" => "fips_dssvs sigver",
22 "SHA1LongMsg" => "fips_shatest",
23 "SHA1Monte" => "fips_shatest",
24 "SHA1ShortMsg" => "fips_shatest",
25 "SHA224LongMsg" => "fips_shatest",
26 "SHA224Monte" => "fips_shatest",
27 "SHA224ShortMsg" => "fips_shatest",
28 "SHA256LongMsg" => "fips_shatest",
29 "SHA256Monte" => "fips_shatest",
30 "SHA256ShortMsg" => "fips_shatest",
31 "SHA384LongMsg" => "fips_shatest",
32 "SHA384Monte" => "fips_shatest",
33 "SHA384ShortMsg" => "fips_shatest",
34 "SHA512LongMsg" => "fips_shatest",
35 "SHA512Monte" => "fips_shatest",
36 "SHA512ShortMsg" => "fips_shatest",
40 "HMAC" => "fips_hmactest",
44 "ANSI931_AES128MCT" => "fips_rngvs mct",
45 "ANSI931_AES192MCT" => "fips_rngvs mct",
46 "ANSI931_AES256MCT" => "fips_rngvs mct",
47 "ANSI931_AES128VST" => "fips_rngvs vst",
48 "ANSI931_AES192VST" => "fips_rngvs vst",
49 "ANSI931_AES256VST" => "fips_rngvs vst",
53 "SigGen15" => "fips_rsastest",
54 "SigVer15" => "fips_rsavtest",
55 "SigGenPSS" => "fips_rsastest -saltlen SALT",
56 "SigVerPSS" => "fips_rsavtest -saltlen SALT",
57 "SigGenRSA" => "fips_rsastest -x931",
58 "SigVerRSA" => "fips_rsavtest -x931",
59 "KeyGenRSA" => "fips_rsagtest",
63 "CBCGFSbox128" => "fips_aesavs -f",
64 "CBCGFSbox192" => "fips_aesavs -f",
65 "CBCGFSbox256" => "fips_aesavs -f",
66 "CBCKeySbox128" => "fips_aesavs -f",
67 "CBCKeySbox192" => "fips_aesavs -f",
68 "CBCKeySbox256" => "fips_aesavs -f",
69 "CBCMCT128" => "fips_aesavs -f",
70 "CBCMCT192" => "fips_aesavs -f",
71 "CBCMCT256" => "fips_aesavs -f",
72 "CBCMMT128" => "fips_aesavs -f",
73 "CBCMMT192" => "fips_aesavs -f",
74 "CBCMMT256" => "fips_aesavs -f",
75 "CBCVarKey128" => "fips_aesavs -f",
76 "CBCVarKey192" => "fips_aesavs -f",
77 "CBCVarKey256" => "fips_aesavs -f",
78 "CBCVarTxt128" => "fips_aesavs -f",
79 "CBCVarTxt192" => "fips_aesavs -f",
80 "CBCVarTxt256" => "fips_aesavs -f",
81 "CFB128GFSbox128" => "fips_aesavs -f",
82 "CFB128GFSbox192" => "fips_aesavs -f",
83 "CFB128GFSbox256" => "fips_aesavs -f",
84 "CFB128KeySbox128" => "fips_aesavs -f",
85 "CFB128KeySbox192" => "fips_aesavs -f",
86 "CFB128KeySbox256" => "fips_aesavs -f",
87 "CFB128MCT128" => "fips_aesavs -f",
88 "CFB128MCT192" => "fips_aesavs -f",
89 "CFB128MCT256" => "fips_aesavs -f",
90 "CFB128MMT128" => "fips_aesavs -f",
91 "CFB128MMT192" => "fips_aesavs -f",
92 "CFB128MMT256" => "fips_aesavs -f",
93 "CFB128VarKey128" => "fips_aesavs -f",
94 "CFB128VarKey192" => "fips_aesavs -f",
95 "CFB128VarKey256" => "fips_aesavs -f",
96 "CFB128VarTxt128" => "fips_aesavs -f",
97 "CFB128VarTxt192" => "fips_aesavs -f",
98 "CFB128VarTxt256" => "fips_aesavs -f",
99 "CFB8GFSbox128" => "fips_aesavs -f",
100 "CFB8GFSbox192" => "fips_aesavs -f",
101 "CFB8GFSbox256" => "fips_aesavs -f",
102 "CFB8KeySbox128" => "fips_aesavs -f",
103 "CFB8KeySbox192" => "fips_aesavs -f",
104 "CFB8KeySbox256" => "fips_aesavs -f",
105 "CFB8MCT128" => "fips_aesavs -f",
106 "CFB8MCT192" => "fips_aesavs -f",
107 "CFB8MCT256" => "fips_aesavs -f",
108 "CFB8MMT128" => "fips_aesavs -f",
109 "CFB8MMT192" => "fips_aesavs -f",
110 "CFB8MMT256" => "fips_aesavs -f",
111 "CFB8VarKey128" => "fips_aesavs -f",
112 "CFB8VarKey192" => "fips_aesavs -f",
113 "CFB8VarKey256" => "fips_aesavs -f",
114 "CFB8VarTxt128" => "fips_aesavs -f",
115 "CFB8VarTxt192" => "fips_aesavs -f",
116 "CFB8VarTxt256" => "fips_aesavs -f",
117 #"CFB1GFSbox128" => "fips_aesavs -f",
118 #"CFB1GFSbox192" => "fips_aesavs -f",
119 #"CFB1GFSbox256" => "fips_aesavs -f",
120 #"CFB1KeySbox128" => "fips_aesavs -f",
121 #"CFB1KeySbox192" => "fips_aesavs -f",
122 #"CFB1KeySbox256" => "fips_aesavs -f",
123 #"CFB1MCT128" => "fips_aesavs -f",
124 #"CFB1MCT192" => "fips_aesavs -f",
125 #"CFB1MCT256" => "fips_aesavs -f",
126 #"CFB1MMT128" => "fips_aesavs -f",
127 #"CFB1MMT192" => "fips_aesavs -f",
128 #"CFB1MMT256" => "fips_aesavs -f",
129 #"CFB1VarKey128" => "fips_aesavs -f",
130 #"CFB1VarKey192" => "fips_aesavs -f",
131 #"CFB1VarKey256" => "fips_aesavs -f",
132 #"CFB1VarTxt128" => "fips_aesavs -f",
133 #"CFB1VarTxt192" => "fips_aesavs -f",
134 #"CFB1VarTxt256" => "fips_aesavs -f",
135 "ECBGFSbox128" => "fips_aesavs -f",
136 "ECBGFSbox192" => "fips_aesavs -f",
137 "ECBGFSbox256" => "fips_aesavs -f",
138 "ECBKeySbox128" => "fips_aesavs -f",
139 "ECBKeySbox192" => "fips_aesavs -f",
140 "ECBKeySbox256" => "fips_aesavs -f",
141 "ECBMCT128" => "fips_aesavs -f",
142 "ECBMCT192" => "fips_aesavs -f",
143 "ECBMCT256" => "fips_aesavs -f",
144 "ECBMMT128" => "fips_aesavs -f",
145 "ECBMMT192" => "fips_aesavs -f",
146 "ECBMMT256" => "fips_aesavs -f",
147 "ECBVarKey128" => "fips_aesavs -f",
148 "ECBVarKey192" => "fips_aesavs -f",
149 "ECBVarKey256" => "fips_aesavs -f",
150 "ECBVarTxt128" => "fips_aesavs -f",
151 "ECBVarTxt192" => "fips_aesavs -f",
152 "ECBVarTxt256" => "fips_aesavs -f",
153 "OFBGFSbox128" => "fips_aesavs -f",
154 "OFBGFSbox192" => "fips_aesavs -f",
155 "OFBGFSbox256" => "fips_aesavs -f",
156 "OFBKeySbox128" => "fips_aesavs -f",
157 "OFBKeySbox192" => "fips_aesavs -f",
158 "OFBKeySbox256" => "fips_aesavs -f",
159 "OFBMCT128" => "fips_aesavs -f",
160 "OFBMCT192" => "fips_aesavs -f",
161 "OFBMCT256" => "fips_aesavs -f",
162 "OFBMMT128" => "fips_aesavs -f",
163 "OFBMMT192" => "fips_aesavs -f",
164 "OFBMMT256" => "fips_aesavs -f",
165 "OFBVarKey128" => "fips_aesavs -f",
166 "OFBVarKey192" => "fips_aesavs -f",
167 "OFBVarKey256" => "fips_aesavs -f",
168 "OFBVarTxt128" => "fips_aesavs -f",
169 "OFBVarTxt192" => "fips_aesavs -f",
170 "OFBVarTxt256" => "fips_aesavs -f",
174 "TCBCinvperm" => "fips_desmovs -f",
175 "TCBCMMT1" => "fips_desmovs -f",
176 "TCBCMMT2" => "fips_desmovs -f",
177 "TCBCMMT3" => "fips_desmovs -f",
178 "TCBCMonte1" => "fips_desmovs -f",
179 "TCBCMonte2" => "fips_desmovs -f",
180 "TCBCMonte3" => "fips_desmovs -f",
181 "TCBCpermop" => "fips_desmovs -f",
182 "TCBCsubtab" => "fips_desmovs -f",
183 "TCBCvarkey" => "fips_desmovs -f",
184 "TCBCvartext" => "fips_desmovs -f",
185 "TCFB64invperm" => "fips_desmovs -f",
186 "TCFB64MMT1" => "fips_desmovs -f",
187 "TCFB64MMT2" => "fips_desmovs -f",
188 "TCFB64MMT3" => "fips_desmovs -f",
189 "TCFB64Monte1" => "fips_desmovs -f",
190 "TCFB64Monte2" => "fips_desmovs -f",
191 "TCFB64Monte3" => "fips_desmovs -f",
192 "TCFB64permop" => "fips_desmovs -f",
193 "TCFB64subtab" => "fips_desmovs -f",
194 "TCFB64varkey" => "fips_desmovs -f",
195 "TCFB64vartext" => "fips_desmovs -f",
196 "TCFB8invperm" => "fips_desmovs -f",
197 "TCFB8MMT1" => "fips_desmovs -f",
198 "TCFB8MMT2" => "fips_desmovs -f",
199 "TCFB8MMT3" => "fips_desmovs -f",
200 "TCFB8Monte1" => "fips_desmovs -f",
201 "TCFB8Monte2" => "fips_desmovs -f",
202 "TCFB8Monte3" => "fips_desmovs -f",
203 "TCFB8permop" => "fips_desmovs -f",
204 "TCFB8subtab" => "fips_desmovs -f",
205 "TCFB8varkey" => "fips_desmovs -f",
206 "TCFB8vartext" => "fips_desmovs -f",
207 "TECBinvperm" => "fips_desmovs -f",
208 "TECBMMT1" => "fips_desmovs -f",
209 "TECBMMT2" => "fips_desmovs -f",
210 "TECBMMT3" => "fips_desmovs -f",
211 "TECBMonte1" => "fips_desmovs -f",
212 "TECBMonte2" => "fips_desmovs -f",
213 "TECBMonte3" => "fips_desmovs -f",
214 "TECBpermop" => "fips_desmovs -f",
215 "TECBsubtab" => "fips_desmovs -f",
216 "TECBvarkey" => "fips_desmovs -f",
217 "TECBvartext" => "fips_desmovs -f",
218 "TOFBinvperm" => "fips_desmovs -f",
219 "TOFBMMT1" => "fips_desmovs -f",
220 "TOFBMMT2" => "fips_desmovs -f",
221 "TOFBMMT3" => "fips_desmovs -f",
222 "TOFBMonte1" => "fips_desmovs -f",
223 "TOFBMonte2" => "fips_desmovs -f",
224 "TOFBMonte3" => "fips_desmovs -f",
225 "TOFBpermop" => "fips_desmovs -f",
226 "TOFBsubtab" => "fips_desmovs -f",
227 "TOFBvarkey" => "fips_desmovs -f",
228 "TOFBvartext" => "fips_desmovs -f",
229 "TCBCinvperm" => "fips_desmovs -f",
230 "TCBCMMT1" => "fips_desmovs -f",
231 "TCBCMMT2" => "fips_desmovs -f",
232 "TCBCMMT3" => "fips_desmovs -f",
233 "TCBCMonte1" => "fips_desmovs -f",
234 "TCBCMonte2" => "fips_desmovs -f",
235 "TCBCMonte3" => "fips_desmovs -f",
236 "TCBCpermop" => "fips_desmovs -f",
237 "TCBCsubtab" => "fips_desmovs -f",
238 "TCBCvarkey" => "fips_desmovs -f",
239 "TCBCvartext" => "fips_desmovs -f",
240 "TCFB64invperm" => "fips_desmovs -f",
241 "TCFB64MMT1" => "fips_desmovs -f",
242 "TCFB64MMT2" => "fips_desmovs -f",
243 "TCFB64MMT3" => "fips_desmovs -f",
244 "TCFB64Monte1" => "fips_desmovs -f",
245 "TCFB64Monte2" => "fips_desmovs -f",
246 "TCFB64Monte3" => "fips_desmovs -f",
247 "TCFB64permop" => "fips_desmovs -f",
248 "TCFB64subtab" => "fips_desmovs -f",
249 "TCFB64varkey" => "fips_desmovs -f",
250 "TCFB64vartext" => "fips_desmovs -f",
251 "TCFB8invperm" => "fips_desmovs -f",
252 "TCFB8MMT1" => "fips_desmovs -f",
253 "TCFB8MMT2" => "fips_desmovs -f",
254 "TCFB8MMT3" => "fips_desmovs -f",
255 "TCFB8Monte1" => "fips_desmovs -f",
256 "TCFB8Monte2" => "fips_desmovs -f",
257 "TCFB8Monte3" => "fips_desmovs -f",
258 "TCFB8permop" => "fips_desmovs -f",
259 "TCFB8subtab" => "fips_desmovs -f",
260 "TCFB8varkey" => "fips_desmovs -f",
261 "TCFB8vartext" => "fips_desmovs -f",
262 "TECBinvperm" => "fips_desmovs -f",
263 "TECBMMT1" => "fips_desmovs -f",
264 "TECBMMT2" => "fips_desmovs -f",
265 "TECBMMT3" => "fips_desmovs -f",
266 "TECBMonte1" => "fips_desmovs -f",
267 "TECBMonte2" => "fips_desmovs -f",
268 "TECBMonte3" => "fips_desmovs -f",
269 "TECBpermop" => "fips_desmovs -f",
270 "TECBsubtab" => "fips_desmovs -f",
271 "TECBvarkey" => "fips_desmovs -f",
272 "TECBvartext" => "fips_desmovs -f",
273 "TOFBinvperm" => "fips_desmovs -f",
274 "TOFBMMT1" => "fips_desmovs -f",
275 "TOFBMMT2" => "fips_desmovs -f",
276 "TOFBMMT3" => "fips_desmovs -f",
277 "TOFBMonte1" => "fips_desmovs -f",
278 "TOFBMonte2" => "fips_desmovs -f",
279 "TOFBMonte3" => "fips_desmovs -f",
280 "TOFBpermop" => "fips_desmovs -f",
281 "TOFBsubtab" => "fips_desmovs -f",
282 "TOFBvarkey" => "fips_desmovs -f",
283 "TOFBvartext" => "fips_desmovs -f"
287 "SigVerPSS (salt 0)" => "SigVerPSS",
288 "SigVerPSS (salt 62)" => "SigVerPSS",
289 "SigGenPSS (salt 0)" => "SigGenPSS",
290 "SigGenPSS (salt 62)" => "SigGenPSS",
294 my $win32 = $^O =~ m/mswin/i;
304 my @bogus = (); # list of unmatched *.rsp files
306 my %_programs = (); # list of external programs to check
314 elsif ($_ eq "--onedir")
318 elsif ($_ eq "--debug")
322 elsif ($_ eq "--quiet")
326 elsif (/--dir=(.*)$/)
330 elsif (/--rspdir=(.*)$/)
334 elsif (/--rspignore$/)
338 elsif (/--tprefix=(.*)$/)
342 elsif (/--shwrap_prefix=(.*)$/)
346 elsif (/--filter=(.*)$/)
350 elsif (/--outfile=(.*)$/)
361 $tvdir = "." unless defined $tvdir;
365 if (!defined $tprefix)
373 $tprefix = "..\\out32dll\\";
379 rem Test vector run script
380 rem Auto generated by mkfipsscr.pl script
390 $tprefix = "./" unless defined $tprefix;
391 $shwrap_prefix = "./" unless defined $shwrap_prefix;
395 $tprefix = "../test/" unless defined $tprefix;
396 $shwrap_prefix = "../util/" unless defined $shwrap_prefix;
402 # Test vector run script
403 # Auto generated by mkfipsscr.pl script
410 foreach (keys %fips_tests)
415 for (keys %salt_names)
420 recurse_test($win32, $tprefix, $filter, $tvdir);
422 while (($key, $value) = each %salt_found)
424 &countentry($key, $value);
425 delete $fips_found{$salt_names{$key}};
427 while (($key, $value) = each %fips_found)
429 &countentry($key, $value);
432 # If no fatal errors write out the script file
433 $outfile = "fipstests.sh" unless defined $outfile;
434 open(OUT, ">$outfile") || die "Error opening $outfile: $!";
436 if (!$rspignore && @bogus)
438 print STDERR "ERROR: please remove bogus *.rsp files\n";
440 echo $outfile generation failed due to presence of bogus *.rsp files
449 # Check for external programs
450 for (keys %_programs)
453 -x $_ || print STDERR "WARNING: program $_ not found\n";
456 #--------------------------------
458 (my $cmd) = ($0 =~ m#([^/]+)$#);
460 $cmd: generate script for CMVP algorithm tests
461 --debug Enable debug output
462 --dir=<dirname> Optional root for *.req file search
464 --onedir <dirname> Assume all components in current directory
465 --outfile=<filename> Optional name of output script, default fipstests.{sh|bat}
466 --rspdir=<dirname> Name of subdirectories containing *.rsp files, default "resp"
467 --rspignore Ignore any bogus *.rsp files
468 --shwrap_prefix=<prefix>
471 --win32 Generate script for Win32 environment
475 #--------------------------------
477 my ($key,$value) = @_;
480 print STDERR "WARNING: test file $key not found\n" unless $quiet;
484 print STDERR "WARNING: test file $key found $value times\n" unless $quiet;
488 print STDERR "Found test file $key\n" if $debug;
492 #--------------------------------
495 my ($win32, $tprefix, $filter, $dir) = @_;
497 opendir($dirh, $dir);
498 while ($_ = readdir($dirh))
500 next if ($_ eq "." || $_ eq "..");
504 if (/\/([^\/]*)\.rsp$/)
506 if (exists $fips_tests{$1})
508 $debug && print "DEBUG: $1 found, will be overwritten\n";
512 print STDERR "ERROR: bogus file $_\n";
516 next unless /$filter.*\.req$/i;
517 if (/\/([^\/]*)\.req$/ && exists $fips_tests{$1})
520 test_line($win32, $_, $tprefix, $1);
522 elsif (! /SHAmix\.req$/)
524 print STDERR "WARNING: unrecognized filename $_\n";
529 if (/$filter.*req$/i)
531 test_dir($win32, $_);
533 recurse_test($win32, $tprefix, $filter, $_);
539 #--------------------------------
542 my ($win32, $req) = @_;
544 $rsp =~ s/req$/$rspdir/;
551 echo Running tests in $req
552 if exist "$rsp" rd /s /q "$rsp"
560 echo Running tests in "$req"
568 #--------------------------------
571 my ($win32, $req, $tprefix, $tnam) = @_;
573 my $tcmd = $fips_tests{$tnam};
574 $rsp =~ s/req\/([^\/]*).req$/$rspdir\/$1.rsp/;
581 $bufout .= "$tprefix$tcmd \"$req\" \"$rsp\"\n";
582 $_programs{"$tprefix$tcmd.exe"} = 1;
587 ${shwrap_prefix}shlib_wrap.sh $tprefix$tcmd "$req" "$rsp" || { echo "$req failure" ; exit 1
590 $_programs{"${shwrap_prefix}shlib_wrap.sh"} = 1;
591 $_programs{"$tprefix$tcmd"} = 1;
595 if ($tcmd =~ /SALT$/)
597 open (IN, $req) || die "Can't Open File $req";
601 if (/^\s*#\s*salt\s+len:\s+(\d+)\s*$/i)
604 print STDERR "$req salt length $sl\n" if $debug;
605 $tcmd =~ s/SALT$/$sl/;
606 $salt_found{"$tnam (salt $sl)"}++;
611 if ($tcmd =~ /SALT$/)
613 die "Can't detect salt length for $req";
621 $bufout .= "$tprefix$tcmd < \"$req\" > \"$rsp\"\n";
622 $_programs{"$tprefix$tcmd.exe"} = 1;
627 ${shwrap_prefix}shlib_wrap.sh $tprefix$tcmd < "$req" > "$rsp" || { echo "$req failure" ; exit 1; }
629 $_programs{"$tprefix$tcmd"} = 1;