summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-06-26 08:57:17 +0000
committertb <>2023-06-26 08:57:17 +0000
commit36dc6e3bd638a341fcee604245bf23d1c02bfd13 (patch)
tree1f9aeffc6ddfee06361ae9af06c8aa5748ef2339 /src
parent1d25a3f2bf52b2b6953443bff609b553c386a202 (diff)
downloadopenbsd-36dc6e3bd638a341fcee604245bf23d1c02bfd13.tar.gz
openbsd-36dc6e3bd638a341fcee604245bf23d1c02bfd13.tar.bz2
openbsd-36dc6e3bd638a341fcee604245bf23d1c02bfd13.zip
Adjust EVP_PKEY_CTRL_HKDF_KEY to OpenSSL's semantics
For some reason there is no NULL check on setting the HKDF key for p2 like in the other cases in the switch, instead OpenSSL fail in memdup, nulling out the key but leaving he key_len at the old value. This looks accidental but our behavior makes some haproxy regress tests segfault. So mimic weird OpenSSL semantics but in addition set the key_len to 0. Reported by Ilya Shipitsin ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/kdf/hkdf_evp.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lib/libcrypto/kdf/hkdf_evp.c b/src/lib/libcrypto/kdf/hkdf_evp.c
index 992c66a14f..b33e2e0a26 100644
--- a/src/lib/libcrypto/kdf/hkdf_evp.c
+++ b/src/lib/libcrypto/kdf/hkdf_evp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hkdf_evp.c,v 1.19 2022/11/26 16:08:53 tb Exp $ */ 1/* $OpenBSD: hkdf_evp.c,v 1.20 2023/06/26 08:57:17 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2016-2018 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2016-2018 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -129,10 +129,17 @@ pkey_hkdf_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
129 return 1; 129 return 1;
130 130
131 case EVP_PKEY_CTRL_HKDF_KEY: 131 case EVP_PKEY_CTRL_HKDF_KEY:
132 if (p1 <= 0) 132 if (p1 < 0)
133 return 0; 133 return 0;
134 134
135 freezero(kctx->key, kctx->key_len); 135 freezero(kctx->key, kctx->key_len);
136 kctx->key = NULL;
137 kctx->key_len = 0;
138
139 /* Match OpenSSL's behavior. */
140 if (p1 == 0 || p2 == NULL)
141 return 0;
142
136 if ((kctx->key = malloc(p1)) == NULL) 143 if ((kctx->key = malloc(p1)) == NULL)
137 return 0; 144 return 0;
138 memcpy(kctx->key, p2, p1); 145 memcpy(kctx->key, p2, p1);