objxref.pl 2.9 KB

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