Skip to content

Commit 93f2e10

Browse files
kaduktmshort
authored andcommitted
Allow zero-length HKDF keys
When making a copy to keep in the EVP_PKEY_CTX, allocate a single byte for the cached key instead of letting memdup return NULL and cause the call to fail. The length still gets set to zero properly, so we don't end up inspecting the allocated byte, but it's important to have a non-NULL pointer set.
1 parent 232c9a1 commit 93f2e10

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

crypto/kdf/hkdf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ static int pkey_hkdf_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
107107
if (kctx->key != NULL)
108108
OPENSSL_clear_free(kctx->key, kctx->key_len);
109109

110-
kctx->key = OPENSSL_memdup(p2, p1);
110+
if (p1 == 0)
111+
kctx->key = OPENSSL_zalloc(1);
112+
else
113+
kctx->key = OPENSSL_memdup(p2, p1);
111114
if (kctx->key == NULL)
112115
return 0;
113116

0 commit comments

Comments
 (0)