Add test for copying uninitialized EVP_MD_CTX
authorTomas Mraz <tomas@openssl.org>
Tue, 23 Nov 2021 15:01:28 +0000 (16:01 +0100)
committerTomas Mraz <tomas@openssl.org>
Wed, 24 Nov 2021 17:42:27 +0000 (18:42 +0100)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17118)

test/evp_extra_test2.c

index 5be8bb5a404b5285602b57764fa07e57ac774b6e..b70c168d9db14b9d0db059b90c472ad2757b265f 100644 (file)
@@ -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;
 }