Skip to content

Commit

Permalink
Allow zero-length HKDF keys
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kaduk authored and tmshort committed Dec 11, 2020
1 parent 232c9a1 commit 93f2e10
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crypto/kdf/hkdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ static int pkey_hkdf_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
if (kctx->key != NULL)
OPENSSL_clear_free(kctx->key, kctx->key_len);

kctx->key = OPENSSL_memdup(p2, p1);
if (p1 == 0)
kctx->key = OPENSSL_zalloc(1);
else
kctx->key = OPENSSL_memdup(p2, p1);
if (kctx->key == NULL)
return 0;

Expand Down

0 comments on commit 93f2e10

Please sign in to comment.