diff options
author | Paul Yang <yang.yang@baishancloud.com> | 2018-09-03 23:56:41 +0800 |
---|---|---|
committer | Paul Yang <yang.yang@baishancloud.com> | 2018-09-07 18:12:26 +0800 |
commit | 00902d9414b4c6e46f78d7a6b6c8edc4d313d4b7 (patch) | |
tree | 9297617a7f6eaa8ff50c63e021c02a1953483818 /crypto | |
parent | 5bd0abe7a2f76d8c80f566ae615c10113884d843 (diff) |
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 <tjh@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7113)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/evp/digest.c | 7 | ||||
-rw-r--r-- | crypto/evp/evp_lib.c | 7 |
2 files changed, 13 insertions, 1 deletions
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; |