diff options
author | Rich Salz <rsalz@akamai.com> | 2016-01-23 13:23:25 -0500 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2016-01-27 19:10:13 -0500 |
commit | b4f35e5e07afa2df7125b814b45242648b33e39e (patch) | |
tree | b34236be3ec44cd00d7ae3b2e27f9f254e91a011 /crypto | |
parent | 3e9e810f2e047effb1056211794d2d12ec2b04e7 (diff) |
Remove EIGHT_BIT and SIXTEEN_BIT
Also cleaned up bn_prime.pl to current coding style.
Reviewed-by: Andy Polyakov <appro@openssl.org>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/bn/bn_prime.c | 8 | ||||
-rw-r--r-- | crypto/bn/bn_prime.h | 13 | ||||
-rw-r--r-- | crypto/bn/bn_prime.pl | 65 |
3 files changed, 26 insertions, 60 deletions
diff --git a/crypto/bn/bn_prime.c b/crypto/bn/bn_prime.c index 7d210d37cf..8d1294fcfc 100644 --- a/crypto/bn/bn_prime.c +++ b/crypto/bn/bn_prime.c @@ -115,18 +115,14 @@ #include <openssl/rand.h> /* - * NB: these functions have been "upgraded", the deprecated versions (which - * are compatibility wrappers using these functions) are in bn_depr.c. - - * Geoff - */ - -/* * The quick sieve algorithm approach to weeding out primes is Philip * Zimmermann's, as implemented in PGP. I have had a read of his comments * and implemented my own version. */ #include "bn_prime.h" +#define NUMPRIMES OSSL_NELEM(primes) + static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1, const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont); diff --git a/crypto/bn/bn_prime.h b/crypto/bn/bn_prime.h index c2824a8b48..d1fbcd1021 100644 --- a/crypto/bn/bn_prime.h +++ b/crypto/bn/bn_prime.h @@ -56,23 +56,15 @@ * [including the GNU Public Licence.] */ -#ifndef EIGHT_BIT -# define NUMPRIMES 2048 typedef unsigned short prime_t; -#else -# define NUMPRIMES 54 -typedef unsigned char prime_t; -#endif -static const prime_t primes[NUMPRIMES]= { +static const prime_t primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, - 227, 229, 233, 239, 241, 251, -#ifndef EIGHT_BIT - 257, 263, + 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, @@ -322,5 +314,4 @@ static const prime_t primes[NUMPRIMES]= { 17609, 17623, 17627, 17657, 17659, 17669, 17681, 17683, 17707, 17713, 17729, 17737, 17747, 17749, 17761, 17783, 17789, 17791, 17807, 17827, 17837, 17839, 17851, 17863, -#endif }; diff --git a/crypto/bn/bn_prime.pl b/crypto/bn/bn_prime.pl index 4e4426a1f4..add6ffb9d0 100644 --- a/crypto/bn/bn_prime.pl +++ b/crypto/bn/bn_prime.pl @@ -1,22 +1,4 @@ -#!/usr/local/bin/perl -# bn_prime.pl - -$num=2048; -$num=$ARGV[0] if ($#ARGV >= 0); - -push(@primes,2); -$p=1; -loop: while ($#primes < $num-1) - { - $p+=2; - $s=int(sqrt($p)); - - for ($i=0; defined($primes[$i]) && $primes[$i]<=$s; $i++) - { - next loop if (($p%$primes[$i]) == 0); - } - push(@primes,$p); - } +#! /usr/bin/env perl print <<\EOF; /* Auto generated by bn_prime.pl */ @@ -79,28 +61,25 @@ print <<\EOF; EOF -for ($i=0; $i <= $#primes; $i++) - { - if ($primes[$i] > 256) - { - $eight=$i; - last; - } - } -printf "#ifndef EIGHT_BIT\n"; -printf "# define NUMPRIMES %d\n",$num; -printf "typedef unsigned short prime_t;\n"; -printf "#else\n"; -printf "# define NUMPRIMES %d\n",$eight; -printf "typedef unsigned char prime_t;\n"; -printf "#endif\n"; -print "static const prime_t primes[NUMPRIMES]= {\n "; -$init=0; -for ($i=0; $i <= $#primes; $i++) - { - printf "\n#ifndef EIGHT_BIT\n " if ($primes[$i] > 256) && !($init++); - printf "\n " if (($i%8) == 0) && ($i != 0); - printf "%4d, ", $primes[$i]; - } -print "\n#endif\n};\n"; +my $num = shift || 2048; +my @primes = ( 2 ); +my $p = 1; +loop: while ($#primes < $num-1) { + $p += 2; + my $s = int(sqrt($p)); + + for (my $i = 0; defined($primes[$i]) && $primes[$i] <= $s; $i++) { + next loop if ($p % $primes[$i]) == 0; + } + push(@primes, $p); +} + +print "typedef unsigned short prime_t;\n"; + +print "static const prime_t primes[] = {"; +for (my $i = 0; $i <= $#primes; $i++) { + printf "\n " if ($i % 8) == 0; + printf "%4d, ", $primes[$i]; +} +print "\n};\n"; |