From: tb Date: Fri, 28 Jul 2023 09:30:22 +0000 (+0000) Subject: Pull up zeroing of out; drop unnecessary check X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f65b3322e6f2d4bc182f70121e77d79973d0f97d;p=openbsd Pull up zeroing of out; drop unnecessary check Move the zeroing of the output buffer a few lines up and remove an unnecessary check. requested/ok jsing --- diff --git a/lib/libcrypto/ecdh/ecdh.c b/lib/libcrypto/ecdh/ecdh.c index 5731f0ca3a3..08183364f91 100644 --- a/lib/libcrypto/ecdh/ecdh.c +++ b/lib/libcrypto/ecdh/ecdh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecdh.c,v 1.8 2023/07/28 09:29:24 tb Exp $ */ +/* $OpenBSD: ecdh.c,v 1.9 2023/07/28 09:30:22 tb Exp $ */ /* ==================================================================== * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. * @@ -246,20 +246,19 @@ ECDH_compute_key(void *out, size_t out_len, const EC_POINT *pub_key, if (!eckey->meth->compute_key(&secret, &secret_len, pub_key, eckey)) goto err; + memset(out, 0, out_len); if (KDF != NULL) { if (KDF(secret, secret_len, out, &out_len) == NULL) { ECerror(EC_R_KDF_FAILED); goto err; } } else { - memset(out, 0, out_len); if (out_len < secret_len) { /* The resulting key would be truncated. */ ECerror(EC_R_KEY_TRUNCATION); goto err; } - if (out_len > secret_len) - out_len = secret_len; + out_len = secret_len; memcpy(out, secret, out_len); }