[openssl] master update

tomas at openssl.org tomas at openssl.org
Wed Nov 24 17:43:04 UTC 2021


The branch master has been updated
       via  8c86529fe1b9ade0794c6f557ca8936f0c0de431 (commit)
       via  9ece8323ea2230092227bf20e5d93012d15d92e9 (commit)
      from  3607b8ad8ee1980a079e985333a196e0c79f8f00 (commit)


- Log -----------------------------------------------------------------
commit 8c86529fe1b9ade0794c6f557ca8936f0c0de431
Author: Tomas Mraz <tomas at openssl.org>
Date:   Tue Nov 23 16:01:28 2021 +0100

    Add test for copying uninitialized EVP_MD_CTX
    
    Reviewed-by: Matt Caswell <matt at openssl.org>
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/17118)

commit 9ece8323ea2230092227bf20e5d93012d15d92e9
Author: Tomas Mraz <tomas at 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 <matt at openssl.org>
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/17118)

-----------------------------------------------------------------------

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 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;
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;
 }
 


More information about the openssl-commits mailing list