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