Makefile.m4: Remove mplimits.[ch] on clean.
[u/mdw/catacomb] / dh-gen.c
index e909989..a1b61a1 100644 (file)
--- a/dh-gen.c
+++ b/dh-gen.c
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: dh-gen.c,v 1.1 2000/02/12 18:21:02 mdw Exp $
+ * $Id: dh-gen.c,v 1.3 2004/04/08 01:36:15 mdw Exp $
  *
  * Generate Diffie-Hellman parameters
  *
  * (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: dh-gen.c,v $
- * Revision 1.1  2000/02/12 18:21:02  mdw
- * Overhaul of key management (again).
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
+#include <mLib/macros.h>
+
 #include "dh.h"
 #include "grand.h"
 #include "mp.h"
@@ -79,15 +73,22 @@ int dh_gen(dh_param *dp, unsigned ql, unsigned pl, unsigned steps, grand *r,
   /* --- If @ql@ is zero, do the time consuming safe-prime thing --- */
 
   if (!ql) {
-    pgen_safetestctx c;
-
-    mp *m = mprand(MP_NEW, pl, r, 3);
-    dp->p = pgen("p", MP_NEW, m, event, ectx, steps, pgen_safestep, &c.c,
-                rabin_iters(pl), pgen_safetest, &c);
+    pgen_simulprime sp[2];
+    pgen_simulctx ss;
+
+    mp *m = mprand(MP_NEW, pl - 1, r, 1);
+    ss.step = MP_TWO;
+    sp[0].mul = MP_ONE; sp[0].add = MP_ZERO; sp[0].f = 0;
+    sp[1].mul = MP_TWO; sp[1].add = MP_ONE; sp[1].f = PGENF_KEEP;
+    ss.v = sp; ss.n = N(sp);
+    dp->q = pgen("p", MP_NEW, m, event, ectx, steps, pgen_simulstep, &ss,
+                rabin_iters(pl), pgen_simultest, &ss);
     mp_drop(m);
-    if (!dp->p)
+    if (!dp->q) {
+      mp_drop(sp[1].u.x);
       return (PGEN_ABORT);
-    dp->q = mp_lsr(MP_NEW, dp->p, 1);
+    }
+    dp->p = sp[1].u.x;
     dp->g = MP_FOUR;
     return (PGEN_DONE);
   }
@@ -137,7 +138,7 @@ int dh_gen(dh_param *dp, unsigned ql, unsigned pl, unsigned steps, grand *r,
     mpmont_create(&p.mm, dp->p);
     mp_div(&m, 0, dp->p, dp->q);
     i = 0;
-    p.f = m;
+    p.exp = m;
     p.n = 0;
     dp->g = pgen("g", MP_NEW, MP_NEW, event, ectx, 0, prim_step, &i,
                 1, prim_test, &p);