From: Mark Wooding Date: Wed, 23 Oct 2019 03:09:05 +0000 (+0100) Subject: pub/dh-kcdsa.c: Make the cleanup flow less crazy. X-Git-Tag: 2.6.0~39 X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/commitdiff_plain/9cbd8bb7d639df855832ee3e3facdeaa903696a8 pub/dh-kcdsa.c: Make the cleanup flow less crazy. I'm pretty sure I've fixed bugs in here. --- diff --git a/pub/dh-kcdsa.c b/pub/dh-kcdsa.c index 4de00c66..6bd3e19e 100644 --- a/pub/dh-kcdsa.c +++ b/pub/dh-kcdsa.c @@ -66,12 +66,12 @@ int dh_kcdsagen(dh_param *dp, unsigned ql, unsigned pl, rabin rb; int rc = PGEN_ABORT; int i; - mp *x; + mp *x = MP_NEW; /* --- First trick: find %$v$% --- */ pf.step = 2; - x = mprand(MP_NEW, pl - ql, r, 1); + x = mprand(x, pl - ql, r, 1); x = pgen("v", x, x, ev, ec, steps, pgen_filter, &pf, rabin_iters(pl - ql), pgen_test, &rb); @@ -82,16 +82,16 @@ int dh_kcdsagen(dh_param *dp, unsigned ql, unsigned pl, 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; + sp[1].add = MP_ONE; sp[1].mul = x; sp[1].f = PGENF_KEEP; x = MP_NEW; ss.step = MP_TWO; ss.v = sp; ss.n = N(sp); - x = mprand(MP_NEW, ql, r, 1); + x = mprand(x, 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[1].mul); + dp->p = sp[1].u.x; if (!dp->q) goto fail_1; - dp->p = sp[1].u.x; /* --- Third trick: find a generator --- */ @@ -104,16 +104,16 @@ int dh_kcdsagen(dh_param *dp, unsigned ql, unsigned pl, 0, prim_step, &i, 1, prim_test, &pc); mpmont_destroy(&pc.mm); if (!dp->g) - goto fail_2; + goto fail_1; rc = PGEN_DONE; goto done; /* --- Tidying up and going home --- */ -fail_2: - mp_drop(dp->p); fail_1: + mp_drop(dp->p); + mp_drop(dp->q); fail_0: done: mp_drop(x);