Remove PSS salt length detection hack from fipslagtest.pl by allowing a regexp

search of the file to determine its type. This will be needed for other tests
later...
This commit is contained in:
Dr. Stephen Henson 2011-04-16 23:54:19 +00:00
parent 7e5b4d6779
commit 764ef43962

View File

@ -48,17 +48,20 @@ my @fips_rsa_test_list = (
my @fips_rsa_pss0_test_list = ( my @fips_rsa_pss0_test_list = (
[ "SigGenPSS(0)", "fips_rsastest -saltlen 0" ], [ "SigGenPSS(0)", "fips_rsastest -saltlen 0",
[ "SigVerPSS(0)", "fips_rsavtest -saltlen 0" ] '^\s*#\s*salt\s+len:\s+0\s*$' ],
[ "SigVerPSS(0)", "fips_rsavtest -saltlen 0",
'^\s*#\s*salt\s+len:\s+0\s*$' ],
); );
# RSA PSS salt length 62 tests # RSA PSS salt length 62 tests
my @fips_rsa_pss62_test_list = ( my @fips_rsa_pss62_test_list = (
[ "SigGenPSS(62)", "fips_rsastest -saltlen 62" ], [ "SigGenPSS(62)", "fips_rsastest -saltlen 62",
[ "SigVerPSS(62)", "fips_rsavtest -saltlen 62" ] '^\s*#\s*salt\s+len:\s+62\s*$' ],
[ "SigVerPSS(62)", "fips_rsavtest -saltlen 62",
'^\s*#\s*salt\s+len:\s+62\s*$' ],
); );
# SHA tests # SHA tests
@ -489,8 +492,8 @@ if ($list_tests) {
foreach (@fips_test_list) { foreach (@fips_test_list) {
next unless ref($_); next unless ref($_);
my $nm = $_->[0]; my $nm = $_->[0];
$_->[2] = "";
$_->[3] = ""; $_->[3] = "";
$_->[4] = "";
print STDERR "Duplicate test $nm\n" if exists $fips_tests{$nm}; print STDERR "Duplicate test $nm\n" if exists $fips_tests{$nm};
$fips_tests{$nm} = $_; $fips_tests{$nm} = $_;
} }
@ -627,17 +630,18 @@ sub sanity_check_exe {
sub find_files { sub find_files {
my ( $filter, $dir ) = @_; my ( $filter, $dir ) = @_;
my ( $dirh, $testname ); my ( $dirh, $testname, $tref );
opendir( $dirh, $dir ); opendir( $dirh, $dir );
while ( $_ = readdir($dirh) ) { while ( $_ = readdir($dirh) ) {
next if ( $_ eq "." || $_ eq ".." ); next if ( $_ eq "." || $_ eq ".." );
$_ = "$dir/$_"; $_ = "$dir/$_";
if ( -f "$_" ) { if ( -f "$_" ) {
if (/\/([^\/]*)\.rsp$/) { if (/\/([^\/]*)\.rsp$/) {
$testname = fix_pss( $1, $_ ); $tref = find_test($1, $_);
if ( exists $fips_tests{$testname} ) { $testname = $$tref[0];
if ( $fips_tests{$testname}->[3] eq "" ) { if ( defined $tref ) {
$fips_tests{$testname}->[3] = $_; if ( $$tref[4] eq "" ) {
$$tref[4] = $_;
} }
else { else {
print STDERR print STDERR
@ -652,10 +656,11 @@ sub find_files {
} }
next unless /$filter.*\.req$/i; next unless /$filter.*\.req$/i;
if (/\/([^\/]*)\.req$/) { if (/\/([^\/]*)\.req$/) {
$testname = fix_pss( $1, $_ ); $tref = find_test($1, $_);
if ( exists $fips_tests{$testname} ) { $testname = $$tref[0];
if ( $fips_tests{$testname}->[2] eq "" ) { if ( defined $tref ) {
$fips_tests{$testname}->[2] = $_; if ( $$tref[3] eq "" ) {
$$tref[3] = $_;
} }
else { else {
print STDERR print STDERR
@ -676,35 +681,40 @@ sub find_files {
} }
closedir($dirh); closedir($dirh);
} }
#
# Find test based on filename.
# In ambiguous cases search file contents for a match
#
sub fix_pss { sub find_test {
my ( $test, $path ) = @_; my ( $test, $path ) = @_;
my $sl = ""; foreach $tref (@fips_test_list) {
local $_; next unless ref($tref);
if ( $test =~ /PSS/ ) { my ( $tst, $cmd, $regexp, $req, $resp ) = @$tref;
open( IN, $path ) || die "Can't Open File $path"; $tst =~ s/\(.*$//;
while (<IN>) { if ($tst eq $test) {
if (/^\s*#\s*salt\s+len:\s+(\d+)\s*$/i) { return $tref if (!defined $regexp);
$sl = $1; my $found = 0;
last; my $line;
} open( IN, $path ) || die "Can't Open File $path";
} while ($line = <IN>) {
close IN; if ($line =~ /$regexp/i) {
if ( $sl eq "" ) { $found = 1;
print STDERR "WARNING: No Salt length detected for file $path\n"; last;
} }
else { }
return $test . "($sl)"; close IN;
} return $tref if $found == 1;
}
} }
return $test; return undef;
} }
sub sanity_check_files { sub sanity_check_files {
my $bad = 0; my $bad = 0;
foreach (@fips_test_list) { foreach (@fips_test_list) {
next unless ref($_); next unless ref($_);
my ( $tst, $cmd, $req, $resp ) = @$_; my ( $tst, $cmd, $regexp, $req, $resp ) = @$_;
#print STDERR "FILES $tst, $cmd, $req, $resp\n"; #print STDERR "FILES $tst, $cmd, $req, $resp\n";
if ( $req eq "" ) { if ( $req eq "" ) {
@ -743,7 +753,7 @@ sub run_tests {
print "Running $_ tests\n" unless $quiet; print "Running $_ tests\n" unless $quiet;
next; next;
} }
my ( $tname, $tcmd, $req, $rsp ) = @$_; my ( $tname, $tcmd, $regexp, $req, $rsp ) = @$_;
my $out = $rsp; my $out = $rsp;
if ($verify) { if ($verify) {
$out =~ s/\.rsp$/.tst/; $out =~ s/\.rsp$/.tst/;