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