X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/b817bfc642225b8c3c0b6a7e42d1fb949b61a606..e564e3f84ad0ea42b78559c0bfe304893fd5e76b:/dh-gen.c diff --git a/dh-gen.c b/dh-gen.c index 6e77ea7..a1b61a1 100644 --- a/dh-gen.c +++ b/dh-gen.c @@ -7,7 +7,7 @@ * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,12 +15,12 @@ * 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, @@ -29,6 +29,8 @@ /*----- Header files ------------------------------------------------------*/ +#include + #include "dh.h" #include "grand.h" #include "mp.h" @@ -71,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); }