Commit 297dcb966c for openssl.org

commit 297dcb966c120115ea1fcc369cf2c1b961493f4b
Author: Stas Mors <morstas99@mail.ru>
Date:   Wed Mar 11 15:33:49 2026 +0300

    Digests Algorithm find from name

    Add finding object and sn from EVP_MD::type_name(in the base case EVP_MD::type == 0 and seacrhing can failed)

    Reviewed-by: Simo Sorce <simo@redhat.com>
    Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
    (Merged from https://github.com/openssl/openssl/pull/30206)

diff --git a/crypto/asn1/x_algor.c b/crypto/asn1/x_algor.c
index 72b1fc8b18..5050adb8f1 100644
--- a/crypto/asn1/x_algor.c
+++ b/crypto/asn1/x_algor.c
@@ -89,8 +89,10 @@ int X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md)
 {
     int type = md->flags & EVP_MD_FLAG_DIGALGID_ABSENT ? V_ASN1_UNDEF
                                                        : V_ASN1_NULL;
+    int md_type = EVP_MD_type(md);

-    return X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_get_type(md)), type, NULL);
+    ASN1_OBJECT *obj = (md_type == NID_undef) ? OBJ_txt2obj(EVP_MD_get0_name(md), 0) : OBJ_nid2obj(md_type);
+    return X509_ALGOR_set0(alg, obj, type, NULL);
 }

 int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b)
diff --git a/crypto/cms/cms_lib.c b/crypto/cms/cms_lib.c
index e5fc67fb9d..82bf01df26 100644
--- a/crypto/cms/cms_lib.c
+++ b/crypto/cms/cms_lib.c
@@ -473,7 +473,7 @@ int ossl_cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
             return 0;
         }
         BIO_get_md_ctx(chain, &mtmp);
-        if (EVP_MD_CTX_get_type(mtmp) == nid
+        if (EVP_MD_CTX_get_type(mtmp) == nid || OBJ_sn2nid(EVP_MD_CTX_get0_name(mtmp)) == nid
             /*
              * Workaround for broken implementations that use signature
              * algorithm OID instead of digest.