The branch openssl-3.0 has been updated via 0eade1589543f4ce9e3dd72449fe03851cc48b6c (commit) via 11a044af6ed36f833e15b30ce742842318bc20cc (commit) from 90023b7e55b87f5b9a4f1b44f79f347cb71e257f (commit)
- Log ----------------------------------------------------------------- commit 0eade1589543f4ce9e3dd72449fe03851cc48b6c Author: Tomas Mraz <to...@openssl.org> Date: Tue Nov 23 16:01:28 2021 +0100 Add test for copying uninitialized EVP_MD_CTX Reviewed-by: Matt Caswell <m...@openssl.org> Reviewed-by: Paul Dale <pa...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17118) (cherry picked from commit 8c86529fe1b9ade0794c6f557ca8936f0c0de431) commit 11a044af6ed36f833e15b30ce742842318bc20cc Author: Tomas Mraz <to...@openssl.org> Date: Tue Nov 23 15:52:04 2021 +0100 EVP_MD_CTX_copy_ex: Allow copying uninitialized digest contexts Fixes #17117 Reviewed-by: Matt Caswell <m...@openssl.org> Reviewed-by: Paul Dale <pa...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17118) (cherry picked from commit 9ece8323ea2230092227bf20e5d93012d15d92e9) ----------------------------------------------------------------------- Summary of changes: crypto/evp/digest.c | 13 +++++++++++-- test/evp_extra_test2.c | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index a269bb8260..d3a28fa351 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -509,11 +509,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; diff --git a/test/evp_extra_test2.c b/test/evp_extra_test2.c index 5be8bb5a40..b70c168d9d 100644 --- a/test/evp_extra_test2.c +++ b/test/evp_extra_test2.c @@ -853,6 +853,22 @@ static int test_rsa_pss_sign(void) return ret; } +static int test_evp_md_ctx_copy(void) +{ + EVP_MD_CTX *mdctx = NULL; + EVP_MD_CTX *copyctx = NULL; + int ret; + + /* test copying freshly initialized context */ + ret = TEST_ptr(mdctx = EVP_MD_CTX_new()) + && TEST_ptr(copyctx = EVP_MD_CTX_new()) + && TEST_true(EVP_MD_CTX_copy_ex(copyctx, mdctx)); + + EVP_MD_CTX_free(mdctx); + EVP_MD_CTX_free(copyctx); + return ret; +} + int setup_tests(void) { if (!test_get_libctx(&mainctx, &nullprov, NULL, NULL, NULL)) { @@ -879,6 +895,7 @@ int setup_tests(void) #endif ADD_ALL_TESTS(test_PEM_read_bio_negative, OSSL_NELEM(keydata)); ADD_TEST(test_rsa_pss_sign); + ADD_TEST(test_evp_md_ctx_copy); return 1; }