summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);