diff options
| author | tb <> | 2023-07-28 09:30:22 +0000 |
|---|---|---|
| committer | tb <> | 2023-07-28 09:30:22 +0000 |
| commit | 3a8fc985d98583b96821febed38c55c12c23ab01 (patch) | |
| tree | 02d1777a7e5226c2a51434aedcf38ff982b21fbe /src | |
| parent | 4d5b61b05eba83625a41168408b456851f77417a (diff) | |
| download | openbsd-3a8fc985d98583b96821febed38c55c12c23ab01.tar.gz openbsd-3a8fc985d98583b96821febed38c55c12c23ab01.tar.bz2 openbsd-3a8fc985d98583b96821febed38c55c12c23ab01.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/ecdh/ecdh.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/lib/libcrypto/ecdh/ecdh.c b/src/lib/libcrypto/ecdh/ecdh.c index 5731f0ca3a..08183364f9 100644 --- a/src/lib/libcrypto/ecdh/ecdh.c +++ b/src/lib/libcrypto/ecdh/ecdh.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ecdh.c,v 1.8 2023/07/28 09:29:24 tb Exp $ */ | 1 | /* $OpenBSD: ecdh.c,v 1.9 2023/07/28 09:30:22 tb Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
| 4 | * | 4 | * |
| @@ -246,20 +246,19 @@ ECDH_compute_key(void *out, size_t out_len, const EC_POINT *pub_key, | |||
| 246 | if (!eckey->meth->compute_key(&secret, &secret_len, pub_key, eckey)) | 246 | if (!eckey->meth->compute_key(&secret, &secret_len, pub_key, eckey)) |
| 247 | goto err; | 247 | goto err; |
| 248 | 248 | ||
| 249 | memset(out, 0, out_len); | ||
| 249 | if (KDF != NULL) { | 250 | if (KDF != NULL) { |
| 250 | if (KDF(secret, secret_len, out, &out_len) == NULL) { | 251 | if (KDF(secret, secret_len, out, &out_len) == NULL) { |
| 251 | ECerror(EC_R_KDF_FAILED); | 252 | ECerror(EC_R_KDF_FAILED); |
| 252 | goto err; | 253 | goto err; |
| 253 | } | 254 | } |
| 254 | } else { | 255 | } else { |
| 255 | memset(out, 0, out_len); | ||
| 256 | if (out_len < secret_len) { | 256 | if (out_len < secret_len) { |
| 257 | /* The resulting key would be truncated. */ | 257 | /* The resulting key would be truncated. */ |
| 258 | ECerror(EC_R_KEY_TRUNCATION); | 258 | ECerror(EC_R_KEY_TRUNCATION); |
| 259 | goto err; | 259 | goto err; |
| 260 | } | 260 | } |
| 261 | if (out_len > secret_len) | 261 | out_len = secret_len; |
| 262 | out_len = secret_len; | ||
| 263 | memcpy(out, secret, out_len); | 262 | memcpy(out, secret, out_len); |
| 264 | } | 263 | } |
| 265 | 264 | ||
