2016-01-24 02:23:25 +08:00
|
|
|
#! /usr/bin/env perl
|
2020-04-23 20:55:52 +08:00
|
|
|
# Copyright 1998-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2016-04-20 10:10:43 +08:00
|
|
|
#
|
2018-12-06 20:22:12 +08:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-04-20 10:10:43 +08:00
|
|
|
# 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 18:52:47 +08:00
|
|
|
|
2020-01-08 04:50:20 +08:00
|
|
|
# The year the output file is generated.
|
|
|
|
my $YEAR = [localtime()]->[5] + 1900;
|
2016-04-20 10:10:43 +08:00
|
|
|
print <<"EOF";
|
|
|
|
/*
|
|
|
|
* WARNING: do not edit!
|
|
|
|
* Generated by crypto/bn/bn_prime.pl
|
2000-01-12 17:16:22 +08:00
|
|
|
*
|
2018-02-14 02:09:02 +08:00
|
|
|
* Copyright 1998-$YEAR The OpenSSL Project Authors. All Rights Reserved.
|
2015-10-28 03:11:48 +08:00
|
|
|
*
|
2018-12-06 20:22:12 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-04-20 10:10:43 +08:00
|
|
|
* 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 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
2016-01-24 02:23:25 +08: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 13:10:11 +08:00
|
|
|
printf "# define NUMPRIMES %d\n\n", $num;
|
2016-01-24 02:23:25 +08:00
|
|
|
|
2016-10-11 05:33:51 +08:00
|
|
|
printf "static const prime_t primes[%d] = {", $num;
|
2016-01-24 02:23:25 +08:00
|
|
|
for (my $i = 0; $i <= $#primes; $i++) {
|
2016-10-11 05:33:51 +08:00
|
|
|
printf "\n " if ($i % 8) == 0;
|
|
|
|
printf " %5d,", $primes[$i];
|
2016-01-24 02:23:25 +08:00
|
|
|
}
|
|
|
|
print "\n};\n";
|