2016-01-24 02:23:25 +08:00
|
|
|
#! /usr/bin/env perl
|
2016-05-18 05:38:18 +08:00
|
|
|
# Copyright 1998-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2016-04-20 10:10:43 +08: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 18:52:47 +08:00
|
|
|
|
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
|
|
|
*
|
2016-05-18 05:38:18 +08:00
|
|
|
* Copyright 1998-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2015-10-28 03:11:48 +08:00
|
|
|
*
|
2016-04-20 10:10:43 +08: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 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";
|