summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2023-07-01 14:48:02 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2023-07-01 14:48:02 +0000
commitd912316699eb02f053a21e9d954f896d0d5a7a38 (patch)
tree01d91d56107d2274a3efbfdbb566ffae079919c8 /lib
parentf16eb02d40c6aec83f2b2f9bb48cf5081a7799ad (diff)
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 'lib')
-rw-r--r--lib/libcrypto/ecdh/ech_key.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/libcrypto/ecdh/ech_key.c b/lib/libcrypto/ecdh/ech_key.c
index 1dfb3c0fa90..b364b31c882 100644
--- a/lib/libcrypto/ecdh/ech_key.c
+++ b/lib/libcrypto/ecdh/ech_key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ech_key.c,v 1.20 2023/07/01 14:39:34 tb Exp $ */
+/* $OpenBSD: ech_key.c,v 1.21 2023/07/01 14:48:01 tb Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
@@ -98,8 +98,8 @@ ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
const BIGNUM *priv_key;
const EC_GROUP* group;
int ret = -1;
- size_t buflen, len;
unsigned char *buf = NULL;
+ int buflen, len;
if (outlen > INT_MAX) {
/* Sort of, anyway. */
@@ -156,9 +156,7 @@ ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
ECDHerror(ERR_R_MALLOC_FAILURE);
goto err;
}
-
- memset(buf, 0, buflen - len);
- if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) {
+ if (BN_bn2binpad(x, buf, buflen) != buflen) {
ECDHerror(ERR_R_BN_LIB);
goto err;
}