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