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