131 static int probable_prime(
BIGNUM *rnd,
int bits);
132 static int probable_prime_dh(
BIGNUM *rnd,
int bits,
134 static int probable_prime_dh_safe(
BIGNUM *rnd,
int bits,
151 return cb->
cb.
cb_2(a, b, cb);
169 if (ctx == NULL)
goto err;
177 if (!probable_prime(ret,bits))
goto err;
183 if (!probable_prime_dh_safe(ret,bits,add,rem,ctx))
188 if (!probable_prime_dh(ret,bits,add,rem,ctx))
200 if (i == -1)
goto err;
201 if (i == 0)
goto loop;
211 for (i=0; i<checks; i++)
214 if (j == -1)
goto err;
215 if (j == 0)
goto loop;
218 if (j == -1)
goto err;
219 if (j == 0)
goto loop;
249 BIGNUM *A1, *A1_odd, *check;
263 if (do_trial_division)
272 if (ctx_passed != NULL)
293 if (check == NULL)
goto err;
320 for (i = 0; i < checks; i++)
328 j = witness(check, A, A1, A1_odd, k, ctx, mont);
329 if (j == -1)
goto err;
343 if (ctx_passed == NULL)
377 static int probable_prime(
BIGNUM *rnd,
int bits)
381 BN_ULONG delta,maxdelta;
384 if (!
BN_rand(rnd,bits,1,1))
return(0);
388 maxdelta=BN_MASK2 - primes[NUMPRIMES-1];
394 if (((mods[i]+delta)%primes[i]) <= 1)
397 if (delta > maxdelta)
goto again;
406 static int probable_prime_dh(
BIGNUM *rnd,
int bits,
415 if (!
BN_rand(rnd,bits,0,1))
goto err;
419 if (!
BN_mod(t1,rnd,add,ctx))
goto err;
420 if (!
BN_sub(rnd,rnd,t1))
goto err;
424 {
if (!
BN_add(rnd,rnd,rem))
goto err; }
433 if (!
BN_add(rnd,rnd,add))
goto err;
444 static int probable_prime_dh_safe(
BIGNUM *
p,
int bits,
const BIGNUM *padd,
455 if (qadd == NULL)
goto err;
459 if (!
BN_rand(q,bits,0,1))
goto err;
462 if (!
BN_mod(t1,q,qadd,ctx))
goto err;
463 if (!
BN_sub(q,q,t1))
goto err;
469 if (!
BN_add(q,q,t1))
goto err;
484 if (!
BN_add(p,p,padd))
goto err;
485 if (!
BN_add(q,q,qadd))
goto err;