3 * $Id: pgen-gcd.c,v 1.2 2000/07/01 11:09:20 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.2 2000/07/01 11:09:20 mdw
34 * (pgen_gcd): Bug fix -- check the GCDs of the right things when deciding
37 * Revision 1.1 2000/06/17 11:51:53 mdw
38 * Filter which imposes additional restrictions on GCD of %$(p - 1)/2$%
39 * with a given integer.
43 /*----- Header files ------------------------------------------------------*/
48 /*----- Main code ---------------------------------------------------------*/
50 int pgen_gcdstep(int rq
, pgen_event
*ev
, void *p
)
52 pgen_gcdstepctx
*g
= p
;
57 /* --- Set everything up --- *
59 * Call things off if @p@ and @jp@ have common factors, or if @q@, @r@
60 * and @jq@ have common factors greater than @max@.
65 mp_gcd(&g
->g
, 0, 0, p
, g
->jp
.m
);
66 if (MP_CMP(g
->g
, >, MP_ONE
))
68 g
->q
= mp_lsr(MP_NEW
, p
, 1);
69 g
->jq
= mp_lsr(MP_NEW
, g
->jp
.m
, 1);
70 mp_gcd(&g
->g
, 0, 0, g
->q
, g
->jq
);
71 mp_gcd(&g
->g
, 0, 0, g
->g
, g
->r
);
72 if (MP_CMP(g
->g
, >, g
->max
)) {
77 rc
= pfilt_create(&g
->p
, p
);
81 /* --- Grind through another iteration --- */
85 rc
= pfilt_jump(&g
->p
, &g
->jp
);
86 g
->q
= mp_add(g
->q
, g
->q
, g
->jq
);
89 /* --- Finished --- */
98 /* --- Step on until everything is OK --- */
101 if (rc
!= PGEN_FAIL
) {
102 mp_gcd(&g
->g
, 0, 0, g
->r
, g
->q
);
103 if (MP_CMP(g
->g
, >, g
->max
))
108 rc
= pfilt_jump(&g
->p
, &g
->jp
);
109 g
->q
= mp_add(g
->q
, g
->q
, g
->jq
);
112 ev
->m
= MP_COPY(g
->p
.m
);
116 /*----- That's all, folks -------------------------------------------------*/