X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/423c89a3b19646bd914c2c0826b7ae05c41fb0a1..cc3ca08f22460b15423bb88632f3a12741b19003:/pgen-gcd.c diff --git a/pgen-gcd.c b/pgen-gcd.c index cd23c37..863b151 100644 --- a/pgen-gcd.c +++ b/pgen-gcd.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: pgen-gcd.c,v 1.1 2000/06/17 11:51:53 mdw Exp $ + * $Id: pgen-gcd.c,v 1.3 2004/04/08 01:36:15 mdw Exp $ * * Prime search stepper ensuring a low GCD for %$(p - 1)/2$% * * (c) 2000 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,27 +15,18 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: pgen-gcd.c,v $ - * Revision 1.1 2000/06/17 11:51:53 mdw - * Filter which imposes additional restrictions on GCD of %$(p - 1)/2$% - * with a given integer. - * - */ - /*----- Header files ------------------------------------------------------*/ #include "mp.h" @@ -52,16 +43,24 @@ int pgen_gcdstep(int rq, pgen_event *ev, void *p) /* --- Set everything up --- * * - * Call things off if @q@ and @jq@ have common factors. + * Call things off if @p@ and @jp@ have common factors, or if @q@, @r@ + * and @jq@ have common factors greater than @max@. */ case PGEN_BEGIN: { mp *p = ev->m; + mp_gcd(&g->g, 0, 0, p, g->jp.m); + if (MP_CMP(g->g, >, MP_ONE)) + return (PGEN_ABORT); g->q = mp_lsr(MP_NEW, p, 1); g->jq = mp_lsr(MP_NEW, g->jp.m, 1); mp_gcd(&g->g, 0, 0, g->q, g->jq); - if (MP_CMP(g->g, >, MP_ONE)) + mp_gcd(&g->g, 0, 0, g->g, g->r); + if (MP_CMP(g->g, >, g->max)) { + mp_drop(g->q); + mp_drop(g->jq); return (PGEN_ABORT); + } rc = pfilt_create(&g->p, p); mp_drop(p); } break;