#!/usr/local/bin/perl -w
+# Quick & dirty utility to generate a script for executing the
+# FIPS 140-2 CMVP algorithm tests based on the pathnames of
+# input algorithm test files actually present (the unqualified
+# file names are consistent but the pathnames are not).
+#
+# List of all the unqualified file names we expect.
my %fips_tests = (
# FIPS test definitions
"TOFBvartext" => "fips_desmovs -f"
);
+my %salt_names = (
+"SigVerPSS (salt 0)" => "SigVerPSS",
+"SigVerPSS (salt 62)" => "SigVerPSS",
+"SigGenPSS (salt 0)" => "SigGenPSS",
+"SigGenPSS (salt 62)" => "SigGenPSS",
+);
+
-my $win32 = 0;
+my $win32 = $^O =~ m/mswin/i;
my $onedir = 0;
my $filter = "";
my $tvdir;
my $debug = 0;
my $quiet = 0;
my $rspdir = "rsp";
+my $rspignore = 0;
+my @bogus = (); # list of unmatched *.rsp files
+my $bufout = '';
+my %_programs = (); # list of external programs to check
foreach (@ARGV)
{
{
$rspdir = $1;
}
+ elsif (/--rspignore$/)
+ {
+ $rspignore = 1;
+ }
elsif (/--tprefix=(.*)$/)
{
$tprefix = $1;
{
$outfile = $1;
}
+ else
+ {
+ &Help();
+ exit(1);
+ }
}
$tvdir = "." unless defined $tvdir;
$tprefix = "..\\out32dll\\";
}
}
- $outfile = "fipstests.bat" unless defined $outfile;
- open(OUT, ">$outfile");
- print OUT <<END;
+ $bufinit .= <<END;
\@echo off
rem Test vector run script
rem Auto generated by mkfipsscr.pl script
$tprefix = "../test/" unless defined $tprefix;
$shwrap_prefix = "../util/" unless defined $shwrap_prefix;
}
- $outfile = "fipstests.sh" unless defined $outfile;
- open(OUT, ">$outfile");
- print OUT <<END;
+ $bufinit .= <<END;
#!/bin/sh
# Test vector run script
{
$fips_found{$_} = 0;
}
+my %saltPSS;
+for (keys %salt_names)
+ {
+ $salt_found{$_} = 0;
+ }
recurse_test($win32, $tprefix, $filter, $tvdir);
+while (($key, $value) = each %salt_found)
+ {
+ &countentry($key, $value);
+ delete $fips_found{$salt_names{$key}};
+ }
while (($key, $value) = each %fips_found)
{
+ &countentry($key, $value);
+ }
+
+# If no fatal errors write out the script file
+ $outfile = "fipstests.sh" unless defined $outfile;
+ open(OUT, ">$outfile") || die "Error opening $outfile: $!";
+ print OUT $bufinit;
+ if (!$rspignore && @bogus)
+ {
+ print STDERR "ERROR: please remove bogus *.rsp files\n";
+ print OUT <<EOF;
+echo $outfile generation failed due to presence of bogus *.rsp files
+EOF
+ }
+ else
+ {
+ print OUT $bufout;
+ }
+ close OUT;
+
+# Check for external programs
+ for (keys %_programs)
+ {
+ s/ .*$//;
+ -x $_ || print STDERR "WARNING: program $_ not found\n";
+ }
+
+#--------------------------------
+sub Help {
+(my $cmd) = ($0 =~ m#([^/]+)$#);
+ print <<EOF;
+$cmd: generate script for CMVP algorithm tests
+ --debug Enable debug output
+ --dir=<dirname> Optional root for *.req file search
+ --filter=<regexp>
+ --onedir <dirname> Assume all components in current directory
+ --outfile=<filename> Optional name of output script, default fipstests.{sh|bat}
+ --rspdir=<dirname> Name of subdirectories containing *.rsp files, default "resp"
+ --rspignore Ignore any bogus *.rsp files
+ --shwrap_prefix=<prefix>
+ --tprefix=<prefix>
+ --quiet Shhh....
+ --win32 Generate script for Win32 environment
+EOF
+}
+
+#--------------------------------
+sub countentry {
+ my ($key,$value) = @_;
if ($value == 0)
{
print STDERR "WARNING: test file $key not found\n" unless $quiet;
}
}
-
+#--------------------------------
sub recurse_test
{
my ($win32, $tprefix, $filter, $dir) = @_;
$_ = "$dir/$_";
if (-f "$_")
{
+ if (/\/([^\/]*)\.rsp$/)
+ {
+ if (exists $fips_tests{$1})
+ {
+ $debug && print "DEBUG: $1 found, will be overwritten\n";
+ }
+ else
+ {
+ print STDERR "ERROR: bogus file $_\n";
+ push @bogus, $_;
+ }
+ }
next unless /$filter.*\.req$/i;
if (/\/([^\/]*)\.req$/ && exists $fips_tests{$1})
{
$fips_found{$1}++;
- test_line($win32, $_, $tprefix, $fips_tests{$1});
+ test_line($win32, $_, $tprefix, $1);
}
elsif (! /SHAmix\.req$/)
{
print STDERR "WARNING: unrecognized filename $_\n";
}
- }
+ }
elsif (-d "$_")
{
if (/$filter.*req$/i)
closedir($dirh);
}
+#--------------------------------
sub test_dir
{
my ($win32, $req) = @_;
{
$rsp =~ tr|/|\\|;
$req =~ tr|/|\\|;
- print OUT <<END;
+ $bufout .= <<END;
echo Running tests in $req
if exist "$rsp" rd /s /q "$rsp"
}
else
{
- print OUT <<END;
+ $bufout .= <<END;
echo Running tests in "$req"
rm -rf "$rsp"
}
}
+#--------------------------------
sub test_line
{
- my ($win32, $req, $tprefix, $tcmd) = @_;
+ my ($win32, $req, $tprefix, $tnam) = @_;
my $rsp = $req;
+ my $tcmd = $fips_tests{$tnam};
$rsp =~ s/req\/([^\/]*).req$/$rspdir\/$1.rsp/;
if ($tcmd =~ /-f$/)
{
{
$req =~ tr|/|\\|;
$rsp =~ tr|/|\\|;
- print OUT "$tprefix$tcmd \"$req\" \"$rsp\"\n";
+ $bufout .= "$tprefix$tcmd \"$req\" \"$rsp\"\n";
+ $_programs{"$tprefix$tcmd.exe"} = 1;
}
else
{
- print OUT <<END;
+ $bufout .= <<END;
${shwrap_prefix}shlib_wrap.sh $tprefix$tcmd "$req" "$rsp" || { echo "$req failure" ; exit 1
}
END
+ $_programs{"${shwrap_prefix}shlib_wrap.sh"} = 1;
+ $_programs{"$tprefix$tcmd"} = 1;
}
return;
}
my $sl = $1;
print STDERR "$req salt length $sl\n" if $debug;
$tcmd =~ s/SALT$/$sl/;
+ $salt_found{"$tnam (salt $sl)"}++;
last;
}
}
{
$req =~ tr|/|\\|;
$rsp =~ tr|/|\\|;
- print OUT "$tprefix$tcmd < \"$req\" > \"$rsp\"\n";
+ $bufout .= "$tprefix$tcmd < \"$req\" > \"$rsp\"\n";
+ $_programs{"$tprefix$tcmd.exe"} = 1;
}
else
{
- print OUT <<END;
+ $bufout .= <<END;
${shwrap_prefix}shlib_wrap.sh $tprefix$tcmd < "$req" > "$rsp" || { echo "$req failure" ; exit 1; }
END
+ $_programs{"$tprefix$tcmd"} = 1;
}
}