2016-01-23 18:23:25 +00:00
|
|
|
#! /usr/bin/env perl
|
2018-02-27 13:37:28 +00:00
|
|
|
# Copyright 1998-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2016-04-20 02:10:43 +00:00
|
|
|
#
|
|
|
|
# Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2018-02-13 18:09:02 +00:00
|
|
|
# Output year depends on the year of the script.
|
|
|
|
my $YEAR = [localtime([stat($0)]->[9])]->[5] + 1900;
|
2016-04-20 02:10:43 +00:00
|
|
|
print <<"EOF";
|
|
|
|
/*
|
|
|
|
* WARNING: do not edit!
|
|
|
|
* Generated by crypto/bn/bn_prime.pl
|
2000-01-12 09:16:22 +00:00
|
|
|
*
|
2018-02-13 18:09:02 +00:00
|
|
|
* Copyright 1998-$YEAR The OpenSSL Project Authors. All Rights Reserved.
|
2015-10-27 19:11:48 +00:00
|
|
|
*
|
2016-04-20 02:10:43 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
2016-01-23 18:23:25 +00:00
|
|
|
my $num = shift || 2048;
|
|
|
|
my @primes = ( 2 );
|
|
|
|
my $p = 1;
|
|
|
|
loop: while ($#primes < $num-1) {
|
|
|
|
$p += 2;
|
|
|
|
my $s = int(sqrt($p));
|
|
|
|
|
|
|
|
for (my $i = 0; defined($primes[$i]) && $primes[$i] <= $s; $i++) {
|
|
|
|
next loop if ($p % $primes[$i]) == 0;
|
|
|
|
}
|
|
|
|
push(@primes, $p);
|
|
|
|
}
|
|
|
|
|
|
|
|
print "typedef unsigned short prime_t;\n";
|
2016-01-28 05:10:11 +00:00
|
|
|
printf "# define NUMPRIMES %d\n\n", $num;
|
2016-01-23 18:23:25 +00:00
|
|
|
|
2016-10-10 21:33:51 +00:00
|
|
|
printf "static const prime_t primes[%d] = {", $num;
|
2016-01-23 18:23:25 +00:00
|
|
|
for (my $i = 0; $i <= $#primes; $i++) {
|
2016-10-10 21:33:51 +00:00
|
|
|
printf "\n " if ($i % 8) == 0;
|
|
|
|
printf " %5d,", $primes[$i];
|
2016-01-23 18:23:25 +00:00
|
|
|
}
|
|
|
|
print "\n};\n";
|