]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/objects/objxref.pl
dsa.h: fix preprocessor indentation
[thirdparty/openssl.git] / crypto / objects / objxref.pl
1 #! /usr/bin/env perl
2 # Copyright 1998-2019 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9
10 use strict;
11
12 my %xref_tbl;
13 my %oid_tbl;
14
15 my ($mac_file, $xref_file) = @ARGV;
16
17 # The year the output file is generated.
18 my $YEAR = [localtime()]->[5] + 1900;
19
20 open(IN, $mac_file) || die "Can't open $mac_file, $!\n";
21
22 # Read in OID nid values for a lookup table.
23
24 while (<IN>)
25 {
26 s|\R$||; # Better chomp
27 my ($name, $num) = /^(\S+)\s+(\S+)$/;
28 $oid_tbl{$name} = $num;
29 }
30 close IN;
31
32 open(IN, $xref_file) || die "Can't open $xref_file, $!\n";
33
34 my $ln = 1;
35
36 while (<IN>)
37 {
38 s|\R$||; # Better chomp
39 s/#.*$//;
40 next if (/^\S*$/);
41 my ($xr, $p1, $p2) = /^(\S+)\s+(\S+)\s+(\S+)/;
42 check_oid($xr);
43 check_oid($p1);
44 check_oid($p2);
45 $xref_tbl{$xr} = [$p1, $p2, $ln];
46 }
47
48 my @xrkeys = keys %xref_tbl;
49
50 my @srt1 = sort { $oid_tbl{$a} <=> $oid_tbl{$b}} @xrkeys;
51
52 my $i;
53 for($i = 0; $i <= $#srt1; $i++)
54 {
55 $xref_tbl{$srt1[$i]}[2] = $i;
56 }
57
58 my @srt2 = sort
59 {
60 my$ap1 = $oid_tbl{$xref_tbl{$a}[0]};
61 my$bp1 = $oid_tbl{$xref_tbl{$b}[0]};
62 return $ap1 - $bp1 if ($ap1 != $bp1);
63 my$ap2 = $oid_tbl{$xref_tbl{$a}[1]};
64 my$bp2 = $oid_tbl{$xref_tbl{$b}[1]};
65
66 return $ap2 - $bp2;
67 } @xrkeys;
68
69 my $pname = $0;
70 $pname =~ s|.*/||;
71
72 print <<EOF;
73 /*
74 * WARNING: do not edit!
75 * Generated by $pname
76 *
77 * Copyright 1998-$YEAR The OpenSSL Project Authors. All Rights Reserved.
78 *
79 * Licensed under the Apache License 2.0 (the "License"). You may not use
80 * this file except in compliance with the License. You can obtain a copy
81 * in the file LICENSE in the source distribution or at
82 * https://www.openssl.org/source/license.html
83 */
84
85
86 typedef struct {
87 int sign_id;
88 int hash_id;
89 int pkey_id;
90 } nid_triple;
91
92 DEFINE_STACK_OF(nid_triple)
93
94 static const nid_triple sigoid_srt[] = {
95 EOF
96
97 foreach (@srt1)
98 {
99 my $xr = $_;
100 my ($p1, $p2) = @{$xref_tbl{$_}};
101 my $o1 = " {NID_$xr, NID_$p1,";
102 my $o2 = "NID_$p2},";
103 if (length("$o1 $o2") < 78)
104 {
105 print "$o1 $o2\n";
106 }
107 else
108 {
109 print "$o1\n $o2\n";
110 }
111 }
112
113 print "};";
114 print <<EOF;
115
116
117 static const nid_triple *const sigoid_srt_xref[] = {
118 EOF
119
120 foreach (@srt2)
121 {
122 my ($p1, $p2, $x) = @{$xref_tbl{$_}};
123 # If digest or signature algorithm is "undef" then the algorithm
124 # needs special handling and is excluded from the cross reference table.
125 next if $p1 eq "undef" || $p2 eq "undef";
126 print " \&sigoid_srt\[$x\],\n";
127 }
128
129 print "};\n";
130
131 sub check_oid
132 {
133 my ($chk) = @_;
134 if (!exists $oid_tbl{$chk})
135 {
136 die "Can't find \"$chk\"\n";
137 }
138 }