Update mkfipsscr.pl to perform some sanity checks on testvector tree.
This commit is contained in:
parent
93d4d2b900
commit
a3a426cfb5
@ -1,5 +1,11 @@
|
||||
#!/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
|
||||
@ -277,8 +283,15 @@ my %fips_tests = (
|
||||
"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;
|
||||
@ -287,6 +300,10 @@ my $shwrap_prefix;
|
||||
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)
|
||||
{
|
||||
@ -314,6 +331,10 @@ foreach (@ARGV)
|
||||
{
|
||||
$rspdir = $1;
|
||||
}
|
||||
elsif (/--rspignore$/)
|
||||
{
|
||||
$rspignore = 1;
|
||||
}
|
||||
elsif (/--tprefix=(.*)$/)
|
||||
{
|
||||
$tprefix = $1;
|
||||
@ -330,6 +351,11 @@ foreach (@ARGV)
|
||||
{
|
||||
$outfile = $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
&Help();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
$tvdir = "." unless defined $tvdir;
|
||||
@ -347,10 +373,8 @@ if ($win32)
|
||||
$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
|
||||
@ -371,10 +395,8 @@ else
|
||||
$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
|
||||
@ -389,11 +411,70 @@ foreach (keys %fips_tests)
|
||||
{
|
||||
$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;
|
||||
@ -408,7 +489,7 @@ while (($key, $value) = each %fips_found)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#--------------------------------
|
||||
sub recurse_test
|
||||
{
|
||||
my ($win32, $tprefix, $filter, $dir) = @_;
|
||||
@ -420,17 +501,29 @@ sub recurse_test
|
||||
$_ = "$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)
|
||||
@ -443,6 +536,7 @@ sub recurse_test
|
||||
closedir($dirh);
|
||||
}
|
||||
|
||||
#--------------------------------
|
||||
sub test_dir
|
||||
{
|
||||
my ($win32, $req) = @_;
|
||||
@ -452,7 +546,7 @@ sub test_dir
|
||||
{
|
||||
$rsp =~ tr|/|\\|;
|
||||
$req =~ tr|/|\\|;
|
||||
print OUT <<END;
|
||||
$bufout .= <<END;
|
||||
|
||||
echo Running tests in $req
|
||||
if exist "$rsp" rd /s /q "$rsp"
|
||||
@ -461,7 +555,7 @@ END
|
||||
}
|
||||
else
|
||||
{
|
||||
print OUT <<END;
|
||||
$bufout .= <<END;
|
||||
|
||||
echo Running tests in "$req"
|
||||
rm -rf "$rsp"
|
||||
@ -471,10 +565,12 @@ END
|
||||
}
|
||||
}
|
||||
|
||||
#--------------------------------
|
||||
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$/)
|
||||
{
|
||||
@ -482,14 +578,17 @@ sub test_line
|
||||
{
|
||||
$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;
|
||||
}
|
||||
@ -504,6 +603,7 @@ END
|
||||
my $sl = $1;
|
||||
print STDERR "$req salt length $sl\n" if $debug;
|
||||
$tcmd =~ s/SALT$/$sl/;
|
||||
$salt_found{"$tnam (salt $sl)"}++;
|
||||
last;
|
||||
}
|
||||
}
|
||||
@ -518,13 +618,15 @@ END
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user