X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/34e4f738bcba58e6d8c4cabbb0b3232a65b42a9d..cc3ca08f22460b15423bb88632f3a12741b19003:/pgen.h diff --git a/pgen.h b/pgen.h index 1834f03..a066e28 100644 --- a/pgen.h +++ b/pgen.h @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: pgen.h,v 1.8 2004/04/01 12:50:09 mdw Exp $ + * $Id$ * * Prime generation glue * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,43 +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.h,v $ - * Revision 1.8 2004/04/01 12:50:09 mdw - * Add cyclic group abstraction, with test code. Separate off exponentation - * functions for better static linking. Fix a buttload of bugs on the way. - * Generally ensure that negative exponents do inversion correctly. Add - * table of standard prime-field subgroups. (Binary field subgroups are - * currently unimplemented but easy to add if anyone ever finds a good one.) - * - * Revision 1.7 2000/08/18 19:16:12 mdw - * New event handler for showing in detail sub-prime generation. - * - * Revision 1.6 2000/06/17 11:52:12 mdw - * Add the GCD filter. - * - * Revision 1.5 2000/02/12 18:21:03 mdw - * Overhaul of key management (again). - * - * Revision 1.4 1999/12/22 16:01:11 mdw - * Same file, completely different code. Main interface for new prime- - * search system. - * - */ - #ifndef CATACOMB_PGEN_H #define CATACOMB_PGEN_H @@ -170,7 +145,7 @@ typedef struct pgen_filterctx { pfilt f; /* The rapid prime filter */ } pgen_filterctx; -extern int pgen_filter(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_filter; /* --- @pgen_jump@ --- * * @@ -183,7 +158,7 @@ typedef struct pgen_jumpctx { pfilt f; } pgen_jumpctx; -extern int pgen_jump(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_jump; /* --- @pgen_test@ --- * * @@ -191,46 +166,43 @@ extern int pgen_jump(int /*rq*/, pgen_event */*ev*/, void */*p*/); * @rabin@ context. */ -extern int pgen_test(int /*rq*/, pgen_event */*ev*/, void */*p*/); - -/*----- Safe prime functions ----------------------------------------------*/ - -/* --- @pgen_safestep@ --- * - * - * Steps two numbers, %$q$% and %$p = 2q + 1$%, such that neither has any - * small factors. %$p$% is put in the event block. - */ - -typedef struct pgen_safestepctx { - pfilt q, p; -} pgen_safestepctx; - -extern int pgen_safestep(int /*rq*/, pgen_event */*ev*/, void */*p*/); - -/* --- @pgen_safejump@ --- * - * - * Jumps two numbers, %$q$% and %$p = 2q + 1$% such that neither has any - * small factors. +extern pgen_proc pgen_test; + +/*----- Simultaneous primality checking -----------------------------------*/ + +typedef struct pgen_simulprime { + mp *mul, *add; /* Arguments from the client */ + unsigned f; /* Flags, set by client, changed */ +#define PGENF_KEEP 1u /* Keep this prime's value */ +#define PGENF_JUMP 8u /* Use jump table, not stepping */ + pfilt p; /* This prime's filter */ + rabin r; /* Rabin testing context */ + union { + mpw step; /* The simple step to use */ + pfilt *jump; /* The jump to move by */ + mp *x; /* The result, if wanted */ + } u; +} pgen_simulprime; + +typedef struct pgen_simulctx { + pgen_simulprime *v; /* Vector of related primes */ + unsigned n; /* Size of the vector */ + mp *step; /* Basic stepping value */ +} pgen_simulctx; + +/* --- @pgen_simulstep@ --- * + * + * Step a collection of numbers simultaneously. */ -typedef struct pgen_safejumpctx { - pfilt q, jq; - pfilt p, jp; -} pgen_safejumpctx; +extern pgen_proc pgen_simulstep; -extern int pgen_safejump(int /*rq*/, pgen_event */*ev*/, void */*p*/); - -/* --- @pgen_safetest@ --- * +/* --- @pgen_simultest@ --- * * - * Applies Rabin-Miller tests to %$p$% and %$(p - 1)/2$%. + * Test a collection of numbers simultaneously. */ -typedef struct pgen_safetestctx { - pgen_safestepctx c; - rabin q, p; -} pgen_safetestctx; - -extern int pgen_safetest(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_simultest; /*----- Miscellaneous steppers and testers --------------------------------*/ @@ -248,7 +220,7 @@ typedef struct pgen_gcdstepctx { * %$\gcd(p, r) \le max$%. */ -extern int pgen_gcdstep(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_gcdstep; /*----- Standard event handlers -------------------------------------------*/ @@ -257,21 +229,21 @@ extern int pgen_gcdstep(int /*rq*/, pgen_event */*ev*/, void */*p*/); * Displays a spinning baton to show progress. */ -extern int pgen_evspin(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_evspin; /* --- @pgen_ev@ --- * * * Traditional event handler, shows dots for each test. */ -extern int pgen_ev(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_ev; /* --- @pgen_subev@ --- * * * Subsidiary event handler, mainly for Lim-Lee searches and so on. */ -extern int pgen_subev(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_subev; /*----- The main driver ---------------------------------------------------*/ @@ -289,7 +261,7 @@ extern int pgen_subev(int /*rq*/, pgen_event */*ev*/, void */*p*/); * @pgen_proc *test@ = tester function to use * @void *tctx@ = context argument for tester * - * Returns: If successful, @PGEN_DONE@; otherwise @PGEN_ABORT@. + * Returns: The resulting value, or null. * * Use: A generalized prime-number search skeleton. Yes, that's a * scary number of arguments.