X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/f621db36df9ae47441e7c515bca8518cc15f456b..20fa0f6976d598481208c0583d72b2ccef637be9:/dh-gen.c diff --git a/dh-gen.c b/dh-gen.c index 1a7ebc6..a1b61a1 100644 --- a/dh-gen.c +++ b/dh-gen.c @@ -1,13 +1,13 @@ /* -*-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. * @@ -15,31 +15,22 @@ * 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 + #include "dh.h" #include "grand.h" #include "mp.h" @@ -82,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); }