X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/f39a39c92bc544254baf4d158e8e41755369c557..8b021c3f89a78c3006ffc5d480feca6ef86d544e:/pgen-safe.c diff --git a/pgen-safe.c b/pgen-safe.c index a8c5ac7..b680ae4 100644 --- a/pgen-safe.c +++ b/pgen-safe.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: pgen-safe.c,v 1.2 2000/02/12 18:21:03 mdw Exp $ + * $Id: pgen-safe.c,v 1.3 2000/06/17 11:52:36 mdw Exp $ * * Safe prime generation * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: pgen-safe.c,v $ + * Revision 1.3 2000/06/17 11:52:36 mdw + * Signal a pgen abort if the jump and base share a common factor. + * * Revision 1.2 2000/02/12 18:21:03 mdw * Overhaul of key management (again). * @@ -119,17 +122,27 @@ int pgen_safejump(int rq, pgen_event *ev, void *p) * * The jump in @j.q@ is congruent to 2 (mod 4); see @strongprime_setup@. * If @p@ is initially 1 (mod 4) then add @j.q@. Then double @j.q@ to - * ensure that the step is 0 (mod 4). + * ensure that the step is 0 (mod 4). Ensure that @jq@ and @q@ don't + * have any common factors. */ case PGEN_BEGIN: { mp *p = ev->m; mp *q; + mp *g = MP_NEW; if ((p->v[0] & 3) != 3) p = mp_add(p, p, j->jq.m); + q = mp_lsr(MP_NEW, p, 1); + mp_gcd(&g, 0, 0, q, j->jq.m); + if (MP_CMP(g, >, MP_ONE)) { + ev->m = p; + mp_drop(q); + mp_drop(g); + return (PGEN_ABORT); + } + mp_drop(g); rc = pfilt_create(&j->p, p); pfilt_muladd(&j->jp, &j->jq, 2, 0); - q = mp_lsr(MP_NEW, p, 1); qrc = pfilt_create(&j->q, q); mp_drop(p); mp_drop(q);