]>
Commit | Line | Data |
---|---|---|
d02b48c6 RE |
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 | ||
6bd27f86 | 14 | for ($i=0; defined($primes[$i]) && $primes[$i]<=$s; $i++) |
d02b48c6 RE |
15 | { |
16 | next loop if (($p%$primes[$i]) == 0); | |
17 | } | |
18 | push(@primes,$p); | |
19 | } | |
20 | ||
e4b76456 | 21 | print <<\EOF; |
d02b48c6 | 22 | /* Auto generated by bn_prime.pl */ |
e4b76456 | 23 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
d02b48c6 | 24 | * All rights reserved. |
e4b76456 BM |
25 | * |
26 | * This package is an SSL implementation written | |
27 | * by Eric Young (eay@cryptsoft.com). | |
28 | * The implementation was written so as to conform with Netscapes SSL. | |
b0700d2c | 29 | * |
e4b76456 BM |
30 | * This library is free for commercial and non-commercial use as long as |
31 | * the following conditions are aheared to. The following conditions | |
32 | * apply to all code found in this distribution, be it the RC4, RSA, | |
33 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | |
34 | * included with this distribution is covered by the same copyright terms | |
35 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | |
b0700d2c | 36 | * |
d02b48c6 RE |
37 | * Copyright remains Eric Young's, and as such any Copyright notices in |
38 | * the code are not to be removed. | |
e4b76456 BM |
39 | * If this package is used in a product, Eric Young should be given attribution |
40 | * as the author of the parts of the library used. | |
41 | * This can be in the form of a textual message at program startup or | |
42 | * in documentation (online or textual) provided with the package. | |
b0700d2c | 43 | * |
e4b76456 BM |
44 | * Redistribution and use in source and binary forms, with or without |
45 | * modification, are permitted provided that the following conditions | |
46 | * are met: | |
47 | * 1. Redistributions of source code must retain the copyright | |
48 | * notice, this list of conditions and the following disclaimer. | |
49 | * 2. Redistributions in binary form must reproduce the above copyright | |
50 | * notice, this list of conditions and the following disclaimer in the | |
51 | * documentation and/or other materials provided with the distribution. | |
52 | * 3. All advertising materials mentioning features or use of this software | |
53 | * must display the following acknowledgement: | |
54 | * "This product includes cryptographic software written by | |
55 | * Eric Young (eay@cryptsoft.com)" | |
56 | * The word 'cryptographic' can be left out if the rouines from the library | |
57 | * being used are not cryptographic related :-). | |
b0700d2c | 58 | * 4. If you include any Windows specific code (or a derivative thereof) from |
e4b76456 BM |
59 | * the apps directory (application code) you must include an acknowledgement: |
60 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | |
b0700d2c | 61 | * |
e4b76456 BM |
62 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
63 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
64 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
65 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
66 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
67 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
68 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
69 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
70 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
71 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
72 | * SUCH DAMAGE. | |
b0700d2c | 73 | * |
e4b76456 BM |
74 | * The licence and distribution terms for any publically available version or |
75 | * derivative of this code cannot be changed. i.e. this code cannot simply be | |
76 | * copied and put under another distribution licence | |
77 | * [including the GNU Public Licence.] | |
d02b48c6 RE |
78 | */ |
79 | ||
80 | EOF | |
81 | ||
82 | for ($i=0; $i <= $#primes; $i++) | |
83 | { | |
84 | if ($primes[$i] > 256) | |
85 | { | |
86 | $eight=$i; | |
87 | last; | |
88 | } | |
89 | } | |
90 | ||
91 | printf "#ifndef EIGHT_BIT\n"; | |
b0700d2c | 92 | printf "# define NUMPRIMES %d\n",$num; |
75a8e30f | 93 | printf "typedef unsigned short prime_t;\n"; |
d02b48c6 | 94 | printf "#else\n"; |
b0700d2c | 95 | printf "# define NUMPRIMES %d\n",$eight; |
75a8e30f | 96 | printf "typedef unsigned char prime_t;\n"; |
d02b48c6 | 97 | printf "#endif\n"; |
b0700d2c | 98 | print "static const prime_t primes[NUMPRIMES]= {\n "; |
d02b48c6 RE |
99 | $init=0; |
100 | for ($i=0; $i <= $#primes; $i++) | |
101 | { | |
b0700d2c RS |
102 | printf "\n#ifndef EIGHT_BIT\n " if ($primes[$i] > 256) && !($init++); |
103 | printf "\n " if (($i%8) == 0) && ($i != 0); | |
104 | printf "%4d, ", $primes[$i]; | |
d02b48c6 | 105 | } |
b0700d2c | 106 | print "\n#endif\n};\n"; |