X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/4e67e30be6dbcc7d4f23be754b67bf7c6a0ade92..0f9bd85aa42c06b55d7a4e1693981233d95c62ff:/dh-kcdsa.c diff --git a/dh-kcdsa.c b/dh-kcdsa.c index d92148b..b503a5b 100644 --- a/dh-kcdsa.c +++ b/dh-kcdsa.c @@ -7,7 +7,7 @@ * (c) 2006 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, @@ -73,25 +73,25 @@ int dh_kcdsagen(dh_param *dp, unsigned ql, unsigned pl, /* --- First trick: find %$q$% --- */ pf.step = 2; - x = mprand(MP_NEW, ql, r, 1); - dp->q = pgen("q", MP_NEW, x, ev, ec, - steps, pgen_filter, &pf, - rabin_iters(ql), pgen_test, &rb); - if (!dp->q) + x = mprand(MP_NEW, pl - ql, r, 1); + x = pgen("v", x, x, ev, ec, + steps, pgen_filter, &pf, + rabin_iters(pl - ql), pgen_test, &rb); + if (!x) goto fail_0; /* --- Second trick: find %$p$% and %$v$% --- */ - x = mp_lsl(x, dp->q, 1); + x = mp_lsl(x, x, 1); sp[0].add = MP_ZERO; sp[0].mul = MP_ONE; sp[0].f = 0; sp[1].add = MP_ONE; sp[1].mul = x; sp[1].f = PGENF_KEEP; ss.step = MP_TWO; ss.v = sp; ss.n = N(sp); - x = mprand(MP_NEW, pl - ql, r, 1); - x = pgen("p", x, x, ev, ec, - steps, pgen_simulstep, &ss, - rabin_iters(pl - ql), pgen_simultest, &ss); + x = mprand(MP_NEW, ql, r, 1); + dp->q = pgen("p", MP_NEW, x, ev, ec, + steps, pgen_simulstep, &ss, + rabin_iters(ql), pgen_simultest, &ss); mp_drop(sp[0].mul); - if (!x) + if (!dp->q) goto fail_1; dp->p = sp[1].u.x; @@ -116,7 +116,6 @@ int dh_kcdsagen(dh_param *dp, unsigned ql, unsigned pl, fail_2: mp_drop(dp->p); fail_1: - mp_drop(dp->q); fail_0: done: mp_drop(x);