Separate DSA functionality from ASN.1 encoding.
[openssl.git] / crypto / bn / bn_prime.pl
1 #!/usr/local/bin/perl
2 # bn_prime.pl
3
4 $num=2048;
5 $num=$ARGV[0] if ($#ARGV >= 0);
6
7 push(@primes,2);
8 $p=1;
9 loop: while ($#primes < $num-1)
10         {
11         $p+=2;
12         $s=int(sqrt($p));
13
14         for ($i=0; $primes[$i]<=$s; $i++)
15                 {
16                 next loop if (($p%$primes[$i]) == 0);
17                 }
18         push(@primes,$p);
19         }
20
21 print <<"EOF";
22 /* Auto generated by bn_prime.pl */
23 /* Copyright (C) 1995-1997 Eric Young (eay\@mincom.oz.au).
24  * All rights reserved.
25  * Copyright remains Eric Young's, and as such any Copyright notices in
26  * the code are not to be removed.
27  * See the COPYRIGHT file in the SSLeay distribution for more details.
28  */
29
30 EOF
31
32 for ($i=0; $i <= $#primes; $i++)
33         {
34         if ($primes[$i] > 256)
35                 {
36                 $eight=$i;
37                 last;
38                 }
39         }
40
41 printf "#ifndef EIGHT_BIT\n";
42 printf "#define NUMPRIMES %d\n",$num;
43 printf "#else\n";
44 printf "#define NUMPRIMES %d\n",$eight;
45 printf "#endif\n";
46 print "static unsigned int primes[NUMPRIMES]=\n\t{\n\t";
47 $init=0;
48 for ($i=0; $i <= $#primes; $i++)
49         {
50         printf "\n#ifndef EIGHT_BIT\n\t" if ($primes[$i] > 256) && !($init++);
51         printf("\n\t") if (($i%8) == 0) && ($i != 0);
52         printf("%4d,",$primes[$i]);
53         }
54 print "\n#endif\n\t};\n";
55
56