--- a/plugins/qca-ossl/qca-ossl.cpp	2021-09-14 08:41:31.000000000 -0400
+++ b/plugins/qca-ossl/qca-ossl.cpp	2021-11-11 14:46:54.000000000 -0500
@@ -2071,7 +2071,7 @@
             md = EVP_sha1();
         else if (alg == EMSA3_MD5)
             md = EVP_md5();
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
         else if (alg == EMSA3_MD2)
             md = EVP_md2();
 #endif
@@ -2098,7 +2098,7 @@
             md = EVP_sha1();
         else if (alg == EMSA3_MD5)
             md = EVP_md5();
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
         else if (alg == EMSA3_MD2)
             md = EVP_md2();
 #endif
@@ -3717,7 +3717,7 @@
         case NID_md5WithRSAEncryption:
             p.sigalgo = QCA::EMSA3_MD5;
             break;
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
         case NID_md2WithRSAEncryption:
             p.sigalgo = QCA::EMSA3_MD2;
             break;
@@ -4215,7 +4215,7 @@
         case NID_md5WithRSAEncryption:
             p.sigalgo = QCA::EMSA3_MD5;
             break;
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
         case NID_md2WithRSAEncryption:
             p.sigalgo = QCA::EMSA3_MD2;
             break;
@@ -4413,7 +4413,7 @@
         case NID_md5WithRSAEncryption:
             p.sigalgo = QCA::EMSA3_MD5;
             break;
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
         case NID_md2WithRSAEncryption:
             p.sigalgo = QCA::EMSA3_MD2;
             break;
@@ -6429,7 +6429,7 @@
     list += QStringLiteral("sha0");
 #endif
     list += QStringLiteral("ripemd160");
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
     list += QStringLiteral("md2");
 #endif
     list += QStringLiteral("md4");
@@ -6682,7 +6682,7 @@
         list += all_hash_types();
         list += all_mac_types();
         list += all_cipher_types();
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
         list += QStringLiteral("pbkdf1(md2)");
 #endif
         list += QStringLiteral("pbkdf1(sha1)");
@@ -6720,7 +6720,7 @@
 #endif
         else if (type == QLatin1String("ripemd160"))
             return new opensslHashContext(EVP_ripemd160(), this, type);
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
         else if (type == QLatin1String("md2"))
             return new opensslHashContext(EVP_md2(), this, type);
 #endif
@@ -6750,7 +6750,7 @@
 #endif
         else if (type == QLatin1String("pbkdf1(sha1)"))
             return new opensslPbkdf1Context(EVP_sha1(), this, type);
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
         else if (type == QLatin1String("pbkdf1(md2)"))
             return new opensslPbkdf1Context(EVP_md2(), this, type);
 #endif
