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