Commit 5855faca authored by Niels Möller's avatar Niels Möller

(dsa_generate_keypair): Updated for changes in nettle_random_prime and

_nettle_generate_pocklington_prime. Invoke progress callback.

Rev: nettle/dsa-keygen.c:1.7
parent f7695101
......@@ -43,7 +43,7 @@
int
dsa_generate_keypair(struct dsa_public_key *pub,
struct dsa_private_key *key,
void *ctx, nettle_random_func random,
void *random_ctx, nettle_random_func random,
void *progress_ctx, nettle_progress_func progress,
unsigned p_bits, unsigned q_bits)
{
......@@ -65,24 +65,35 @@ dsa_generate_keypair(struct dsa_public_key *pub,
return 0;
}
nettle_random_prime (pub->q, q_bits, ctx, random);
mpz_init (p0);
mpz_init (p0q);
mpz_init (r);
nettle_random_prime (pub->q, q_bits, 0, random_ctx, random,
progress_ctx, progress);
p0_bits = (p_bits + 3)/2;
nettle_random_prime (p0, p0_bits, ctx, random);
nettle_random_prime (p0, p0_bits, 0,
random_ctx, random,
progress_ctx, progress);
if (progress)
progress (progress_ctx, 'q');
/* Generate p = 2 r q p0 + 1, such that 2^{n-1} < p < 2^n.
*
* We select r in the range i + 1 < r <= 2i, with i = floor (2^{n-2} / (p0 q). */
mpz_init (p0q);
mpz_mul (p0q, p0, pub->q);
_nettle_generate_pocklington_prime (pub->p, p_bits, r,
ctx, random,
_nettle_generate_pocklington_prime (pub->p, r, p_bits, 0,
random_ctx, random,
p0, pub->q, p0q);
if (progress)
progress (progress_ctx, 'p');
mpz_mul (r, r, p0);
for (a = 2; ; a++)
......@@ -93,13 +104,19 @@ dsa_generate_keypair(struct dsa_public_key *pub,
break;
}
if (progress)
progress (progress_ctx, 'g');
mpz_init_set(r, pub->q);
mpz_sub_ui(r, r, 2);
nettle_mpz_random(key->x, ctx, random, r);
nettle_mpz_random(key->x, random_ctx, random, r);
mpz_add_ui(key->x, key->x, 1);
mpz_powm(pub->y, pub->g, key->x, pub->p);
if (progress)
progress (progress_ctx, '\n');
mpz_clear (p0);
mpz_clear (p0q);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment