1d205b5c7cffd98044c7dba4bb115a1011497d2c
3 * Prime search stepper ensuring a low GCD for %$(p - 1)/2$%
5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
33 /*----- Main code ---------------------------------------------------------*/
35 int pgen_gcdstep(int rq
, pgen_event
*ev
, void *p
)
37 pgen_gcdstepctx
*g
= p
;
42 /* --- Set everything up --- *
44 * Call things off if @p@ and @jp@ have common factors, or if @q@, @r@
45 * and @jq@ have common factors greater than @max@.
50 mp_gcd(&g
->g
, 0, 0, p
, g
->jp
.m
);
51 if (MP_CMP(g
->g
, >, MP_ONE
))
53 g
->q
= mp_lsr(MP_NEW
, p
, 1);
54 g
->jq
= mp_lsr(MP_NEW
, g
->jp
.m
, 1);
55 mp_gcd(&g
->g
, 0, 0, g
->q
, g
->jq
);
56 mp_gcd(&g
->g
, 0, 0, g
->g
, g
->r
);
57 if (MP_CMP(g
->g
, >, g
->max
)) {
62 rc
= pfilt_create(&g
->p
, p
);
66 /* --- Grind through another iteration --- */
70 rc
= pfilt_jump(&g
->p
, &g
->jp
);
71 g
->q
= mp_add(g
->q
, g
->q
, g
->jq
);
74 /* --- Finished --- */
83 /* --- Step on until everything is OK --- */
86 if (rc
!= PGEN_FAIL
) {
87 mp_gcd(&g
->g
, 0, 0, g
->r
, g
->q
);
88 if (MP_CMP(g
->g
, >, g
->max
))
93 rc
= pfilt_jump(&g
->p
, &g
->jp
);
94 g
->q
= mp_add(g
->q
, g
->q
, g
->jq
);
97 ev
->m
= MP_COPY(g
->p
.m
);
101 /*----- That's all, folks -------------------------------------------------*/