obj_dat.pl 7.4 KB

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