summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ecdh/ecdh.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/lib/libcrypto/ecdh/ecdh.c b/src/lib/libcrypto/ecdh/ecdh.c
index 034bd84a49..5731f0ca3a 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.7 2023/07/28 09:28:37 tb Exp $ */ 1/* $OpenBSD: ecdh.c,v 1.8 2023/07/28 09:29:24 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -155,7 +155,7 @@ ecdh_compute_key(unsigned char **out, size_t *out_len, const EC_POINT *pub_key,
155 const EC_GROUP *group; 155 const EC_GROUP *group;
156 EC_POINT *point = NULL; 156 EC_POINT *point = NULL;
157 unsigned char *buf = NULL; 157 unsigned char *buf = NULL;
158 int buflen; 158 int buf_len = 0;
159 int ret = 0; 159 int ret = 0;
160 160
161 *out = NULL; 161 *out = NULL;
@@ -195,22 +195,23 @@ ecdh_compute_key(unsigned char **out, size_t *out_len, const EC_POINT *pub_key,
195 goto err; 195 goto err;
196 } 196 }
197 197
198 if ((buflen = ECDH_size(ecdh)) < BN_num_bytes(x)) { 198 if ((buf_len = ECDH_size(ecdh)) < BN_num_bytes(x)) {
199 ECerror(ERR_R_INTERNAL_ERROR); 199 ECerror(ERR_R_INTERNAL_ERROR);
200 goto err; 200 goto err;
201 } 201 }
202 if ((buf = malloc(buflen)) == NULL) { 202 if ((buf = calloc(1, buf_len)) == NULL) {
203 ECerror(ERR_R_MALLOC_FAILURE); 203 ECerror(ERR_R_MALLOC_FAILURE);
204 goto err; 204 goto err;
205 } 205 }
206 if (BN_bn2binpad(x, buf, buflen) != buflen) { 206 if (BN_bn2binpad(x, buf, buf_len) != buf_len) {
207 ECerror(ERR_R_BN_LIB); 207 ECerror(ERR_R_BN_LIB);
208 goto err; 208 goto err;
209 } 209 }
210 210
211 *out = buf; 211 *out = buf;
212 *out_len = buflen; 212 *out_len = buf_len;
213 buf = NULL; 213 buf = NULL;
214 buf_len = 0;
214 215
215 ret = 1; 216 ret = 1;
216 217
@@ -218,7 +219,7 @@ ecdh_compute_key(unsigned char **out, size_t *out_len, const EC_POINT *pub_key,
218 EC_POINT_free(point); 219 EC_POINT_free(point);
219 BN_CTX_end(ctx); 220 BN_CTX_end(ctx);
220 BN_CTX_free(ctx); 221 BN_CTX_free(ctx);
221 free(buf); 222 freezero(buf, buf_len);
222 223
223 return ret; 224 return ret;
224} 225}