X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/0b09aab8c8a83e618a2c5d00f716102fb8db13e4..373641eaacc86b56715a2ebf0b603fce25c16051:/pub/rsa-gen.c diff --git a/pub/rsa-gen.c b/pub/rsa-gen.c index 0653d1c3..3b5334b8 100644 --- a/pub/rsa-gen.c +++ b/pub/rsa-gen.c @@ -73,7 +73,6 @@ int rsa_gen(rsa_priv *rp, unsigned nbits, grand *r, unsigned n, * conservative about that sort of thing. */ -again: if ((rp->p = strongprime("p", MP_NEWSEC, nbits/2, r, n, event, ectx)) == 0) goto fail_p; @@ -85,16 +84,11 @@ again: { mp *q; - mp *t = MP_NEW, *u = MP_NEW; rabin rb; if ((q = strongprime_setup("q", MP_NEWSEC, &g.jp, nbits / 2, r, n, event, ectx)) == 0) goto fail_q; - t = mp_lsl(t, MP_ONE, nbits - 1); - mp_div(&t, &u, t, rp->p); - if (!MP_ZEROP(u)) t = mp_add(t, t, MP_ONE); - if (MP_CMP(q, <, t)) q = mp_leastcongruent(q, t, q, g.jp.m); g.r = mp_lsr(MP_NEW, rp->p, 1); g.g = MP_NEW; @@ -105,10 +99,7 @@ again: mp_drop(g.r); if (!q) { mp_drop(g.g); - if (n) - goto fail_q; - mp_drop(rp->p); - goto again; + goto fail_q; } rp->q = q; } @@ -124,10 +115,7 @@ again: MP_LEN(phi) * 4 < MP_LEN(rp->q) * 3) { mp_drop(rp->p); mp_drop(g.g); - if (n) - goto fail_q; - mp_drop(rp->q); - goto again; + goto fail_q; } if (MP_NEGP(phi)) { @@ -164,6 +152,8 @@ again: mp_gcd(&g.g, 0, &rp->d, phi, rp->e); if (!MP_EQ(g.g, MP_ONE) && MP_LEN(rp->d) * 4 > MP_LEN(rp->n) * 3) goto fail_e; + if (mp_bits(rp->n) != nbits) + goto fail_e; /* --- Work out exponent residues --- */