Minimize stack utilization in probable_prime.
authorAndy Polyakov <appro@openssl.org>
Tue, 18 Sep 2007 20:52:05 +0000 (20:52 +0000)
committerAndy Polyakov <appro@openssl.org>
Tue, 18 Sep 2007 20:52:05 +0000 (20:52 +0000)
crypto/bn/bn_prime.c
crypto/bn/bn_prime.h
crypto/bn/bn_prime.pl

index 5bab019553bf2ecf3486e46c561c01408520be89..7b25979dd1c450324eaf08a5574fb3ba0a9b92b7 100644 (file)
@@ -377,14 +377,14 @@ static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
 static int probable_prime(BIGNUM *rnd, int bits)
        {
        int i;
-       BN_ULONG mods[NUMPRIMES];
+       prime_t mods[NUMPRIMES];
        BN_ULONG delta,maxdelta;
 
 again:
        if (!BN_rand(rnd,bits,1,1)) return(0);
        /* we now have a random number 'rand' to test. */
        for (i=1; i<NUMPRIMES; i++)
-               mods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]);
+               mods[i]=(prime_t)BN_mod_word(rnd,(BN_ULONG)primes[i]);
        maxdelta=BN_MASK2 - primes[NUMPRIMES-1];
        delta=0;
        loop: for (i=1; i<NUMPRIMES; i++)
index b7cf9a9bfe124d9361686fdc8b9d4010b8f6e8fc..51d2194febdb66268674ec31e062a1fdaa5c3944 100644 (file)
 
 #ifndef EIGHT_BIT
 #define NUMPRIMES 2048
+typedef unsigned short prime_t;
 #else
 #define NUMPRIMES 54
+typedef unsigned char prime_t;
 #endif
-static const unsigned int primes[NUMPRIMES]=
+static const prime_t primes[NUMPRIMES]=
        {
           2,   3,   5,   7,  11,  13,  17,  19,
          23,  29,  31,  37,  41,  43,  47,  53,
index e583d1d53b9dffb2178778c26ad2f280e1c6c304..3fafb6f3e90aa8576fcacd2ea56a65cabd192232 100644 (file)
@@ -101,10 +101,12 @@ for ($i=0; $i <= $#primes; $i++)
 
 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 unsigned int primes[NUMPRIMES]=\n\t{\n\t";
+print "static const prime_t primes[NUMPRIMES]=\n\t{\n\t";
 $init=0;
 for ($i=0; $i <= $#primes; $i++)
        {