diff --git a/plugins/qca-ossl/qca-ossl.cpp b/plugins/qca-ossl/qca-ossl.cpp
index 11ecdc9d2c34f639a8515ac3fe7a12400590ac29..59e2135209b481ba60ebb32b6cb7f2af33d42188 100644
--- a/plugins/qca-ossl/qca-ossl.cpp
+++ b/plugins/qca-ossl/qca-ossl.cpp
@@ -2102,7 +2102,7 @@ public:
 			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
@@ -2130,7 +2130,7 @@ public:
 			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
@@ -3848,7 +3848,7 @@ public:
 		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;
@@ -4351,7 +4351,7 @@ public:
 		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;
@@ -4548,7 +4548,7 @@ public:
 		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;
@@ -7176,7 +7176,7 @@ static QStringList all_hash_types()
 	list += "sha0";
 #endif
 	list += "ripemd160";
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
 	list += "md2";
 #endif
 	list += "md4";
@@ -7411,7 +7411,7 @@ public:
 		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 += "pbkdf1(md2)";
 #endif
 		list += "pbkdf1(sha1)";
@@ -7451,7 +7451,7 @@ public:
 #endif
 		else if ( type == "ripemd160" )
 			return new opensslHashContext( EVP_ripemd160(), this, type);
-#ifdef HAVE_OPENSSL_MD2
+#if defined(HAVE_OPENSSL_MD2) && !defined(OPENSSL_NO_MD2)
 		else if ( type == "md2" )
 			return new opensslHashContext( EVP_md2(), this, type);
 #endif
@@ -7483,7 +7483,7 @@ public:
 */
 		else if ( type == "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 == "pbkdf1(md2)" )
 			return new opensslPbkdf1Context( EVP_md2(), this, type );
 #endif
