From 939ce713df2ac39346f8378deae1a915bf86b6e4 Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Fri, 4 Mar 2022 11:43:20 -0700 Subject: [PATCH] EVP_PKEY_derive: set internal DH key if needed --- wolfcrypt/src/evp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index 9c59a67e8..118426f84 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -1535,7 +1535,18 @@ int wolfSSL_EVP_PKEY_derive(WOLFSSL_EVP_PKEY_CTX *ctx, unsigned char *key, size_ #ifndef NO_DH case EVP_PKEY_DH: /* Use DH */ - if (!ctx->pkey->dh || !ctx->peerKey->dh || !ctx->peerKey->dh->pub_key) { + if (!ctx->pkey->dh || !ctx->peerKey->dh) { + return WOLFSSL_FAILURE; + } + /* set internal peer key if not done */ + if (!ctx->peerKey->dh->inSet) { + if (SetDhInternal(ctx->peerKey->dh) != WOLFSSL_SUCCESS) { + WOLFSSL_MSG("SetDhInternal failed"); + return WOLFSSL_FAILURE; + } + } + if (!ctx->peerKey->dh->pub_key) { + WOLFSSL_MSG("SetDhInternal failed, pub_key is NULL"); return WOLFSSL_FAILURE; } if ((len = wolfSSL_DH_size(ctx->pkey->dh)) <= 0) {