3 * $Id: pgen-gcd.c,v 1.1 2000/06/17 11:51:53 mdw Exp $
5 * Prime search stepper ensuring a low GCD for %$(p - 1)/2$%
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
32 * $Log: pgen-gcd.c,v $
33 * Revision 1.1 2000/06/17 11:51:53 mdw
34 * Filter which imposes additional restrictions on GCD of %$(p - 1)/2$%
35 * with a given integer.
39 /*----- Header files ------------------------------------------------------*/
44 /*----- Main code ---------------------------------------------------------*/
46 int pgen_gcdstep(int rq, pgen_event *ev, void *p)
48 pgen_gcdstepctx *g = p;
53 /* --- Set everything up --- *
55 * Call things off if @q@ and @jq@ have common factors.
60 g->q = mp_lsr(MP_NEW, p, 1);
61 g->jq = mp_lsr(MP_NEW, g->jp.m, 1);
62 mp_gcd(&g->g, 0, 0, g->q, g->jq);
63 if (MP_CMP(g->g, >, MP_ONE))
65 rc = pfilt_create(&g->p, p);
69 /* --- Grind through another iteration --- */
73 rc = pfilt_jump(&g->p, &g->jp);
74 g->q = mp_add(g->q, g->q, g->jq);
77 /* --- Finished --- */
86 /* --- Step on until everything is OK --- */
89 if (rc != PGEN_FAIL) {
90 mp_gcd(&g->g, 0, 0, g->r, g->q);
91 if (MP_CMP(g->g, >, g->max))
96 rc = pfilt_jump(&g->p, &g->jp);
97 g->q = mp_add(g->q, g->q, g->jq);
100 ev->m = MP_COPY(g->p.m);
104 /*----- That's all, folks -------------------------------------------------*/