From 705ecf30979cfc14f2d8ae5c8fba9a33e26ff970 Mon Sep 17 00:00:00 2001 Message-Id: <705ecf30979cfc14f2d8ae5c8fba9a33e26ff970.1715392587.git.mdw@distorted.org.uk> From: Mark Wooding Date: Wed, 19 Apr 2017 21:02:24 +0100 Subject: [PATCH] server/keyexch.c: Don't copy group elements when registering a challenge. Organization: Straylight/Edgeware From: Mark Wooding Instead, just remember that ownership has been transferred. For `c', we don't use the original variable any more, so we can just mark it null; but `r' gets reused, so allocate a fresh place for it. This is the only use of `G_COPY' in the program. --- server/keyexch.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/keyexch.c b/server/keyexch.c index 7b4eb0d8..0c1ed829 100644 --- a/server/keyexch.c +++ b/server/keyexch.c @@ -427,6 +427,8 @@ static void kxc_stoptimer(kxchal *kxc) * Returns: A pointer to the challenge block. * * Use: Returns a pointer to a new challenge block to fill in. + * In particular, the @c@ and @r@ members are left + * uninitialized. */ static kxchal *kxc_new(keyexch *kx) @@ -446,8 +448,6 @@ static kxchal *kxc_new(keyexch *kx) /* --- Fill in the new structure --- */ kxc = CREATE(kxchal); - kxc->c = G_CREATE(kx->kpriv->g); - kxc->r = G_CREATE(kx->kpriv->g); kxc->ks = 0; kxc->kx = kx; kxc->f = 0; @@ -693,8 +693,8 @@ static kxchal *respond(keyexch *kx, unsigned msg, buf *b) /* --- Fill in a new challenge block --- */ kxc = kxc_new(kx); - G_COPY(g, kxc->c, c); - G_COPY(g, kxc->r, r); + kxc->c = c; c = 0; + kxc->r = r; r = G_CREATE(g); h = GH_INIT(algs->h); HASH_STRING(h, "tripe-check-hash"); GH_HASH(h, ck, ixsz); @@ -711,7 +711,7 @@ static kxchal *respond(keyexch *kx, unsigned msg, buf *b) /* --- Work out the shared key --- */ - G_EXP(g, r, c, kx->alpha); + G_EXP(g, r, kxc->c, kx->alpha); IF_TRACING(T_KEYEXCH, IF_TRACING(T_CRYPTO, { trace(T_CRYPTO, "crypto: shared secret = %s", gestr(g, r)); })) @@ -754,7 +754,7 @@ static kxchal *respond(keyexch *kx, unsigned msg, buf *b) kxc->ks = ks_gen(BBASE(&bb), x, y, z, kx->p); } - G_DESTROY(g, c); + if (c) G_DESTROY(g, c); G_DESTROY(g, cc); G_DESTROY(g, r); mp_drop(cv); @@ -764,7 +764,7 @@ badcheck: a_warn("KX", "?PEER", kx->p, "bad-expected-reply-log", A_END); goto bad; bad: - G_DESTROY(g, c); + if (c) G_DESTROY(g, c); G_DESTROY(g, cc); G_DESTROY(g, r); mp_drop(cv); -- [mdw]