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