Blame crypto/bn/bn_prime.pl
|
Packit |
c4476c |
#! /usr/bin/env perl
|
|
Packit |
c4476c |
# Copyright 1998-2019 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit |
c4476c |
#
|
|
Packit |
c4476c |
# Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit |
c4476c |
# this file except in compliance with the License. You can obtain a copy
|
|
Packit |
c4476c |
# in the file LICENSE in the source distribution or at
|
|
Packit |
c4476c |
# https://www.openssl.org/source/license.html
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
# Output year depends on the year of the script.
|
|
Packit |
c4476c |
my $YEAR = [localtime([stat($0)]->[9])]->[5] + 1900;
|
|
Packit |
c4476c |
print <<"EOF";
|
|
Packit |
c4476c |
/*
|
|
Packit |
c4476c |
* WARNING: do not edit!
|
|
Packit |
c4476c |
* Generated by crypto/bn/bn_prime.pl
|
|
Packit |
c4476c |
*
|
|
Packit |
c4476c |
* Copyright 1998-$YEAR The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit |
c4476c |
*
|
|
Packit |
c4476c |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit |
c4476c |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit |
c4476c |
* in the file LICENSE in the source distribution or at
|
|
Packit |
c4476c |
* https://www.openssl.org/source/license.html
|
|
Packit |
c4476c |
*/
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
EOF
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
my $num = shift || 2048;
|
|
Packit |
c4476c |
my @primes = ( 2 );
|
|
Packit |
c4476c |
my $p = 1;
|
|
Packit |
c4476c |
loop: while ($#primes < $num-1) {
|
|
Packit |
c4476c |
$p += 2;
|
|
Packit |
c4476c |
my $s = int(sqrt($p));
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
for (my $i = 0; defined($primes[$i]) && $primes[$i] <= $s; $i++) {
|
|
Packit |
c4476c |
next loop if ($p % $primes[$i]) == 0;
|
|
Packit |
c4476c |
}
|
|
Packit |
c4476c |
push(@primes, $p);
|
|
Packit |
c4476c |
}
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
print "typedef unsigned short prime_t;\n";
|
|
Packit |
c4476c |
printf "# define NUMPRIMES %d\n\n", $num;
|
|
Packit |
c4476c |
|
|
Packit |
c4476c |
printf "static const prime_t primes[%d] = {", $num;
|
|
Packit |
c4476c |
for (my $i = 0; $i <= $#primes; $i++) {
|
|
Packit |
c4476c |
printf "\n " if ($i % 8) == 0;
|
|
Packit |
c4476c |
printf " %5d,", $primes[$i];
|
|
Packit |
c4476c |
}
|
|
Packit |
c4476c |
print "\n};\n";
|