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