You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

310 lines
7.5 KiB

  1. #!/usr/bin/env perl
  2. # fixes bug in floating point emulation on sparc64 when
  3. # this script produces off-by-one output on sparc64
  4. use integer;
  5. if (scalar @ARGV != 2)
  6. {
  7. print "Usage: perl obj_dat.pl ../../include/openssl/obj_mac.h obj_dat.h\n";
  8. exit 1;
  9. }
  10. sub obj_cmp
  11. {
  12. local(@a,@b,$_,$r);
  13. $A=$obj_len{$obj{$nid{$a}}};
  14. $B=$obj_len{$obj{$nid{$b}}};
  15. $r=($A-$B);
  16. return($r) if $r != 0;
  17. $A=$obj_der{$obj{$nid{$a}}};
  18. $B=$obj_der{$obj{$nid{$b}}};
  19. return($A cmp $B);
  20. }
  21. sub expand_obj
  22. {
  23. local(*v)=@_;
  24. local($k,$d);
  25. local($i);
  26. do {
  27. $i=0;
  28. foreach $k (keys %v)
  29. {
  30. if (($v{$k} =~ s/(OBJ_[^,]+),/$v{$1},/))
  31. { $i++; }
  32. }
  33. } while($i);
  34. foreach $k (keys %v)
  35. {
  36. @a=split(/,/,$v{$k});
  37. $objn{$k}=$#a+1;
  38. }
  39. return(%objn);
  40. }
  41. open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
  42. open (OUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
  43. while (<IN>)
  44. {
  45. next unless /^\#define\s+(\S+)\s+(.*)$/;
  46. $v=$1;
  47. $d=$2;
  48. $d =~ s/^\"//;
  49. $d =~ s/\"$//;
  50. if ($v =~ /^SN_(.*)$/)
  51. {
  52. if(defined $snames{$d})
  53. {
  54. print "WARNING: Duplicate short name \"$d\"\n";
  55. }
  56. else
  57. { $snames{$d} = "X"; }
  58. $sn{$1}=$d;
  59. }
  60. elsif ($v =~ /^LN_(.*)$/)
  61. {
  62. if(defined $lnames{$d})
  63. {
  64. print "WARNING: Duplicate long name \"$d\"\n";
  65. }
  66. else
  67. { $lnames{$d} = "X"; }
  68. $ln{$1}=$d;
  69. }
  70. elsif ($v =~ /^NID_(.*)$/)
  71. { $nid{$d}=$1; }
  72. elsif ($v =~ /^OBJ_(.*)$/)
  73. {
  74. $obj{$1}=$v;
  75. $objd{$v}=$d;
  76. }
  77. }
  78. close IN;
  79. %ob=&expand_obj(*objd);
  80. @a=sort { $a <=> $b } keys %nid;
  81. $n=$a[$#a]+1;
  82. @lvalues=();
  83. $lvalues=0;
  84. for ($i=0; $i<$n; $i++)
  85. {
  86. if (!defined($nid{$i}))
  87. {
  88. push(@out,"{NULL,NULL,NID_undef,0,NULL,0},\n");
  89. }
  90. else
  91. {
  92. $sn=defined($sn{$nid{$i}})?"$sn{$nid{$i}}":"NULL";
  93. $ln=defined($ln{$nid{$i}})?"$ln{$nid{$i}}":"NULL";
  94. if ($sn eq "NULL") {
  95. $sn=$ln;
  96. $sn{$nid{$i}} = $ln;
  97. }
  98. if ($ln eq "NULL") {
  99. $ln=$sn;
  100. $ln{$nid{$i}} = $sn;
  101. }
  102. $out ="{";
  103. $out.="\"$sn\"";
  104. $out.=","."\"$ln\"";
  105. $out.=",NID_$nid{$i},";
  106. if (defined($obj{$nid{$i}}) && $objd{$obj{$nid{$i}}} =~ /,/)
  107. {
  108. $v=$objd{$obj{$nid{$i}}};
  109. $v =~ s/L//g;
  110. $v =~ s/,/ /g;
  111. $r=&der_it($v);
  112. $z="";
  113. $length=0;
  114. foreach (unpack("C*",$r))
  115. {
  116. $z.=sprintf("0x%02X,",$_);
  117. $length++;
  118. }
  119. $obj_der{$obj{$nid{$i}}}=$z;
  120. $obj_len{$obj{$nid{$i}}}=$length;
  121. push(@lvalues,sprintf("%-45s/* [%3d] %s */\n",
  122. $z,$lvalues,$obj{$nid{$i}}));
  123. $out.="$length,&(lvalues[$lvalues]),0";
  124. $lvalues+=$length;
  125. }
  126. else
  127. {
  128. $out.="0,NULL,0";
  129. }
  130. $out.="},\n";
  131. push(@out,$out);
  132. }
  133. }
  134. @a=grep(defined($sn{$nid{$_}}),0 .. $n);
  135. foreach (sort { $sn{$nid{$a}} cmp $sn{$nid{$b}} } @a)
  136. {
  137. push(@sn,sprintf("%2d,\t/* \"$sn{$nid{$_}}\" */\n",$_));
  138. }
  139. @a=grep(defined($ln{$nid{$_}}),0 .. $n);
  140. foreach (sort { $ln{$nid{$a}} cmp $ln{$nid{$b}} } @a)
  141. {
  142. push(@ln,sprintf("%2d,\t/* \"$ln{$nid{$_}}\" */\n",$_));
  143. }
  144. @a=grep(defined($obj{$nid{$_}}),0 .. $n);
  145. foreach (sort obj_cmp @a)
  146. {
  147. $m=$obj{$nid{$_}};
  148. $v=$objd{$m};
  149. $v =~ s/L//g;
  150. $v =~ s/,/ /g;
  151. push(@ob,sprintf("%2d,\t/* %-32s %s */\n",$_,$m,$v));
  152. }
  153. print OUT <<'EOF';
  154. /* THIS FILE IS GENERATED FROM objects.h by obj_dat.pl via the
  155. * following command:
  156. * perl obj_dat.pl ../../include/openssl/obj_mac.h obj_dat.h */
  157. /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
  158. * All rights reserved.
  159. *
  160. * This package is an SSL implementation written
  161. * by Eric Young (eay@cryptsoft.com).
  162. * The implementation was written so as to conform with Netscapes SSL.
  163. *
  164. * This library is free for commercial and non-commercial use as long as
  165. * the following conditions are aheared to. The following conditions
  166. * apply to all code found in this distribution, be it the RC4, RSA,
  167. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  168. * included with this distribution is covered by the same copyright terms
  169. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  170. *
  171. * Copyright remains Eric Young's, and as such any Copyright notices in
  172. * the code are not to be removed.
  173. * If this package is used in a product, Eric Young should be given attribution
  174. * as the author of the parts of the library used.
  175. * This can be in the form of a textual message at program startup or
  176. * in documentation (online or textual) provided with the package.
  177. *
  178. * Redistribution and use in source and binary forms, with or without
  179. * modification, are permitted provided that the following conditions
  180. * are met:
  181. * 1. Redistributions of source code must retain the copyright
  182. * notice, this list of conditions and the following disclaimer.
  183. * 2. Redistributions in binary form must reproduce the above copyright
  184. * notice, this list of conditions and the following disclaimer in the
  185. * documentation and/or other materials provided with the distribution.
  186. * 3. All advertising materials mentioning features or use of this software
  187. * must display the following acknowledgement:
  188. * "This product includes cryptographic software written by
  189. * Eric Young (eay@cryptsoft.com)"
  190. * The word 'cryptographic' can be left out if the rouines from the library
  191. * being used are not cryptographic related :-).
  192. * 4. If you include any Windows specific code (or a derivative thereof) from
  193. * the apps directory (application code) you must include an acknowledgement:
  194. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  195. *
  196. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  197. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  198. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  199. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  200. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  201. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  202. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  203. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  204. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  205. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  206. * SUCH DAMAGE.
  207. *
  208. * The licence and distribution terms for any publically available version or
  209. * derivative of this code cannot be changed. i.e. this code cannot simply be
  210. * copied and put under another distribution licence
  211. * [including the GNU Public Licence.] */
  212. EOF
  213. printf OUT "#define NUM_NID %d\n",$n;
  214. printf OUT "#define NUM_SN %d\n",$#sn+1;
  215. printf OUT "#define NUM_LN %d\n",$#ln+1;
  216. printf OUT "#define NUM_OBJ %d\n\n",$#ob+1;
  217. printf OUT "static const unsigned char lvalues[%d]={\n",$lvalues+1;
  218. print OUT @lvalues;
  219. print OUT "};\n\n";
  220. printf OUT "static const ASN1_OBJECT kObjects[NUM_NID]={\n";
  221. foreach (@out)
  222. {
  223. if (length($_) > 75)
  224. {
  225. $out="";
  226. foreach (split(/,/))
  227. {
  228. $t=$out.$_.",";
  229. if (length($t) > 70)
  230. {
  231. print OUT "$out\n";
  232. $t="\t$_,";
  233. }
  234. $out=$t;
  235. }
  236. chop $out;
  237. print OUT "$out";
  238. }
  239. else
  240. { print OUT $_; }
  241. }
  242. print OUT "};\n\n";
  243. printf OUT "static const unsigned int kNIDsInShortNameOrder[NUM_SN]={\n";
  244. print OUT @sn;
  245. print OUT "};\n\n";
  246. printf OUT "static const unsigned int kNIDsInLongNameOrder[NUM_LN]={\n";
  247. print OUT @ln;
  248. print OUT "};\n\n";
  249. printf OUT "static const unsigned int kNIDsInOIDOrder[NUM_OBJ]={\n";
  250. print OUT @ob;
  251. print OUT "};\n\n";
  252. close OUT;
  253. sub der_it
  254. {
  255. local($v)=@_;
  256. local(@a,$i,$ret,@r);
  257. @a=split(/\s+/,$v);
  258. $ret.=pack("C*",$a[0]*40+$a[1]);
  259. shift @a;
  260. shift @a;
  261. foreach (@a)
  262. {
  263. @r=();
  264. $t=0;
  265. while ($_ >= 128)
  266. {
  267. $x=$_%128;
  268. $_/=128;
  269. push(@r,((($t++)?0x80:0)|$x));
  270. }
  271. push(@r,((($t++)?0x80:0)|$_));
  272. $ret.=pack("C*",reverse(@r));
  273. }
  274. return($ret);
  275. }