]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/bn/bn_prime.pl
Make generated copyright year be "now"
[thirdparty/openssl.git] / crypto / bn / bn_prime.pl
CommitLineData
b4f35e5e 1#! /usr/bin/env perl
b2f16a22 2# Copyright 1998-2019 The OpenSSL Project Authors. All Rights Reserved.
e0a65194 3#
367ace68 4# Licensed under the Apache License 2.0 (the "License"). You may not use
e0a65194
RS
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
339638b5
RS
9# The year the output file is generated.
10my $YEAR = [localtime()]->[5] + 1900;
e0a65194
RS
11print <<"EOF";
12/*
13 * WARNING: do not edit!
14 * Generated by crypto/bn/bn_prime.pl
e4b76456 15 *
97d37b85 16 * Copyright 1998-$YEAR The OpenSSL Project Authors. All Rights Reserved.
b0700d2c 17 *
367ace68 18 * Licensed under the Apache License 2.0 (the "License"). You may not use
e0a65194
RS
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
d02b48c6
RE
22 */
23
24EOF
25
d02b48c6 26
b4f35e5e
RS
27my $num = shift || 2048;
28my @primes = ( 2 );
29my $p = 1;
30loop: 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
40print "typedef unsigned short prime_t;\n";
7eba4e62 41printf "# define NUMPRIMES %d\n\n", $num;
b4f35e5e 42
0e831db0 43printf "static const prime_t primes[%d] = {", $num;
b4f35e5e 44for (my $i = 0; $i <= $#primes; $i++) {
0e831db0
DB
45 printf "\n " if ($i % 8) == 0;
46 printf " %5d,", $primes[$i];
b4f35e5e
RS
47}
48print "\n};\n";