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