summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-07-01 14:48:01 +0000
committertb <>2023-07-01 14:48:01 +0000
commit5855c97c92ffd9ede66d72d985e6008517f9b02c (patch)
treea3e8c65911fa61ce3960db681c2268d8bbcada60 /src
parentf7d55086ac67cf69e2a58cf90ad07e63006d9bec (diff)
downloadopenbsd-5855c97c92ffd9ede66d72d985e6008517f9b02c.tar.gz
openbsd-5855c97c92ffd9ede66d72d985e6008517f9b02c.tar.bz2
openbsd-5855c97c92ffd9ede66d72d985e6008517f9b02c.zip
Use BN_bn2binpad() instead of handrolling it
As ugly as the BN_bn2binpad() internals are, what it does is quite handy with all sorts of EC stuff. So use it here too and eliminate some ugly manual pointer zeroing and offsets. Also switch len and buflen from size_t to int to remove an iffy cast: both are set by functions that return a non-negative int. ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/ecdh/ech_key.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/lib/libcrypto/ecdh/ech_key.c b/src/lib/libcrypto/ecdh/ech_key.c
index 1dfb3c0fa9..b364b31c88 100644
--- a/src/lib/libcrypto/ecdh/ech_key.c
+++ b/src/lib/libcrypto/ecdh/ech_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ech_key.c,v 1.20 2023/07/01 14:39:34 tb Exp $ */ 1/* $OpenBSD: ech_key.c,v 1.21 2023/07/01 14:48:01 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -98,8 +98,8 @@ ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
98 const BIGNUM *priv_key; 98 const BIGNUM *priv_key;
99 const EC_GROUP* group; 99 const EC_GROUP* group;
100 int ret = -1; 100 int ret = -1;
101 size_t buflen, len;
102 unsigned char *buf = NULL; 101 unsigned char *buf = NULL;
102 int buflen, len;
103 103
104 if (outlen > INT_MAX) { 104 if (outlen > INT_MAX) {
105 /* Sort of, anyway. */ 105 /* Sort of, anyway. */
@@ -156,9 +156,7 @@ ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
156 ECDHerror(ERR_R_MALLOC_FAILURE); 156 ECDHerror(ERR_R_MALLOC_FAILURE);
157 goto err; 157 goto err;
158 } 158 }
159 159 if (BN_bn2binpad(x, buf, buflen) != buflen) {
160 memset(buf, 0, buflen - len);
161 if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) {
162 ECDHerror(ERR_R_BN_LIB); 160 ECDHerror(ERR_R_BN_LIB);
163 goto err; 161 goto err;
164 } 162 }