--- /dev/null
+/* -*-c-*-
+ *
+ * $Id: pgen.h,v 1.1 1999/11/19 13:17:57 mdw Exp $
+ *
+ * Finding and testing prime numbers
+ *
+ * (c) 1999 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of Catacomb.
+ *
+ * Catacomb is free software; you can redistribute it and/or modify
+ * 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.1 1999/11/19 13:17:57 mdw
+ * Prime number generator and tester.
+ *
+ */
+
+#ifndef PGEN_H
+#define PGEN_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#ifndef MP_H
+# include "mp.h"
+#endif
+
+#ifndef PTAB_H
+# include "ptab.h"
+#endif
+
+/*----- Constants ---------------------------------------------------------*/
+
+#define PGEN_COMPOSITE (-1) /* Number is definitely composite */
+#define PGEN_MAYBE (0) /* Number may be prime */
+#define PGEN_PRIME (1) /* Number is definitely prime */
+
+/*----- Data structures ---------------------------------------------------*/
+
+typedef struct pgen {
+ mp *m;
+ unsigned char r[NPRIME];
+} pgen;
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @pgen_create@ --- *
+ *
+ * Arguments: @pgen *p@ = pointer to prime generation context
+ * @mp *m@ = pointer to initial number to test
+ *
+ * Returns: One of the @PGEN@ constants above.
+ *
+ * Use: Tests an initial number for primality by computing its
+ * residue modulo various small prime numbers. This is fairly
+ * quick, but not particularly certain. If a @PGEN_MAYBE@
+ * result is returned, perform Rabin-Miller tests to confirm.
+ */
+
+extern int pgen_create(pgen */*p*/, mp */*m*/);
+
+/* --- @pgen_destroy@ --- *
+ *
+ * Arguments: @pgen *p@ = pointer to prime generation context
+ *
+ * Returns: ---
+ *
+ * Use: Discards a context and all the resources it holds.
+ */
+
+extern void pgen_destroy(pgen */*p*/);
+
+/* --- @pgen_step@ --- *
+ *
+ * Arguments: @pgen *p@ = pointer to prime generation context
+ * @mpw step@ = how much to step the number
+ *
+ * Returns: One of the @PGEN@ constants above.
+ *
+ * Use: Steps a number by a small amount. Stepping is much faster
+ * than initializing with a new number. The test performed is
+ * the same simple one used by @ptab_create@, so @PGEN_MAYBE@
+ * results should be followed up by a Rabin-Miller test.
+ */
+
+extern int pgen_step(pgen */*p*/, mpw /*step*/);
+
+/* --- @pgen_jump@ --- *
+ *
+ * Arguments: @pgen *p@ = pointer to prime generation context
+ * @pgen *j@ = pointer to another generation context
+ *
+ * Returns: One of the @PGEN@ constants above.
+ *
+ * Use: Steps a number by a large amount. Even so, jumping is much
+ * faster than initializing a new number. The test peformed is
+ * the same simple one used by @ptab_create@, so @PGEN_MAYBE@
+ * results should be followed up by a Rabin-Miller test.
+ *
+ * Note that the number stored in the @j@ context is probably
+ * better off being even than prime. The important thing is
+ * that all of the residues for the number have already been
+ * computed.
+ */
+
+extern int pgen_jump(pgen */*p*/, pgen */*j*/);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif