Raise error when invalid digest used with SM2
authorTomas Mraz <tomas@openssl.org>
Thu, 14 Oct 2021 09:02:36 +0000 (11:02 +0200)
committerTomas Mraz <tomas@openssl.org>
Fri, 15 Oct 2021 12:37:21 +0000 (14:37 +0200)
Otherwise commands like openssl req -newkey sm2 fail silently without
reporting any error unless -sm3 option is added.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16833)

providers/implementations/signature/sm2_sig.c

index 719e7a2eb26e2e8d4dd7abcc85be760f6f921fce..10a9496904c7ce4750099d7bfb82869e8b3a5e72 100644 (file)
@@ -94,9 +94,13 @@ static int sm2sig_set_mdname(PROV_SM2_CTX *psm2ctx, const char *mdname)
     if (psm2ctx->md == NULL) /* We need an SM3 md to compare with */
         psm2ctx->md = EVP_MD_fetch(psm2ctx->libctx, psm2ctx->mdname,
                                    psm2ctx->propq);
-    if (psm2ctx->md == NULL
-        || strlen(mdname) >= sizeof(psm2ctx->mdname)
+    if (psm2ctx->md == NULL)
+        return 0;
+
+    if (strlen(mdname) >= sizeof(psm2ctx->mdname)
         || !EVP_MD_is_a(psm2ctx->md, mdname)) {
+        ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, "digest=%s",
+                       mdname);
         return 0;
     }