/* -*-c-*-
*
- * $Id: dh-gen.c,v 1.2 2000/07/29 10:01:58 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.2 2000/07/29 10:01:58 mdw
- * Track change in primitive-element generation.
- *
- * 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"
/* --- 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);
}