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
|
#!/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 = (
|
my %fips_tests = (
|
||||||
|
|
||||||
# FIPS test definitions
|
# FIPS test definitions
|
||||||
@ -277,8 +283,15 @@ my %fips_tests = (
|
|||||||
"TOFBvartext" => "fips_desmovs -f"
|
"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 $onedir = 0;
|
||||||
my $filter = "";
|
my $filter = "";
|
||||||
my $tvdir;
|
my $tvdir;
|
||||||
@ -287,6 +300,10 @@ my $shwrap_prefix;
|
|||||||
my $debug = 0;
|
my $debug = 0;
|
||||||
my $quiet = 0;
|
my $quiet = 0;
|
||||||
my $rspdir = "rsp";
|
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)
|
foreach (@ARGV)
|
||||||
{
|
{
|
||||||
@ -314,6 +331,10 @@ foreach (@ARGV)
|
|||||||
{
|
{
|
||||||
$rspdir = $1;
|
$rspdir = $1;
|
||||||
}
|
}
|
||||||
|
elsif (/--rspignore$/)
|
||||||
|
{
|
||||||
|
$rspignore = 1;
|
||||||
|
}
|
||||||
elsif (/--tprefix=(.*)$/)
|
elsif (/--tprefix=(.*)$/)
|
||||||
{
|
{
|
||||||
$tprefix = $1;
|
$tprefix = $1;
|
||||||
@ -330,6 +351,11 @@ foreach (@ARGV)
|
|||||||
{
|
{
|
||||||
$outfile = $1;
|
$outfile = $1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
&Help();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$tvdir = "." unless defined $tvdir;
|
$tvdir = "." unless defined $tvdir;
|
||||||
@ -347,10 +373,8 @@ if ($win32)
|
|||||||
$tprefix = "..\\out32dll\\";
|
$tprefix = "..\\out32dll\\";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$outfile = "fipstests.bat" unless defined $outfile;
|
|
||||||
open(OUT, ">$outfile");
|
|
||||||
|
|
||||||
print OUT <<END;
|
$bufinit .= <<END;
|
||||||
\@echo off
|
\@echo off
|
||||||
rem Test vector run script
|
rem Test vector run script
|
||||||
rem Auto generated by mkfipsscr.pl script
|
rem Auto generated by mkfipsscr.pl script
|
||||||
@ -371,10 +395,8 @@ else
|
|||||||
$tprefix = "../test/" unless defined $tprefix;
|
$tprefix = "../test/" unless defined $tprefix;
|
||||||
$shwrap_prefix = "../util/" unless defined $shwrap_prefix;
|
$shwrap_prefix = "../util/" unless defined $shwrap_prefix;
|
||||||
}
|
}
|
||||||
$outfile = "fipstests.sh" unless defined $outfile;
|
|
||||||
open(OUT, ">$outfile");
|
|
||||||
|
|
||||||
print OUT <<END;
|
$bufinit .= <<END;
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Test vector run script
|
# Test vector run script
|
||||||
@ -389,11 +411,70 @@ foreach (keys %fips_tests)
|
|||||||
{
|
{
|
||||||
$fips_found{$_} = 0;
|
$fips_found{$_} = 0;
|
||||||
}
|
}
|
||||||
|
my %saltPSS;
|
||||||
|
for (keys %salt_names)
|
||||||
|
{
|
||||||
|
$salt_found{$_} = 0;
|
||||||
|
}
|
||||||
|
|
||||||
recurse_test($win32, $tprefix, $filter, $tvdir);
|
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)
|
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)
|
if ($value == 0)
|
||||||
{
|
{
|
||||||
print STDERR "WARNING: test file $key not found\n" unless $quiet;
|
print STDERR "WARNING: test file $key not found\n" unless $quiet;
|
||||||
@ -408,7 +489,7 @@ while (($key, $value) = each %fips_found)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#--------------------------------
|
||||||
sub recurse_test
|
sub recurse_test
|
||||||
{
|
{
|
||||||
my ($win32, $tprefix, $filter, $dir) = @_;
|
my ($win32, $tprefix, $filter, $dir) = @_;
|
||||||
@ -420,17 +501,29 @@ sub recurse_test
|
|||||||
$_ = "$dir/$_";
|
$_ = "$dir/$_";
|
||||||
if (-f "$_")
|
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;
|
next unless /$filter.*\.req$/i;
|
||||||
if (/\/([^\/]*)\.req$/ && exists $fips_tests{$1})
|
if (/\/([^\/]*)\.req$/ && exists $fips_tests{$1})
|
||||||
{
|
{
|
||||||
$fips_found{$1}++;
|
$fips_found{$1}++;
|
||||||
test_line($win32, $_, $tprefix, $fips_tests{$1});
|
test_line($win32, $_, $tprefix, $1);
|
||||||
}
|
}
|
||||||
elsif (! /SHAmix\.req$/)
|
elsif (! /SHAmix\.req$/)
|
||||||
{
|
{
|
||||||
print STDERR "WARNING: unrecognized filename $_\n";
|
print STDERR "WARNING: unrecognized filename $_\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif (-d "$_")
|
elsif (-d "$_")
|
||||||
{
|
{
|
||||||
if (/$filter.*req$/i)
|
if (/$filter.*req$/i)
|
||||||
@ -443,6 +536,7 @@ sub recurse_test
|
|||||||
closedir($dirh);
|
closedir($dirh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#--------------------------------
|
||||||
sub test_dir
|
sub test_dir
|
||||||
{
|
{
|
||||||
my ($win32, $req) = @_;
|
my ($win32, $req) = @_;
|
||||||
@ -452,7 +546,7 @@ sub test_dir
|
|||||||
{
|
{
|
||||||
$rsp =~ tr|/|\\|;
|
$rsp =~ tr|/|\\|;
|
||||||
$req =~ tr|/|\\|;
|
$req =~ tr|/|\\|;
|
||||||
print OUT <<END;
|
$bufout .= <<END;
|
||||||
|
|
||||||
echo Running tests in $req
|
echo Running tests in $req
|
||||||
if exist "$rsp" rd /s /q "$rsp"
|
if exist "$rsp" rd /s /q "$rsp"
|
||||||
@ -461,7 +555,7 @@ END
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print OUT <<END;
|
$bufout .= <<END;
|
||||||
|
|
||||||
echo Running tests in "$req"
|
echo Running tests in "$req"
|
||||||
rm -rf "$rsp"
|
rm -rf "$rsp"
|
||||||
@ -471,10 +565,12 @@ END
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#--------------------------------
|
||||||
sub test_line
|
sub test_line
|
||||||
{
|
{
|
||||||
my ($win32, $req, $tprefix, $tcmd) = @_;
|
my ($win32, $req, $tprefix, $tnam) = @_;
|
||||||
my $rsp = $req;
|
my $rsp = $req;
|
||||||
|
my $tcmd = $fips_tests{$tnam};
|
||||||
$rsp =~ s/req\/([^\/]*).req$/$rspdir\/$1.rsp/;
|
$rsp =~ s/req\/([^\/]*).req$/$rspdir\/$1.rsp/;
|
||||||
if ($tcmd =~ /-f$/)
|
if ($tcmd =~ /-f$/)
|
||||||
{
|
{
|
||||||
@ -482,14 +578,17 @@ sub test_line
|
|||||||
{
|
{
|
||||||
$req =~ tr|/|\\|;
|
$req =~ tr|/|\\|;
|
||||||
$rsp =~ tr|/|\\|;
|
$rsp =~ tr|/|\\|;
|
||||||
print OUT "$tprefix$tcmd \"$req\" \"$rsp\"\n";
|
$bufout .= "$tprefix$tcmd \"$req\" \"$rsp\"\n";
|
||||||
|
$_programs{"$tprefix$tcmd.exe"} = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print OUT <<END;
|
$bufout .= <<END;
|
||||||
${shwrap_prefix}shlib_wrap.sh $tprefix$tcmd "$req" "$rsp" || { echo "$req failure" ; exit 1
|
${shwrap_prefix}shlib_wrap.sh $tprefix$tcmd "$req" "$rsp" || { echo "$req failure" ; exit 1
|
||||||
}
|
}
|
||||||
END
|
END
|
||||||
|
$_programs{"${shwrap_prefix}shlib_wrap.sh"} = 1;
|
||||||
|
$_programs{"$tprefix$tcmd"} = 1;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -504,6 +603,7 @@ END
|
|||||||
my $sl = $1;
|
my $sl = $1;
|
||||||
print STDERR "$req salt length $sl\n" if $debug;
|
print STDERR "$req salt length $sl\n" if $debug;
|
||||||
$tcmd =~ s/SALT$/$sl/;
|
$tcmd =~ s/SALT$/$sl/;
|
||||||
|
$salt_found{"$tnam (salt $sl)"}++;
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -518,13 +618,15 @@ END
|
|||||||
{
|
{
|
||||||
$req =~ tr|/|\\|;
|
$req =~ tr|/|\\|;
|
||||||
$rsp =~ tr|/|\\|;
|
$rsp =~ tr|/|\\|;
|
||||||
print OUT "$tprefix$tcmd < \"$req\" > \"$rsp\"\n";
|
$bufout .= "$tprefix$tcmd < \"$req\" > \"$rsp\"\n";
|
||||||
|
$_programs{"$tprefix$tcmd.exe"} = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print OUT <<END;
|
$bufout .= <<END;
|
||||||
${shwrap_prefix}shlib_wrap.sh $tprefix$tcmd < "$req" > "$rsp" || { echo "$req failure" ; exit 1; }
|
${shwrap_prefix}shlib_wrap.sh $tprefix$tcmd < "$req" > "$rsp" || { echo "$req failure" ; exit 1; }
|
||||||
END
|
END
|
||||||
|
$_programs{"$tprefix$tcmd"} = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user