summaryrefslogtreecommitdiffstats
path: root/crypto/evp
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2021-11-23 15:52:04 +0100
committerTomas Mraz <tomas@openssl.org>2021-11-24 18:42:27 +0100
commit9ece8323ea2230092227bf20e5d93012d15d92e9 (patch)
tree5f78ae89ca9217e531fa71d65be1c7d61939f204 /crypto/evp
parent3607b8ad8ee1980a079e985333a196e0c79f8f00 (diff)
EVP_MD_CTX_copy_ex: Allow copying uninitialized digest contexts
Fixes #17117 Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17118)
Diffstat (limited to 'crypto/evp')
-rw-r--r--crypto/evp/digest.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index 0a133c5c15..7ebb2e3235 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -510,11 +510,20 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
{
unsigned char *tmp_buf;
- if (in == NULL || in->digest == NULL) {
- ERR_raise(ERR_LIB_EVP, EVP_R_INPUT_NOT_INITIALIZED);
+ if (in == NULL) {
+ ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
+ if (in->digest == NULL) {
+ /* copying uninitialized digest context */
+ EVP_MD_CTX_reset(out);
+ if (out->fetched_digest != NULL)
+ EVP_MD_free(out->fetched_digest);
+ *out = *in;
+ return 1;
+ }
+
if (in->digest->prov == NULL
|| (in->flags & EVP_MD_CTX_FLAG_NO_INIT) != 0)
goto legacy;