Remove static from probable_prime_dh.
This commit is contained in:
parent
e55fca760b
commit
e46a059ebf
@ -534,6 +534,9 @@ int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_U
|
|||||||
BIGNUM *int_bn_mod_inverse(BIGNUM *in,
|
BIGNUM *int_bn_mod_inverse(BIGNUM *in,
|
||||||
const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx, int *noinv);
|
const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx, int *noinv);
|
||||||
|
|
||||||
|
int bn_probable_prime_dh(BIGNUM *rnd, int bits,
|
||||||
|
const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -129,8 +129,6 @@
|
|||||||
static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
|
static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
|
||||||
const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont);
|
const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont);
|
||||||
static int probable_prime(BIGNUM *rnd, int bits);
|
static int probable_prime(BIGNUM *rnd, int bits);
|
||||||
static int probable_prime_dh(BIGNUM *rnd, int bits,
|
|
||||||
const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
|
|
||||||
static int probable_prime_dh_safe(BIGNUM *rnd, int bits,
|
static int probable_prime_dh_safe(BIGNUM *rnd, int bits,
|
||||||
const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
|
const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
|
||||||
|
|
||||||
@ -198,7 +196,7 @@ loop:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!probable_prime_dh(ret,bits,add,rem,ctx))
|
if (!bn_probable_prime_dh(ret,bits,add,rem,ctx))
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,6 +360,45 @@ err:
|
|||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bn_probable_prime_dh(BIGNUM *rnd, int bits,
|
||||||
|
const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx)
|
||||||
|
{
|
||||||
|
int i,ret=0;
|
||||||
|
BIGNUM *t1;
|
||||||
|
|
||||||
|
BN_CTX_start(ctx);
|
||||||
|
if ((t1 = BN_CTX_get(ctx)) == NULL) goto err;
|
||||||
|
|
||||||
|
if (!BN_rand(rnd,bits,0,1)) goto err;
|
||||||
|
|
||||||
|
/* we need ((rnd-rem) % add) == 0 */
|
||||||
|
|
||||||
|
if (!BN_mod(t1,rnd,add,ctx)) goto err;
|
||||||
|
if (!BN_sub(rnd,rnd,t1)) goto err;
|
||||||
|
if (rem == NULL)
|
||||||
|
{ if (!BN_add_word(rnd,1)) goto err; }
|
||||||
|
else
|
||||||
|
{ if (!BN_add(rnd,rnd,rem)) goto err; }
|
||||||
|
|
||||||
|
/* we now have a random number 'rand' to test. */
|
||||||
|
|
||||||
|
loop:
|
||||||
|
for (i=1; i<NUMPRIMES; i++)
|
||||||
|
{
|
||||||
|
/* check that rnd is a prime */
|
||||||
|
if (BN_mod_word(rnd,(BN_ULONG)primes[i]) <= 1)
|
||||||
|
{
|
||||||
|
if (!BN_add(rnd,rnd,add)) goto err;
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret=1;
|
||||||
|
err:
|
||||||
|
BN_CTX_end(ctx);
|
||||||
|
bn_check_top(rnd);
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
|
static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
|
||||||
const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont)
|
const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont)
|
||||||
{
|
{
|
||||||
@ -454,45 +491,6 @@ loop:
|
|||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int probable_prime_dh(BIGNUM *rnd, int bits,
|
|
||||||
const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx)
|
|
||||||
{
|
|
||||||
int i,ret=0;
|
|
||||||
BIGNUM *t1;
|
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
|
||||||
if ((t1 = BN_CTX_get(ctx)) == NULL) goto err;
|
|
||||||
|
|
||||||
if (!BN_rand(rnd,bits,0,1)) goto err;
|
|
||||||
|
|
||||||
/* we need ((rnd-rem) % add) == 0 */
|
|
||||||
|
|
||||||
if (!BN_mod(t1,rnd,add,ctx)) goto err;
|
|
||||||
if (!BN_sub(rnd,rnd,t1)) goto err;
|
|
||||||
if (rem == NULL)
|
|
||||||
{ if (!BN_add_word(rnd,1)) goto err; }
|
|
||||||
else
|
|
||||||
{ if (!BN_add(rnd,rnd,rem)) goto err; }
|
|
||||||
|
|
||||||
/* we now have a random number 'rand' to test. */
|
|
||||||
|
|
||||||
loop:
|
|
||||||
for (i=1; i<NUMPRIMES; i++)
|
|
||||||
{
|
|
||||||
/* check that rnd is a prime */
|
|
||||||
if (BN_mod_word(rnd,(BN_ULONG)primes[i]) <= 1)
|
|
||||||
{
|
|
||||||
if (!BN_add(rnd,rnd,add)) goto err;
|
|
||||||
goto loop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret=1;
|
|
||||||
err:
|
|
||||||
BN_CTX_end(ctx);
|
|
||||||
bn_check_top(rnd);
|
|
||||||
return(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,
|
static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,
|
||||||
const BIGNUM *rem, BN_CTX *ctx)
|
const BIGNUM *rem, BN_CTX *ctx)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user