summaryrefslogtreecommitdiffstats
path: root/crypto/bn/bn_prime.c
diff options
context:
space:
mode:
authorBodo Möller <bodo@openssl.org>2006-09-18 14:01:39 +0000
committerBodo Möller <bodo@openssl.org>2006-09-18 14:01:39 +0000
commit7d5af5e0fa8605e0f29dbab1782ed1e58a0484ca (patch)
tree4ad99722be91c47fd1f3d53e58b25a585cd551dd /crypto/bn/bn_prime.c
parent8fdb296cbdf0228b4c08aa5621ca394db5a9ce45 (diff)
Ensure that the addition mods[i]+delta cannot overflow in probable_prime().
[Problem pointed out by Adam Young <adamy (at) acm.org>]
Diffstat (limited to 'crypto/bn/bn_prime.c')
-rw-r--r--crypto/bn/bn_prime.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/crypto/bn/bn_prime.c b/crypto/bn/bn_prime.c
index d57f658211..5bab019553 100644
--- a/crypto/bn/bn_prime.c
+++ b/crypto/bn/bn_prime.c
@@ -378,13 +378,14 @@ static int probable_prime(BIGNUM *rnd, int bits)
{
int i;
BN_ULONG mods[NUMPRIMES];
- BN_ULONG delta,d;
+ 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]);
+ maxdelta=BN_MASK2 - primes[NUMPRIMES-1];
delta=0;
loop: for (i=1; i<NUMPRIMES; i++)
{
@@ -392,12 +393,8 @@ again:
* that gcd(rnd-1,primes) == 1 (except for 2) */
if (((mods[i]+delta)%primes[i]) <= 1)
{
- d=delta;
delta+=2;
- /* perhaps need to check for overflow of
- * delta (but delta can be up to 2^32)
- * 21-May-98 eay - added overflow check */
- if (delta < d) goto again;
+ if (delta > maxdelta) goto again;
goto loop;
}
}