]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/bn/bn_prime.pl
Copyright consolidation: perl files
[thirdparty/openssl.git] / crypto / bn / bn_prime.pl
CommitLineData
b4f35e5e 1#! /usr/bin/env perl
e0a65194
RS
2# Copyright 1995-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
d02b48c6 8
e0a65194
RS
9print <<"EOF";
10/*
11 * WARNING: do not edit!
12 * Generated by crypto/bn/bn_prime.pl
e4b76456 13 *
e0a65194 14 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
b0700d2c 15 *
e0a65194
RS
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
d02b48c6
RE
20 */
21
22EOF
23
d02b48c6 24
b4f35e5e
RS
25my $num = shift || 2048;
26my @primes = ( 2 );
27my $p = 1;
28loop: 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
38print "typedef unsigned short prime_t;\n";
7eba4e62 39printf "# define NUMPRIMES %d\n\n", $num;
b4f35e5e 40
7eba4e62 41printf "static const prime_t primes[%d] = {\n", $num;
b4f35e5e
RS
42for (my $i = 0; $i <= $#primes; $i++) {
43 printf "\n " if ($i % 8) == 0;
44 printf "%4d, ", $primes[$i];
45}
46print "\n};\n";