produce_param_decoder);
my $case_sensitive = 1;
+my $need_break = 0;
my %params = (
# Well known parameter names that core passes to providers
'SKEY_PARAM_KEY_LENGTH' => "key-length",
);
+sub output_ifdef {
+ my $cond = shift;
+
+ if (defined($cond)) {
+ print "# if" . $cond . "\n";
+ }
+}
+
+sub output_endifdef {
+ my $cond = shift;
+
+ if (defined($cond)) {
+ print "# endif\n";
+ $need_break = 1;
+ }
+}
+
# Generate string based macros for public consumption
sub generate_public_macros {
my @macros = ();
my $trieref = shift;
my $identmap = shift;
my $concat_num = shift;
+ my $ifdefs = shift;
my $idt = " ";
my $indent0 = $idt x ($n + 3);
my $indent1 = $indent0 . $idt;
$field = $identmap->{$trieref->{'name'}};
my $num = $concat_num->{$field};
+ output_ifdef($ifdefs->{$field});
printf "%sif (ossl_likely($strcmp(\"$suf\", s + $n) == 0", $indent0;
if (not $case_sensitive) {
$suf =~ tr/_/-/;
print ")) {\n";
trie_matched($field, $num, $indent1, $indent2);
printf "%s}\n", $indent0;
+ output_endifdef($ifdefs->{$field});
return;
}
printf "%sswitch(s\[%d\]) {\n", $indent0, $n;
printf "%sdefault:\n", $indent0;
for my $l (sort keys %$trieref) {
+ $need_break = 0;
if ($l eq 'val') {
$field = $identmap->{$trieref->{'val'}};
my $num = $concat_num->{$field};
printf "%sbreak;\n", $indent1;
+ output_ifdef($ifdefs->{$field});
printf "%scase '\\0':\n", $indent0;
trie_matched($field, $num, $indent1, $indent2);
- } else {
+ output_endifdef($ifdefs->{$field});
+ } else {
printf "%sbreak;\n", $indent1;
printf "%scase '%s':", $indent0, $l;
if (not $case_sensitive) {
printf " case '%s':", uc $l if ($l =~ /[a-z]/);
}
print "\n";
- generate_decoder_from_trie($n + 1, $trieref->{$l}, $identmap, $concat_num);
+ generate_decoder_from_trie($n + 1, $trieref->{$l}, $identmap, $concat_num, $ifdefs);
}
}
+ if ($need_break) {
+ printf "%sbreak;\n", $indent1;
+ }
printf "%s}\n", $indent0;
return;
}
my @keys = ();
my %prms = ();
my %concat_num = ();
+ my %ifdefs = ();
print "/* Machine generated by util/perl/OpenSSL/paramnames.pm */\n";
# Output ettable param array
$prms{$pname} = $pident;
- if (defined $pnum && $pnum eq 'hidden') {
- # Don't output the list entry for hidden items.
- # Otherwise treat them as scalars, by deleting the count entry.
- # Hidden arrays will not be supported until necessary.
- undef $pnum;
- $params[$i][3] = undef;
- } else {
- print " OSSL_PARAM_$ptype(OSSL_$pname, NULL";
- print ", 0" if $ptype eq "octet_string" || $ptype eq "octet_ptr"
- || $ptype eq "utf8_string" || $ptype eq "utf8_ptr";
- printf "),\n";
+ if (defined $pnum) {
+ if ($pnum eq 'hidden') {
+ next;
+ } elsif ($pnum eq 'fips') {
+ # The `#if' is added on output
+ $ifdefs{$pident} = ' defined(FIPS_MODULE)';
+ } elsif (substr($pnum, 0, 3) eq '#if') {
+ # Trim the `#if' from the front
+ $ifdefs{$pident} = substr($pnum, 3);
+ } else {
+ $concat_num{$pident} = $pnum;
+ }
}
-
- $concat_num{$pident} = $pnum if defined($pnum);
+ output_ifdef($ifdefs{$pident});
+ print " OSSL_PARAM_$ptype(OSSL_$pname, NULL";
+ print ", 0" if $ptype eq "octet_string" || $ptype eq "octet_ptr"
+ || $ptype eq "utf8_string" || $ptype eq "utf8_ptr";
+ printf "),\n";
+ output_endifdef($ifdefs{$pident});
}
print " OSSL_PARAM_END\n};\n#endif\n\n";
foreach my $pident (sort values %prms) {
if (not defined $done_prms{$pident}) {
$done_prms{$pident} = 1;
+ output_ifdef($ifdefs{$pident});
if (defined($concat_num{$pident})) {
printf " OSSL_PARAM *%s[%s];\n", $pident, $concat_num{$pident};
printf " int num_%s;\n", $pident;
} else {
printf " OSSL_PARAM *%s;\n", $pident;
}
+ output_endifdef($ifdefs{$pident});
}
}
print "};\n#endif\n\n";
print " memset(r, 0, sizeof(*r));\n";
print " if (p != NULL)\n";
print " for (; (s = p->key) != NULL; p++)\n";
- generate_decoder_from_trie(0, \%t, \%prms, \%concat_num);
+ generate_decoder_from_trie(0, \%t, \%prms, \%concat_num, \%ifdefs);
print " return 1;\n";
print "}\n#endif\n";
print "/* End of machine generated */";