Add cyclic group abstraction, with test code. Separate off exponentation
[u/mdw/catacomb] / pfilt.c
diff --git a/pfilt.c b/pfilt.c
index 1dc46a1..e3d1d3d 100644 (file)
--- a/pfilt.c
+++ b/pfilt.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: pfilt.c,v 1.4 2000/10/08 12:14:57 mdw Exp $
+ * $Id: pfilt.c,v 1.5 2004/04/01 12:50:09 mdw Exp $
  *
  * Finding and testing prime numbers
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: pfilt.c,v $
+ * Revision 1.5  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.4  2000/10/08 12:14:57  mdw
  * Remove vestiges of @primorial@.
  *
@@ -113,7 +120,8 @@ int pfilt_smallfactor(mp *m)
   int rc = PGEN_TRY;
   int i;
   size_t sz = MP_LEN(m);
-  mpw *v = mpalloc(m->a, sz);
+  mparena *a = m->a ? m->a : MPARENA_GLOBAL;
+  mpw *v = mpalloc(a, sz);
 
   /* --- Fill in the residues --- */
 
@@ -133,7 +141,7 @@ int pfilt_smallfactor(mp *m)
 
   /* --- Done --- */
 
-  mpfree(m->a, v);
+  mpfree(a, v);
   return (rc);
 }
 
@@ -155,7 +163,8 @@ int pfilt_create(pfilt *p, mp *m)
   int rc = PGEN_TRY;
   int i;
   size_t sz = MP_LEN(m);
-  mpw *v = mpalloc(m->a, sz);
+  mparena *a = m->a ? m->a : MPARENA_GLOBAL;
+  mpw *v = mpalloc(a, sz);
 
   /* --- Take a copy of the number --- */
 
@@ -181,7 +190,7 @@ int pfilt_create(pfilt *p, mp *m)
 
   /* --- Done --- */
 
-  mpfree(m->a, v);
+  mpfree(a, v);
   return (rc);
 }