]>
Commit | Line | Data |
---|---|---|
b4f35e5e | 1 | #! /usr/bin/env perl |
b2f16a22 | 2 | # Copyright 1998-2019 The OpenSSL Project Authors. All Rights Reserved. |
e0a65194 | 3 | # |
367ace68 | 4 | # Licensed under the Apache License 2.0 (the "License"). You may not use |
e0a65194 RS |
5 | # this file except in compliance with the License. You can obtain a copy |
6 | # in the file LICENSE in the source distribution or at | |
7 | # https://www.openssl.org/source/license.html | |
d02b48c6 | 8 | |
339638b5 RS |
9 | # The year the output file is generated. |
10 | my $YEAR = [localtime()]->[5] + 1900; | |
e0a65194 RS |
11 | print <<"EOF"; |
12 | /* | |
13 | * WARNING: do not edit! | |
14 | * Generated by crypto/bn/bn_prime.pl | |
e4b76456 | 15 | * |
97d37b85 | 16 | * Copyright 1998-$YEAR The OpenSSL Project Authors. All Rights Reserved. |
b0700d2c | 17 | * |
367ace68 | 18 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
e0a65194 RS |
19 | * this file except in compliance with the License. You can obtain a copy |
20 | * in the file LICENSE in the source distribution or at | |
21 | * https://www.openssl.org/source/license.html | |
d02b48c6 RE |
22 | */ |
23 | ||
24 | EOF | |
25 | ||
d02b48c6 | 26 | |
b4f35e5e RS |
27 | my $num = shift || 2048; |
28 | my @primes = ( 2 ); | |
29 | my $p = 1; | |
30 | loop: while ($#primes < $num-1) { | |
31 | $p += 2; | |
32 | my $s = int(sqrt($p)); | |
33 | ||
34 | for (my $i = 0; defined($primes[$i]) && $primes[$i] <= $s; $i++) { | |
35 | next loop if ($p % $primes[$i]) == 0; | |
36 | } | |
37 | push(@primes, $p); | |
38 | } | |
39 | ||
40 | print "typedef unsigned short prime_t;\n"; | |
7eba4e62 | 41 | printf "# define NUMPRIMES %d\n\n", $num; |
b4f35e5e | 42 | |
0e831db0 | 43 | printf "static const prime_t primes[%d] = {", $num; |
b4f35e5e | 44 | for (my $i = 0; $i <= $#primes; $i++) { |
0e831db0 DB |
45 | printf "\n " if ($i % 8) == 0; |
46 | printf " %5d,", $primes[$i]; | |
b4f35e5e RS |
47 | } |
48 | print "\n};\n"; |