DSA fix from main branch.
This commit is contained in:
@@ -328,6 +328,7 @@ BIGNUM *BN_CTX_get(BN_CTX *ctx);
|
||||
void BN_CTX_end(BN_CTX *ctx);
|
||||
int BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
|
||||
int BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom);
|
||||
int BN_rand_range(BIGNUM *rnd, BIGNUM *min, BIGNUM *max);
|
||||
int BN_num_bits(const BIGNUM *a);
|
||||
int BN_num_bits_word(BN_ULONG);
|
||||
BIGNUM *BN_new(void);
|
||||
|
||||
@@ -140,3 +140,15 @@ int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
|
||||
{
|
||||
return bnrand(1, rnd, bits, top, bottom);
|
||||
}
|
||||
|
||||
/* random number r: min <= r < max */
|
||||
int BN_rand_range(BIGNUM *r, BIGNUM *min, BIGNUM *max)
|
||||
{
|
||||
int n = BN_num_bits(max);
|
||||
do
|
||||
{
|
||||
if (!BN_rand(r, n, 0, 0)) return 0;
|
||||
} while ((min && BN_cmp(r, min) < 0) || BN_cmp(r, max) >= 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -179,13 +179,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
|
||||
kinv=NULL;
|
||||
|
||||
/* Get random k */
|
||||
for (;;)
|
||||
{
|
||||
if (!BN_rand(&k, BN_num_bits(dsa->q), 0, 0)) goto err;
|
||||
if (BN_cmp(&k,dsa->q) >= 0)
|
||||
BN_sub(&k,&k,dsa->q);
|
||||
if (!BN_is_zero(&k)) break;
|
||||
}
|
||||
if (!BN_rand_range(&k, BN_value_one(), dsa->q)) goto err;
|
||||
|
||||
if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user