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