c6964e19cfadd68ea9306b678565771427fc6241
[openssl.git] / util / fipsas.pl
1
2 # FIPS assembly language preprocessor
3 # Renames all symbols in the file to
4 # their modified fips versions.
5
6
7 my @ARGS = @ARGV;
8
9 my $top = shift @ARGS;
10 my $target = shift @ARGS;
11
12 # HACK to disable operation if no OPENSSL_FIPSSYMS option.
13 # will go away when tested more fully.
14
15 my $enabled = 0;
16
17 foreach (@ARGS) { $enabled = 1 if /-DOPENSSL_FIPSSYMS/ ; }
18
19 if ($enabled == 0)
20         {
21         system @ARGS;
22         exit $?
23         }
24
25 # Open symbol rename file.
26 open(IN, "$top/fips/fipssyms.h") || die "Can't open fipssyms.h";
27
28 # Skip to assembler symbols
29 while (<IN>)
30         {
31         last if (/assembler/)
32         }
33
34 # Store all renames.
35 while (<IN>)
36         {
37         if (/^#define\s+(\w+)\s+(\w+)\b/)
38                 {
39                 $edits{$1} = $2;
40                 }
41         }
42
43 my ($from, $to);
44
45 #rename target temporarily
46 rename($target, "tmptarg.s") || die "Can't rename $target\n";
47
48 #edit target
49 open IN,"tmptarg.s";
50 open OUT, ">$target";
51
52 while (<IN>)
53 {
54         while (($from, $to) = each %edits)
55                 {
56                 s/(\b)$from(\b)/$1$to$2/g;
57                 }
58         print OUT $_;
59 }
60 # run assembler
61 system @ARGS;
62
63 my $rv = $?;
64
65 # restore target
66 unlink $target;
67 rename "tmptarg.s", $target;
68
69 die "Error executing assembler!" if $rv != 0;
70