Add test for resetting SM2 dist ID
authorTomas Mraz <tomas@openssl.org>
Wed, 6 Apr 2022 08:29:54 +0000 (10:29 +0200)
committerTomas Mraz <tomas@openssl.org>
Mon, 11 Apr 2022 09:46:05 +0000 (11:46 +0200)
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18052)

(cherry picked from commit 707d4e06eba71fb8a8b2faa77a2072511189544d)

test/evp_extra_test.c

index 113ec2bd66ad19c0ea6113567f07b6f55404b5b6..826e558cc0cd07453ef46a4163d7300a51ad3eff 100644 (file)
@@ -1963,6 +1963,24 @@ static int test_EVP_SM2(void)
     if (!TEST_int_gt(EVP_DigestVerifyFinal(md_ctx_verify, sig, sig_len), 0))
         goto done;
 
+    /*
+     * Try verify again with non-matching 0 length id but ensure that it can
+     * be set on the context and overrides the previous value.
+     */
+
+    if (!TEST_true(EVP_DigestVerifyInit(md_ctx_verify, NULL, check_md, NULL,
+                                        pkey)))
+        goto done;
+
+    if (!TEST_int_gt(EVP_PKEY_CTX_set1_id(sctx, NULL, 0), 0))
+        goto done;
+
+    if (!TEST_true(EVP_DigestVerifyUpdate(md_ctx_verify, kMsg, sizeof(kMsg))))
+        goto done;
+
+    if (!TEST_int_eq(EVP_DigestVerifyFinal(md_ctx_verify, sig, sig_len), 0))
+        goto done;
+
     /* now check encryption/decryption */
 
     gparams[0] = OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_DIGEST,