xref: /onnv-gate/usr/src/common/openssl/crypto/objects/obj_dat.pl (revision 2139:6243c3338933)
10Sstevel@tonic-gate#!/usr/local/bin/perl
20Sstevel@tonic-gate
30Sstevel@tonic-gate# fixes bug in floating point emulation on sparc64 when
40Sstevel@tonic-gate# this script produces off-by-one output on sparc64
50Sstevel@tonic-gateuse integer;
60Sstevel@tonic-gate
70Sstevel@tonic-gatesub obj_cmp
80Sstevel@tonic-gate	{
90Sstevel@tonic-gate	local(@a,@b,$_,$r);
100Sstevel@tonic-gate
110Sstevel@tonic-gate	$A=$obj_len{$obj{$nid{$a}}};
120Sstevel@tonic-gate	$B=$obj_len{$obj{$nid{$b}}};
130Sstevel@tonic-gate
140Sstevel@tonic-gate	$r=($A-$B);
150Sstevel@tonic-gate	return($r) if $r != 0;
160Sstevel@tonic-gate
170Sstevel@tonic-gate	$A=$obj_der{$obj{$nid{$a}}};
180Sstevel@tonic-gate	$B=$obj_der{$obj{$nid{$b}}};
190Sstevel@tonic-gate
200Sstevel@tonic-gate	return($A cmp $B);
210Sstevel@tonic-gate	}
220Sstevel@tonic-gate
230Sstevel@tonic-gatesub expand_obj
240Sstevel@tonic-gate	{
250Sstevel@tonic-gate	local(*v)=@_;
260Sstevel@tonic-gate	local($k,$d);
270Sstevel@tonic-gate	local($i);
280Sstevel@tonic-gate
290Sstevel@tonic-gate	do	{
300Sstevel@tonic-gate		$i=0;
310Sstevel@tonic-gate		foreach $k (keys %v)
320Sstevel@tonic-gate			{
330Sstevel@tonic-gate			if (($v{$k} =~ s/(OBJ_[^,]+),/$v{$1},/))
340Sstevel@tonic-gate				{ $i++; }
350Sstevel@tonic-gate			}
360Sstevel@tonic-gate		} while($i);
370Sstevel@tonic-gate	foreach $k (keys %v)
380Sstevel@tonic-gate		{
390Sstevel@tonic-gate		@a=split(/,/,$v{$k});
400Sstevel@tonic-gate		$objn{$k}=$#a+1;
410Sstevel@tonic-gate		}
420Sstevel@tonic-gate	return(%objn);
430Sstevel@tonic-gate	}
440Sstevel@tonic-gate
450Sstevel@tonic-gateopen (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
460Sstevel@tonic-gateopen (OUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
470Sstevel@tonic-gate
480Sstevel@tonic-gatewhile (<IN>)
490Sstevel@tonic-gate	{
500Sstevel@tonic-gate	next unless /^\#define\s+(\S+)\s+(.*)$/;
510Sstevel@tonic-gate	$v=$1;
520Sstevel@tonic-gate	$d=$2;
530Sstevel@tonic-gate	$d =~ s/^\"//;
540Sstevel@tonic-gate	$d =~ s/\"$//;
550Sstevel@tonic-gate	if ($v =~ /^SN_(.*)$/)
560Sstevel@tonic-gate		{
570Sstevel@tonic-gate		if(defined $snames{$d})
580Sstevel@tonic-gate			{
590Sstevel@tonic-gate			print "WARNING: Duplicate short name \"$d\"\n";
600Sstevel@tonic-gate			}
610Sstevel@tonic-gate		else
620Sstevel@tonic-gate			{ $snames{$d} = "X"; }
630Sstevel@tonic-gate		$sn{$1}=$d;
640Sstevel@tonic-gate		}
650Sstevel@tonic-gate	elsif ($v =~ /^LN_(.*)$/)
660Sstevel@tonic-gate		{
670Sstevel@tonic-gate		if(defined $lnames{$d})
680Sstevel@tonic-gate			{
690Sstevel@tonic-gate			print "WARNING: Duplicate long name \"$d\"\n";
700Sstevel@tonic-gate			}
710Sstevel@tonic-gate		else
720Sstevel@tonic-gate			{ $lnames{$d} = "X"; }
730Sstevel@tonic-gate		$ln{$1}=$d;
740Sstevel@tonic-gate		}
750Sstevel@tonic-gate	elsif ($v =~ /^NID_(.*)$/)
760Sstevel@tonic-gate		{ $nid{$d}=$1; }
770Sstevel@tonic-gate	elsif ($v =~ /^OBJ_(.*)$/)
780Sstevel@tonic-gate		{
790Sstevel@tonic-gate		$obj{$1}=$v;
800Sstevel@tonic-gate		$objd{$v}=$d;
810Sstevel@tonic-gate		}
820Sstevel@tonic-gate	}
830Sstevel@tonic-gateclose IN;
840Sstevel@tonic-gate
850Sstevel@tonic-gate%ob=&expand_obj(*objd);
860Sstevel@tonic-gate
870Sstevel@tonic-gate@a=sort { $a <=> $b } keys %nid;
880Sstevel@tonic-gate$n=$a[$#a]+1;
890Sstevel@tonic-gate
900Sstevel@tonic-gate@lvalues=();
910Sstevel@tonic-gate$lvalues=0;
920Sstevel@tonic-gate
930Sstevel@tonic-gatefor ($i=0; $i<$n; $i++)
940Sstevel@tonic-gate	{
950Sstevel@tonic-gate	if (!defined($nid{$i}))
960Sstevel@tonic-gate		{
97*2139Sjp161948		push(@out,"{NULL,NULL,NID_undef,0,NULL,0},\n");
980Sstevel@tonic-gate		}
990Sstevel@tonic-gate	else
1000Sstevel@tonic-gate		{
1010Sstevel@tonic-gate		$sn=defined($sn{$nid{$i}})?"$sn{$nid{$i}}":"NULL";
1020Sstevel@tonic-gate		$ln=defined($ln{$nid{$i}})?"$ln{$nid{$i}}":"NULL";
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate		if ($sn eq "NULL") {
1050Sstevel@tonic-gate			$sn=$ln;
1060Sstevel@tonic-gate			$sn{$nid{$i}} = $ln;
1070Sstevel@tonic-gate		}
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate		if ($ln eq "NULL") {
1100Sstevel@tonic-gate			$ln=$sn;
1110Sstevel@tonic-gate			$ln{$nid{$i}} = $sn;
1120Sstevel@tonic-gate		}
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate		$out ="{";
1150Sstevel@tonic-gate		$out.="\"$sn\"";
1160Sstevel@tonic-gate		$out.=","."\"$ln\"";
1170Sstevel@tonic-gate		$out.=",NID_$nid{$i},";
1180Sstevel@tonic-gate		if (defined($obj{$nid{$i}}))
1190Sstevel@tonic-gate			{
1200Sstevel@tonic-gate			$v=$objd{$obj{$nid{$i}}};
1210Sstevel@tonic-gate			$v =~ s/L//g;
1220Sstevel@tonic-gate			$v =~ s/,/ /g;
1230Sstevel@tonic-gate			$r=&der_it($v);
1240Sstevel@tonic-gate			$z="";
1250Sstevel@tonic-gate			$length=0;
1260Sstevel@tonic-gate			foreach (unpack("C*",$r))
1270Sstevel@tonic-gate				{
1280Sstevel@tonic-gate				$z.=sprintf("0x%02X,",$_);
1290Sstevel@tonic-gate				$length++;
1300Sstevel@tonic-gate				}
1310Sstevel@tonic-gate			$obj_der{$obj{$nid{$i}}}=$z;
1320Sstevel@tonic-gate			$obj_len{$obj{$nid{$i}}}=$length;
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate			push(@lvalues,sprintf("%-45s/* [%3d] %s */\n",
1350Sstevel@tonic-gate				$z,$lvalues,$obj{$nid{$i}}));
1360Sstevel@tonic-gate			$out.="$length,&(lvalues[$lvalues]),0";
1370Sstevel@tonic-gate			$lvalues+=$length;
1380Sstevel@tonic-gate			}
1390Sstevel@tonic-gate		else
1400Sstevel@tonic-gate			{
141*2139Sjp161948			$out.="0,NULL,0";
1420Sstevel@tonic-gate			}
1430Sstevel@tonic-gate		$out.="},\n";
1440Sstevel@tonic-gate		push(@out,$out);
1450Sstevel@tonic-gate		}
1460Sstevel@tonic-gate	}
1470Sstevel@tonic-gate
1480Sstevel@tonic-gate@a=grep(defined($sn{$nid{$_}}),0 .. $n);
1490Sstevel@tonic-gateforeach (sort { $sn{$nid{$a}} cmp $sn{$nid{$b}} } @a)
1500Sstevel@tonic-gate	{
1510Sstevel@tonic-gate	push(@sn,sprintf("&(nid_objs[%2d]),/* \"$sn{$nid{$_}}\" */\n",$_));
1520Sstevel@tonic-gate	}
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate@a=grep(defined($ln{$nid{$_}}),0 .. $n);
1550Sstevel@tonic-gateforeach (sort { $ln{$nid{$a}} cmp $ln{$nid{$b}} } @a)
1560Sstevel@tonic-gate	{
1570Sstevel@tonic-gate	push(@ln,sprintf("&(nid_objs[%2d]),/* \"$ln{$nid{$_}}\" */\n",$_));
1580Sstevel@tonic-gate	}
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate@a=grep(defined($obj{$nid{$_}}),0 .. $n);
1610Sstevel@tonic-gateforeach (sort obj_cmp @a)
1620Sstevel@tonic-gate	{
1630Sstevel@tonic-gate	$m=$obj{$nid{$_}};
1640Sstevel@tonic-gate	$v=$objd{$m};
1650Sstevel@tonic-gate	$v =~ s/L//g;
1660Sstevel@tonic-gate	$v =~ s/,/ /g;
1670Sstevel@tonic-gate	push(@ob,sprintf("&(nid_objs[%2d]),/* %-32s %s */\n",$_,$m,$v));
1680Sstevel@tonic-gate	}
1690Sstevel@tonic-gate
1700Sstevel@tonic-gateprint OUT <<'EOF';
1710Sstevel@tonic-gate/* crypto/objects/obj_dat.h */
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate/* THIS FILE IS GENERATED FROM objects.h by obj_dat.pl via the
1740Sstevel@tonic-gate * following command:
1750Sstevel@tonic-gate * perl obj_dat.pl obj_mac.h obj_dat.h
1760Sstevel@tonic-gate */
1770Sstevel@tonic-gate
1780Sstevel@tonic-gate/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
1790Sstevel@tonic-gate * All rights reserved.
1800Sstevel@tonic-gate *
1810Sstevel@tonic-gate * This package is an SSL implementation written
1820Sstevel@tonic-gate * by Eric Young (eay@cryptsoft.com).
1830Sstevel@tonic-gate * The implementation was written so as to conform with Netscapes SSL.
1840Sstevel@tonic-gate *
1850Sstevel@tonic-gate * This library is free for commercial and non-commercial use as long as
1860Sstevel@tonic-gate * the following conditions are aheared to.  The following conditions
1870Sstevel@tonic-gate * apply to all code found in this distribution, be it the RC4, RSA,
1880Sstevel@tonic-gate * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1890Sstevel@tonic-gate * included with this distribution is covered by the same copyright terms
1900Sstevel@tonic-gate * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1910Sstevel@tonic-gate *
1920Sstevel@tonic-gate * Copyright remains Eric Young's, and as such any Copyright notices in
1930Sstevel@tonic-gate * the code are not to be removed.
1940Sstevel@tonic-gate * If this package is used in a product, Eric Young should be given attribution
1950Sstevel@tonic-gate * as the author of the parts of the library used.
1960Sstevel@tonic-gate * This can be in the form of a textual message at program startup or
1970Sstevel@tonic-gate * in documentation (online or textual) provided with the package.
1980Sstevel@tonic-gate *
1990Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
2000Sstevel@tonic-gate * modification, are permitted provided that the following conditions
2010Sstevel@tonic-gate * are met:
2020Sstevel@tonic-gate * 1. Redistributions of source code must retain the copyright
2030Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer.
2040Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
2050Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
2060Sstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
2070Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software
2080Sstevel@tonic-gate *    must display the following acknowledgement:
2090Sstevel@tonic-gate *    "This product includes cryptographic software written by
2100Sstevel@tonic-gate *     Eric Young (eay@cryptsoft.com)"
2110Sstevel@tonic-gate *    The word 'cryptographic' can be left out if the rouines from the library
2120Sstevel@tonic-gate *    being used are not cryptographic related :-).
2130Sstevel@tonic-gate * 4. If you include any Windows specific code (or a derivative thereof) from
2140Sstevel@tonic-gate *    the apps directory (application code) you must include an acknowledgement:
2150Sstevel@tonic-gate *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
2160Sstevel@tonic-gate *
2170Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
2180Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2190Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2200Sstevel@tonic-gate * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2210Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2220Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2230Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2240Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2250Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2260Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2270Sstevel@tonic-gate * SUCH DAMAGE.
2280Sstevel@tonic-gate *
2290Sstevel@tonic-gate * The licence and distribution terms for any publically available version or
2300Sstevel@tonic-gate * derivative of this code cannot be changed.  i.e. this code cannot simply be
2310Sstevel@tonic-gate * copied and put under another distribution licence
2320Sstevel@tonic-gate * [including the GNU Public Licence.]
2330Sstevel@tonic-gate */
2340Sstevel@tonic-gate
2350Sstevel@tonic-gateEOF
2360Sstevel@tonic-gate
2370Sstevel@tonic-gateprintf OUT "#define NUM_NID %d\n",$n;
2380Sstevel@tonic-gateprintf OUT "#define NUM_SN %d\n",$#sn+1;
2390Sstevel@tonic-gateprintf OUT "#define NUM_LN %d\n",$#ln+1;
2400Sstevel@tonic-gateprintf OUT "#define NUM_OBJ %d\n\n",$#ob+1;
2410Sstevel@tonic-gate
2420Sstevel@tonic-gateprintf OUT "static unsigned char lvalues[%d]={\n",$lvalues+1;
2430Sstevel@tonic-gateprint OUT @lvalues;
2440Sstevel@tonic-gateprint OUT "};\n\n";
2450Sstevel@tonic-gate
2460Sstevel@tonic-gateprintf OUT "static ASN1_OBJECT nid_objs[NUM_NID]={\n";
2470Sstevel@tonic-gateforeach (@out)
2480Sstevel@tonic-gate	{
2490Sstevel@tonic-gate	if (length($_) > 75)
2500Sstevel@tonic-gate		{
2510Sstevel@tonic-gate		$out="";
2520Sstevel@tonic-gate		foreach (split(/,/))
2530Sstevel@tonic-gate			{
2540Sstevel@tonic-gate			$t=$out.$_.",";
2550Sstevel@tonic-gate			if (length($t) > 70)
2560Sstevel@tonic-gate				{
2570Sstevel@tonic-gate				print OUT "$out\n";
2580Sstevel@tonic-gate				$t="\t$_,";
2590Sstevel@tonic-gate				}
2600Sstevel@tonic-gate			$out=$t;
2610Sstevel@tonic-gate			}
2620Sstevel@tonic-gate		chop $out;
2630Sstevel@tonic-gate		print OUT "$out";
2640Sstevel@tonic-gate		}
2650Sstevel@tonic-gate	else
2660Sstevel@tonic-gate		{ print OUT $_; }
2670Sstevel@tonic-gate	}
2680Sstevel@tonic-gateprint  OUT "};\n\n";
2690Sstevel@tonic-gate
2700Sstevel@tonic-gateprintf OUT "static ASN1_OBJECT *sn_objs[NUM_SN]={\n";
2710Sstevel@tonic-gateprint  OUT @sn;
2720Sstevel@tonic-gateprint  OUT "};\n\n";
2730Sstevel@tonic-gate
2740Sstevel@tonic-gateprintf OUT "static ASN1_OBJECT *ln_objs[NUM_LN]={\n";
2750Sstevel@tonic-gateprint  OUT @ln;
2760Sstevel@tonic-gateprint  OUT "};\n\n";
2770Sstevel@tonic-gate
2780Sstevel@tonic-gateprintf OUT "static ASN1_OBJECT *obj_objs[NUM_OBJ]={\n";
2790Sstevel@tonic-gateprint  OUT @ob;
2800Sstevel@tonic-gateprint  OUT "};\n\n";
2810Sstevel@tonic-gate
2820Sstevel@tonic-gateclose OUT;
2830Sstevel@tonic-gate
2840Sstevel@tonic-gatesub der_it
2850Sstevel@tonic-gate	{
2860Sstevel@tonic-gate	local($v)=@_;
2870Sstevel@tonic-gate	local(@a,$i,$ret,@r);
2880Sstevel@tonic-gate
2890Sstevel@tonic-gate	@a=split(/\s+/,$v);
2900Sstevel@tonic-gate	$ret.=pack("C*",$a[0]*40+$a[1]);
2910Sstevel@tonic-gate	shift @a;
2920Sstevel@tonic-gate	shift @a;
2930Sstevel@tonic-gate	foreach (@a)
2940Sstevel@tonic-gate		{
2950Sstevel@tonic-gate		@r=();
2960Sstevel@tonic-gate		$t=0;
2970Sstevel@tonic-gate		while ($_ >= 128)
2980Sstevel@tonic-gate			{
2990Sstevel@tonic-gate			$x=$_%128;
3000Sstevel@tonic-gate			$_/=128;
3010Sstevel@tonic-gate			push(@r,((($t++)?0x80:0)|$x));
3020Sstevel@tonic-gate			}
3030Sstevel@tonic-gate		push(@r,((($t++)?0x80:0)|$_));
3040Sstevel@tonic-gate		$ret.=pack("C*",reverse(@r));
3050Sstevel@tonic-gate		}
3060Sstevel@tonic-gate	return($ret);
3070Sstevel@tonic-gate	}
308