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
commite31da3c8eee0fdd1dcf6c0a9c3e447aba90a70e3 (patch)
treea3e8c65911fa61ce3960db681c2268d8bbcada60 /src
parent0b62628544207292086b9e49e37fcd12d51198dd (diff)
downloadopenbsd-e31da3c8eee0fdd1dcf6c0a9c3e447aba90a70e3.tar.gz
openbsd-e31da3c8eee0fdd1dcf6c0a9c3e447aba90a70e3.tar.bz2
openbsd-e31da3c8eee0fdd1dcf6c0a9c3e447aba90a70e3.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 }