/* -*-c-*-
*
- * $Id: pgen.h,v 1.7 2000/08/18 19:16:12 mdw Exp $
+ * $Id$
*
* Prime generation glue
*
* (c) 1999 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of Catacomb.
*
* 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.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
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@ --- *
*
pfilt f;
} pgen_jumpctx;
-extern int pgen_jump(int /*rq*/, pgen_event */*ev*/, void */*p*/);
+extern pgen_proc pgen_jump;
/* --- @pgen_test@ --- *
*
* @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 int pgen_safejump(int /*rq*/, pgen_event */*ev*/, void */*p*/);
+extern pgen_proc pgen_simulstep;
-/* --- @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 --------------------------------*/
* %$\gcd(p, r) \le max$%.
*/
-extern int pgen_gcdstep(int /*rq*/, pgen_event */*ev*/, void */*p*/);
+extern pgen_proc pgen_gcdstep;
/*----- Standard event handlers -------------------------------------------*/
* 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 ---------------------------------------------------*/
* @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.
unsigned /*steps*/, pgen_proc */*step*/, void */*sctx*/,
unsigned /*tests*/, pgen_proc */*test*/, void */*tctx*/);
+/* --- @pgen_primep@ --- *
+ *
+ * Arguments: @mp *p@ = a number to check
+ * @grand *gr@ = a random number source
+ *
+ * Returns: Nonzero if @p@ is really prime.
+ */
+
+extern int pgen_primep(mp */*p*/, grand */*gr*/);
+
/*----- That's all, folks -------------------------------------------------*/
#ifdef __cplusplus