xref: /onnv-gate/usr/src/common/openssl/crypto/bn/bn_prime.pl (revision 2139:6243c3338933)
10Sstevel@tonic-gate#!/usr/local/bin/perl
20Sstevel@tonic-gate# bn_prime.pl
30Sstevel@tonic-gate
40Sstevel@tonic-gate$num=2048;
50Sstevel@tonic-gate$num=$ARGV[0] if ($#ARGV >= 0);
60Sstevel@tonic-gate
70Sstevel@tonic-gatepush(@primes,2);
80Sstevel@tonic-gate$p=1;
90Sstevel@tonic-gateloop: while ($#primes < $num-1)
100Sstevel@tonic-gate	{
110Sstevel@tonic-gate	$p+=2;
120Sstevel@tonic-gate	$s=int(sqrt($p));
130Sstevel@tonic-gate
14*2139Sjp161948	for ($i=0; defined($primes[$i]) && $primes[$i]<=$s; $i++)
150Sstevel@tonic-gate		{
160Sstevel@tonic-gate		next loop if (($p%$primes[$i]) == 0);
170Sstevel@tonic-gate		}
180Sstevel@tonic-gate	push(@primes,$p);
190Sstevel@tonic-gate	}
200Sstevel@tonic-gate
210Sstevel@tonic-gate# print <<"EOF";
220Sstevel@tonic-gate# /* Auto generated by bn_prime.pl */
230Sstevel@tonic-gate# /* Copyright (C) 1995-1997 Eric Young (eay\@mincom.oz.au).
240Sstevel@tonic-gate#  * All rights reserved.
250Sstevel@tonic-gate#  * Copyright remains Eric Young's, and as such any Copyright notices in
260Sstevel@tonic-gate#  * the code are not to be removed.
270Sstevel@tonic-gate#  * See the COPYRIGHT file in the SSLeay distribution for more details.
280Sstevel@tonic-gate#  */
290Sstevel@tonic-gate#
300Sstevel@tonic-gate# EOF
310Sstevel@tonic-gate
320Sstevel@tonic-gateprint <<\EOF;
330Sstevel@tonic-gate/* Auto generated by bn_prime.pl */
340Sstevel@tonic-gate/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
350Sstevel@tonic-gate * All rights reserved.
360Sstevel@tonic-gate *
370Sstevel@tonic-gate * This package is an SSL implementation written
380Sstevel@tonic-gate * by Eric Young (eay@cryptsoft.com).
390Sstevel@tonic-gate * The implementation was written so as to conform with Netscapes SSL.
400Sstevel@tonic-gate *
410Sstevel@tonic-gate * This library is free for commercial and non-commercial use as long as
420Sstevel@tonic-gate * the following conditions are aheared to.  The following conditions
430Sstevel@tonic-gate * apply to all code found in this distribution, be it the RC4, RSA,
440Sstevel@tonic-gate * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
450Sstevel@tonic-gate * included with this distribution is covered by the same copyright terms
460Sstevel@tonic-gate * except that the holder is Tim Hudson (tjh@cryptsoft.com).
470Sstevel@tonic-gate *
480Sstevel@tonic-gate * Copyright remains Eric Young's, and as such any Copyright notices in
490Sstevel@tonic-gate * the code are not to be removed.
500Sstevel@tonic-gate * If this package is used in a product, Eric Young should be given attribution
510Sstevel@tonic-gate * as the author of the parts of the library used.
520Sstevel@tonic-gate * This can be in the form of a textual message at program startup or
530Sstevel@tonic-gate * in documentation (online or textual) provided with the package.
540Sstevel@tonic-gate *
550Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
560Sstevel@tonic-gate * modification, are permitted provided that the following conditions
570Sstevel@tonic-gate * are met:
580Sstevel@tonic-gate * 1. Redistributions of source code must retain the copyright
590Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer.
600Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
610Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
620Sstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
630Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software
640Sstevel@tonic-gate *    must display the following acknowledgement:
650Sstevel@tonic-gate *    "This product includes cryptographic software written by
660Sstevel@tonic-gate *     Eric Young (eay@cryptsoft.com)"
670Sstevel@tonic-gate *    The word 'cryptographic' can be left out if the rouines from the library
680Sstevel@tonic-gate *    being used are not cryptographic related :-).
690Sstevel@tonic-gate * 4. If you include any Windows specific code (or a derivative thereof) from
700Sstevel@tonic-gate *    the apps directory (application code) you must include an acknowledgement:
710Sstevel@tonic-gate *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
720Sstevel@tonic-gate *
730Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
740Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
750Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
760Sstevel@tonic-gate * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
770Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
780Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
790Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
800Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
810Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
820Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
830Sstevel@tonic-gate * SUCH DAMAGE.
840Sstevel@tonic-gate *
850Sstevel@tonic-gate * The licence and distribution terms for any publically available version or
860Sstevel@tonic-gate * derivative of this code cannot be changed.  i.e. this code cannot simply be
870Sstevel@tonic-gate * copied and put under another distribution licence
880Sstevel@tonic-gate * [including the GNU Public Licence.]
890Sstevel@tonic-gate */
900Sstevel@tonic-gate
910Sstevel@tonic-gateEOF
920Sstevel@tonic-gate
930Sstevel@tonic-gatefor ($i=0; $i <= $#primes; $i++)
940Sstevel@tonic-gate	{
950Sstevel@tonic-gate	if ($primes[$i] > 256)
960Sstevel@tonic-gate		{
970Sstevel@tonic-gate		$eight=$i;
980Sstevel@tonic-gate		last;
990Sstevel@tonic-gate		}
1000Sstevel@tonic-gate	}
1010Sstevel@tonic-gate
1020Sstevel@tonic-gateprintf "#ifndef EIGHT_BIT\n";
1030Sstevel@tonic-gateprintf "#define NUMPRIMES %d\n",$num;
1040Sstevel@tonic-gateprintf "#else\n";
1050Sstevel@tonic-gateprintf "#define NUMPRIMES %d\n",$eight;
1060Sstevel@tonic-gateprintf "#endif\n";
1070Sstevel@tonic-gateprint "static const unsigned int primes[NUMPRIMES]=\n\t{\n\t";
1080Sstevel@tonic-gate$init=0;
1090Sstevel@tonic-gatefor ($i=0; $i <= $#primes; $i++)
1100Sstevel@tonic-gate	{
1110Sstevel@tonic-gate	printf "\n#ifndef EIGHT_BIT\n\t" if ($primes[$i] > 256) && !($init++);
1120Sstevel@tonic-gate	printf("\n\t") if (($i%8) == 0) && ($i != 0);
1130Sstevel@tonic-gate	printf("%4d,",$primes[$i]);
1140Sstevel@tonic-gate	}
1150Sstevel@tonic-gateprint "\n#endif\n\t};\n";
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate
118