summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/objects/objxref.pl
diff options
context:
space:
mode:
authortb <>2023-07-22 18:32:05 +0000
committertb <>2023-07-22 18:32:05 +0000
commit2b1933408aa0e5cad4486c6862c788a70c48670e (patch)
tree23b647d507fee13df5656ab54ae6c84c29cbbddf /src/lib/libcrypto/objects/objxref.pl
parent4244536f1a2e55a7e32d35ed15ac7a8fe4989fd5 (diff)
downloadopenbsd-2b1933408aa0e5cad4486c6862c788a70c48670e.tar.gz
openbsd-2b1933408aa0e5cad4486c6862c788a70c48670e.tar.bz2
openbsd-2b1933408aa0e5cad4486c6862c788a70c48670e.zip
Rewrite obj_xref.c
Instead of having two unreadable tables placed in a header generated by a janky perl script from an ugly text file, use a single table inlined in the C file. This table is used to translate between signature algorithm OIDs and pairs of OIDs of a message digest and a cipher. The table has fewer than fifty entries and isn't used in a hot path. Using binary search is overkill. Just do two linear searches, one for each translation. None of the original code remains apart from the API. ok jsing
Diffstat (limited to 'src/lib/libcrypto/objects/objxref.pl')
-rw-r--r--src/lib/libcrypto/objects/objxref.pl111
1 files changed, 0 insertions, 111 deletions
diff --git a/src/lib/libcrypto/objects/objxref.pl b/src/lib/libcrypto/objects/objxref.pl
deleted file mode 100644
index 8873c91ad9..0000000000
--- a/src/lib/libcrypto/objects/objxref.pl
+++ /dev/null
@@ -1,111 +0,0 @@
1#!/usr/local/bin/perl
2
3use strict;
4
5my %xref_tbl;
6my %oid_tbl;
7
8my ($mac_file, $xref_file) = @ARGV;
9
10open(IN, $mac_file) || die "Can't open $mac_file";
11
12# Read in OID nid values for a lookup table.
13
14while (<IN>)
15 {
16 chomp;
17 my ($name, $num) = /^(\S+)\s+(\S+)$/;
18 $oid_tbl{$name} = $num;
19 }
20close IN;
21
22open(IN, $xref_file) || die "Can't open $xref_file";
23
24my $ln = 1;
25
26while (<IN>)
27 {
28 chomp;
29 s/#.*$//;
30 next if (/^\S*$/);
31 my ($xr, $p1, $p2) = /^(\S+)\s+(\S+)\s+(\S+)/;
32 check_oid($xr);
33 check_oid($p1);
34 check_oid($p2);
35 $xref_tbl{$xr} = [$p1, $p2, $ln];
36 }
37
38my @xrkeys = keys %xref_tbl;
39
40my @srt1 = sort { $oid_tbl{$a} <=> $oid_tbl{$b}} @xrkeys;
41
42for(my $i = 0; $i <= $#srt1; $i++)
43 {
44 $xref_tbl{$srt1[$i]}[2] = $i;
45 }
46
47my @srt2 = sort
48 {
49 my$ap1 = $oid_tbl{$xref_tbl{$a}[0]};
50 my$bp1 = $oid_tbl{$xref_tbl{$b}[0]};
51 return $ap1 - $bp1 if ($ap1 != $bp1);
52 my$ap2 = $oid_tbl{$xref_tbl{$a}[1]};
53 my$bp2 = $oid_tbl{$xref_tbl{$b}[1]};
54
55 return $ap2 - $bp2;
56 } @xrkeys;
57
58my $pname = $0;
59
60$pname =~ s|^.[^/]/||;
61
62print <<EOF;
63/* \$OpenBSD\$ */
64/* AUTOGENERATED BY $pname, DO NOT EDIT */
65
66__BEGIN_HIDDEN_DECLS
67
68typedef struct
69 {
70 int sign_id;
71 int hash_id;
72 int pkey_id;
73 } nid_triple;
74
75static const nid_triple sigoid_srt[] =
76 {
77EOF
78
79foreach (@srt1)
80 {
81 my $xr = $_;
82 my ($p1, $p2) = @{$xref_tbl{$_}};
83 print "\t{NID_$xr, NID_$p1, NID_$p2},\n";
84 }
85
86print "\t};";
87print <<EOF;
88
89
90static const nid_triple * const sigoid_srt_xref[] =
91 {
92EOF
93
94foreach (@srt2)
95 {
96 my $x = $xref_tbl{$_}[2];
97 print "\t\&sigoid_srt\[$x\],\n";
98 }
99
100print "\t};\n\n";
101print "__END_HIDDEN_DECLS\n";
102
103sub check_oid
104 {
105 my ($chk) = @_;
106 if (!exists $oid_tbl{$chk})
107 {
108 die "Not Found \"$chk\"\n";
109 }
110 }
111