summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2019-03-29 16:28:07 +0000
committerMatt Caswell <matt@openssl.org>2019-04-03 15:44:36 +0100
commitb7c913c820a80f8534ead1dc49b569280fcb1f9a (patch)
tree2ceb2bf11055045123b5180f17e28b55585c72a1 /crypto
parente4e91084d6b7acbe55139141f553b361871ec768 (diff)
Ensure EVP_MD_CTX_md returns the EVP_MD originally used
Fixes #8613 Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/8614)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/evp/digest.c4
-rw-r--r--crypto/evp/evp_lib.c4
-rw-r--r--crypto/evp/evp_locl.h1
3 files changed, 7 insertions, 2 deletions
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index 7b4972553b..89f8e54a91 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -83,6 +83,7 @@ void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
EVP_MD_meth_free(ctx->fetched_digest);
ctx->fetched_digest = NULL;
ctx->digest = NULL;
+ ctx->reqdigest = NULL;
OPENSSL_free(ctx);
return;
@@ -106,6 +107,9 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);
+ if (type != NULL)
+ ctx->reqdigest = type;
+
/* TODO(3.0): Legacy work around code below. Remove this */
#ifndef OPENSSL_NO_ENGINE
/*
diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c
index 219ae532d1..f99e905e42 100644
--- a/crypto/evp/evp_lib.c
+++ b/crypto/evp/evp_lib.c
@@ -479,9 +479,9 @@ int (*EVP_MD_meth_get_ctrl(const EVP_MD *md))(EVP_MD_CTX *ctx, int cmd,
const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
{
- if (!ctx)
+ if (ctx == NULL)
return NULL;
- return ctx->digest;
+ return ctx->reqdigest;
}
EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)
diff --git a/crypto/evp/evp_locl.h b/crypto/evp/evp_locl.h
index 936824a851..2453effe1d 100644
--- a/crypto/evp/evp_locl.h
+++ b/crypto/evp/evp_locl.h
@@ -10,6 +10,7 @@
/* EVP_MD_CTX related stuff */
struct evp_md_ctx_st {
+ const EVP_MD *reqdigest; /* The original requested digest */
const EVP_MD *digest;
ENGINE *engine; /* functional reference if 'digest' is
* ENGINE-provided */