From 00902d9414b4c6e46f78d7a6b6c8edc4d313d4b7 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 3 Sep 2018 23:56:41 +0800 Subject: Introduce EVP_MD_CTX_set_pkey_ctx Thus users can use this function to set customized EVP_PKEY_CTX to EVP_MD_CTX structure. Reviewed-by: Tim Hudson Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/7113) --- crypto/evp/digest.c | 7 ++++++- crypto/evp/evp_lib.c | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'crypto') diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index c380dca0b5..8a2d162df1 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -32,7 +32,12 @@ int EVP_MD_CTX_reset(EVP_MD_CTX *ctx) && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) { OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size); } - EVP_PKEY_CTX_free(ctx->pctx); + /* + * pctx should be freed by the user of EVP_MD_CTX + * if EVP_MD_CTX_FLAG_NEGLECT_PCTX is set + */ + if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_NEGLECT_PCTX)) + EVP_PKEY_CTX_free(ctx->pctx); #ifndef OPENSSL_NO_ENGINE ENGINE_finish(ctx->engine); #endif diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c index 6c48199f83..4faaf694b4 100644 --- a/crypto/evp/evp_lib.c +++ b/crypto/evp/evp_lib.c @@ -460,6 +460,13 @@ EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx) return ctx->pctx; } +void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx) +{ + ctx->pctx = pctx; + /* make sure pctx is not freed when destroying EVP_MD_CTX */ + EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NEGLECT_PCTX); +} + void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx) { return ctx->md_data; -- cgit v1.2.3