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;
301 my $rmcmd = "rm -rf";
307 my @bogus = (); # list of unmatched *.rsp files
310 my %_programs = (); # list of external programs to check
318 elsif ($_ eq "--onedir")
322 elsif ($_ eq "--debug")
326 elsif ($_ eq "--quiet")
330 elsif (/--dir=(.*)$/)
334 elsif (/--rspdir=(.*)$/)
338 elsif (/--noshwrap$/)
342 elsif (/--rspignore$/)
346 elsif (/--tprefix=(.*)$/)
350 elsif (/--shwrap_prefix=(.*)$/)
354 elsif (/--filter=(.*)$/)
358 elsif (/--mkdir=(.*)$/)
366 elsif (/--outfile=(.*)$/)
377 $tvdir = "." unless defined $tvdir;
381 if (!defined $tprefix)
389 $tprefix = "..\\out32dll\\";
395 rem Test vector run script
396 rem Auto generated by mkfipsscr.pl script
406 $tprefix = "./" unless defined $tprefix;
407 $shwrap_prefix = "./" unless defined $shwrap_prefix;
411 $tprefix = "../test/" unless defined $tprefix;
412 $shwrap_prefix = "../util/" unless defined $shwrap_prefix;
415 $shwrap = "${shwrap_prefix}shlib_wrap.sh " unless defined $shwrap;
420 # Test vector run script
421 # Auto generated by mkfipsscr.pl script
431 foreach (keys %fips_tests)
436 for (keys %salt_names)
441 recurse_test($win32, $tprefix, $filter, $tvdir);
443 while (($key, $value) = each %salt_found)
445 &countentry($key, $value);
446 delete $fips_found{$salt_names{$key}};
448 while (($key, $value) = each %fips_found)
450 &countentry($key, $value);
453 # If no fatal errors write out the script file
454 $outfile = "fipstests.sh" unless defined $outfile;
455 open(OUT, ">$outfile") || die "Error opening $outfile: $!";
457 if (!$rspignore && @bogus)
459 print STDERR "ERROR: please remove bogus *.rsp files\n";
461 echo $outfile generation failed due to presence of bogus *.rsp files
470 # Check for external programs
471 for (keys %_programs)
474 -x $_ || print STDERR "WARNING: program $_ not found\n";
477 #--------------------------------
479 (my $cmd) = ($0 =~ m#([^/]+)$#);
481 $cmd: generate script for CMVP algorithm tests
482 --debug Enable debug output
483 --dir=<dirname> Optional root for *.req file search
485 --onedir <dirname> Assume all components in current directory
486 --outfile=<filename> Optional name of output script, default fipstests.{sh|bat}
487 --rspdir=<dirname> Name of subdirectories containing *.rsp files, default "resp"
488 --rspignore Ignore any bogus *.rsp files
489 --shwrap_prefix=<prefix>
492 --win32 Generate script for Win32 environment
496 #--------------------------------
498 my ($key,$value) = @_;
501 print STDERR "WARNING: test file $key not found\n" unless $quiet;
505 print STDERR "WARNING: test file $key found $value times\n" unless $quiet;
509 print STDERR "Found test file $key\n" if $debug;
513 #--------------------------------
516 my ($win32, $tprefix, $filter, $dir) = @_;
518 opendir($dirh, $dir);
519 while ($_ = readdir($dirh))
521 next if ($_ eq "." || $_ eq "..");
525 if (/\/([^\/]*)\.rsp$/)
527 if (exists $fips_tests{$1})
529 $debug && print "DEBUG: $1 found, will be overwritten\n";
533 print STDERR "ERROR: bogus file $_\n";
537 next unless /$filter.*\.req$/i;
538 if (/\/([^\/]*)\.req$/ && exists $fips_tests{$1})
541 test_line($win32, $_, $tprefix, $1);
543 elsif (! /SHAmix\.req$/)
545 print STDERR "WARNING: unrecognized filename $_\n";
550 if (/$filter.*req$/i)
552 test_dir($win32, $_);
554 recurse_test($win32, $tprefix, $filter, $_);
560 #--------------------------------
563 my ($win32, $req) = @_;
565 $rsp =~ s/req$/$rspdir/;
572 echo Running tests in $req
573 if exist "$rsp" rd /s /q "$rsp"
581 echo Running tests in "$req"
589 #--------------------------------
592 my ($win32, $req, $tprefix, $tnam) = @_;
594 my $tcmd = $fips_tests{$tnam};
599 $rsp =~ s/req\/([^\/]*).req$/$rspdir\/$1.rsp/;
606 $bufout .= "$tprefix$tcmd \"$req\" \"$rsp\"\n";
607 $_programs{"$tprefix$tcmd.exe"} = 1;
612 ${shwrap}\${TPREFIX}$tcmd "$req" "$rsp" || { echo "$req failure" ; exit 1
615 $_programs{"${shwrap_prefix}shlib_wrap.sh"} = 1;
616 $_programs{"$tprefix$tcmd"} = 1;
620 if ($tcmd =~ /SALT$/)
622 open (IN, $req) || die "Can't Open File $req";
626 if (/^\s*#\s*salt\s+len:\s+(\d+)\s*$/i)
629 print STDERR "$req salt length $sl\n" if $debug;
630 $tcmd =~ s/SALT$/$sl/;
631 $salt_found{"$tnam (salt $sl)"}++;
636 if ($tcmd =~ /SALT$/)
638 die "Can't detect salt length for $req";
646 $bufout .= "$tprefix$tcmd < \"$req\" > \"$rsp\"\n";
647 $_programs{"$tprefix$tcmd.exe"} = 1;
652 ${shwrap}\${TPREFIX}$tcmd < "$req" > "$rsp" || { echo "$req failure" ; exit 1; }
654 $_programs{"$tprefix$tcmd"} = 1;