8 die "Environment variable $_ not defined!\n" unless exists $ENV{$_};
15 my ($fips_cc,$fips_cc_args, $fips_link,$fips_target, $fips_libdir, $sha1_exe)
16 = check_env
("FIPS_CC", "FIPS_CC_ARGS", "FIPS_LINK", "FIPS_TARGET",
17 "FIPSLIB_D", "FIPS_SHA1_EXE");
21 if (exists $ENV{"PREMAIN_DSO_EXE"})
23 $fips_premain_dso = $ENV{"PREMAIN_DSO_EXE"};
27 $fips_premain_dso = "";
30 check_hash
($sha1_exe, "fips_premain.c");
31 check_hash
($sha1_exe, "fipscanister.lib");
34 print "Integrity check OK\n";
36 print "$fips_cc $fips_cc_args $fips_libdir/fips_premain.c\n";
37 system "$fips_cc $fips_cc_args $fips_libdir/fips_premain.c";
38 die "First stage Compile failure" if $?
!= 0;
40 print "$fips_link @ARGV\n";
41 system "$fips_link @ARGV";
42 die "First stage Link failure" if $?
!= 0;
45 print "$fips_premain_dso $fips_target\n";
46 system("$fips_premain_dso $fips_target >$fips_target.sha1");
47 die "Get hash failure" if $?
!= 0;
48 open my $sha1_res, '<', $fips_target.".sha1" or die "Get hash failure";
49 $fips_hash=<$sha1_res>;
51 unlink $fips_target.".sha1";
53 die "Get hash failure" if $?
!= 0;
56 print "$fips_cc -DHMAC_SHA1_SIG=\\\"$fips_hash\\\" $fips_cc_args $fips_libdir/fips_premain.c\n";
57 system "$fips_cc -DHMAC_SHA1_SIG=\\\"$fips_hash\\\" $fips_cc_args $fips_libdir/fips_premain.c";
58 die "Second stage Compile failure" if $?
!= 0;
61 print "$fips_link @ARGV\n";
62 system "$fips_link @ARGV";
63 die "Second stage Link failure" if $?
!= 0;
67 my ($sha1_exe, $filename) = @_;
68 my ($hashfile, $hashval);
70 open(IN
, "${fips_libdir}/${filename}.sha1") || die "Cannot open file hash file ${fips_libdir}/${filename}.sha1";
73 $hashval = `$sha1_exe ${fips_libdir}/$filename`;
76 $hashfile =~ s/^.*=\s+//;
77 $hashval =~ s/^.*=\s+//;
78 die "Invalid hash syntax in file" if (length($hashfile) != 40);
79 die "Invalid hash received for file" if (length($hashval) != 40);
80 die "***HASH VALUE MISMATCH FOR FILE $filename ***" if ($hashval ne $hashfile);