2
0

objxref.pl 2.8 KB

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