2
0

objxref.pl 2.7 KB

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