summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Samir <[email protected]>2025-03-03 17:16:18 +0200
committerAhmad Samir <[email protected]>2025-04-02 03:11:58 +0200
commita3813abd407c31da715b434805d780424c589949 (patch)
tree533d863d94d6285365fad12622b1b14cf16340e8
parentc6c2a0bf3799c9851551bc9e1bd0919dbc64924c (diff)
QCryptographicHash: remove QT_CRYPTOGRAPHICHASH_ONLY_SHA1
It was added in 44cb71d6fdb0b7285d4ef74a1ef778323aa9e5ee to reduce the size of the bootstrap lib. Since commit c7f64d84fbd9b5b3cac41c1d81dc4d0479fc3fa1 removed QCryptographicHash from the bootstrap lib, the macro is now redundant (unless it's used by QtLite). Change-Id: I5459a52507bc9e0a7b982b4382211be9a23c4ad9 Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r--src/corelib/tools/qcryptographichash.cpp41
-rw-r--r--src/corelib/tools/qcryptographichash.h4
-rw-r--r--src/network/ssl/qpassworddigestor.cpp2
-rw-r--r--src/plugins/tls/openssl/qdtls_openssl_p.h4
-rw-r--r--src/plugins/tls/shared/qdtls_base_p.h4
-rw-r--r--src/plugins/tls/shared/qtlskey_generic.cpp2
-rw-r--r--tests/auto/network/ssl/qdtls/tst_qdtls.cpp4
-rw-r--r--tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp4
-rw-r--r--tests/auto/network/ssl/qpassworddigestor/tst_qpassworddigestor.cpp2
9 files changed, 0 insertions, 67 deletions
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp
index 5e9be231995..68ac08ad39e 100644
--- a/src/corelib/tools/qcryptographichash.cpp
+++ b/src/corelib/tools/qcryptographichash.cpp
@@ -20,9 +20,7 @@
// Header from rfc6234
#include "../../3rdparty/rfc6234/sha.h"
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
#if !QT_CONFIG(openssl_hash)
-// qdoc and qmake only need SHA-1
#include "../../3rdparty/md5/md5.h"
#include "../../3rdparty/md5/md5.cpp"
#include "../../3rdparty/md4/md4.h"
@@ -115,7 +113,6 @@ QT_WARNING_DISABLE_MSVC(4505)
#include "../../3rdparty/blake2/src/blake2s-ref.c"
QT_WARNING_POP
#endif
-#endif // QT_CRYPTOGRAPHICHASH_ONLY_SHA1
#if !defined(QT_BOOTSTRAPPED) && QT_CONFIG(openssl_hash)
#define USING_OPENSSL30
@@ -133,7 +130,6 @@ static constexpr int hashLengthInternal(QCryptographicHash::Algorithm method) no
return Size \
/*end*/
CASE(Sha1, 20);
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
CASE(Md4, 16);
CASE(Md5, 16);
CASE(Sha224, SHA224HashSize);
@@ -161,7 +157,6 @@ static constexpr int hashLengthInternal(QCryptographicHash::Algorithm method) no
case QCryptographicHash::Keccak_512:
case QCryptographicHash::Blake2b_512:
return 512 / 8;
-#endif
#undef CASE
case QCryptographicHash::NumAlgorithms: ;
// fall through
@@ -304,7 +299,6 @@ public:
void finalizeUnchecked(QCryptographicHash::Algorithm method, HashResult &result) noexcept;
Sha1State sha1Context;
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
#ifdef USING_OPENSSL30
EVP evp;
#else
@@ -321,7 +315,6 @@ public:
static void sha3Finish(SHA3Context &ctx, HashResult &result, Sha3Variant sha3Variant);
blake2b_state blake2bContext;
blake2s_state blake2sContext;
-#endif
} state;
// protects result in finalize()
QBasicMutex finalizeMutex;
@@ -330,7 +323,6 @@ public:
const QCryptographicHash::Algorithm method;
};
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
void QCryptographicHashPrivate::State::sha3Finish(SHA3Context &ctx, HashResult &result,
Sha3Variant sha3Variant)
{
@@ -366,7 +358,6 @@ void QCryptographicHashPrivate::State::sha3Finish(SHA3Context &ctx, HashResult &
sha3Final(&ctx, result.data());
}
-#endif
/*!
\class QCryptographicHash
@@ -574,12 +565,6 @@ QCryptographicHashPrivate::State::State(QCryptographicHash::Algorithm method)
case QCryptographicHash::Sha1:
new (&sha1Context) Sha1State;
break;
-#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
- default:
- Q_ASSERT_X(false, "QCryptographicHash", "Method not compiled in");
- Q_UNREACHABLE();
- break;
-#else
case QCryptographicHash::Md4:
new (&md4Context) md4_context;
break;
@@ -620,7 +605,6 @@ QCryptographicHashPrivate::State::State(QCryptographicHash::Algorithm method)
case QCryptographicHash::Blake2s_256:
new (&blake2sContext) blake2s_state;
break;
-#endif
case QCryptographicHash::NumAlgorithms:
Q_UNREACHABLE();
}
@@ -681,12 +665,6 @@ void QCryptographicHashPrivate::State::reset(QCryptographicHash::Algorithm metho
case QCryptographicHash::Sha1:
sha1InitState(&sha1Context);
break;
-#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
- default:
- Q_ASSERT_X(false, "QCryptographicHash", "Method not compiled in");
- Q_UNREACHABLE();
- break;
-#else
case QCryptographicHash::Md4:
md4_init(&md4Context);
break;
@@ -727,7 +705,6 @@ void QCryptographicHashPrivate::State::reset(QCryptographicHash::Algorithm metho
case QCryptographicHash::Blake2s_256:
blake2s_init(&blake2sContext, hashLengthInternal(method));
break;
-#endif
case QCryptographicHash::NumAlgorithms:
Q_UNREACHABLE();
}
@@ -816,12 +793,6 @@ void QCryptographicHashPrivate::State::addData(QCryptographicHash::Algorithm met
case QCryptographicHash::Sha1:
sha1Update(&sha1Context, (const unsigned char *)data, length);
break;
-#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
- default:
- Q_ASSERT_X(false, "QCryptographicHash", "Method not compiled in");
- Q_UNREACHABLE();
- break;
-#else
case QCryptographicHash::Md4:
md4_update(&md4Context, (const unsigned char *)data, length);
break;
@@ -862,7 +833,6 @@ void QCryptographicHashPrivate::State::addData(QCryptographicHash::Algorithm met
case QCryptographicHash::Blake2s_256:
blake2s_update(&blake2sContext, reinterpret_cast<const uint8_t *>(data), length);
break;
-#endif
case QCryptographicHash::NumAlgorithms:
Q_UNREACHABLE();
}
@@ -1001,12 +971,6 @@ void QCryptographicHashPrivate::State::finalizeUnchecked(QCryptographicHash::Alg
sha1ToHash(&copy, result.data());
break;
}
-#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
- default:
- Q_ASSERT_X(false, "QCryptographicHash", "Method not compiled in");
- Q_UNREACHABLE();
- break;
-#else
case QCryptographicHash::Md4: {
md4_context copy = md4Context;
md4_final(&copy, result.data());
@@ -1071,7 +1035,6 @@ void QCryptographicHashPrivate::State::finalizeUnchecked(QCryptographicHash::Alg
blake2s_final(&copy, result.data(), length);
break;
}
-#endif
case QCryptographicHash::NumAlgorithms:
Q_UNREACHABLE();
}
@@ -1177,7 +1140,6 @@ bool QCryptographicHashPrivate::supportsAlgorithm(QCryptographicHash::Algorithm
#else
switch (method) {
case QCryptographicHash::Sha1:
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
case QCryptographicHash::Md4:
case QCryptographicHash::Md5:
case QCryptographicHash::Sha224:
@@ -1200,7 +1162,6 @@ bool QCryptographicHashPrivate::supportsAlgorithm(QCryptographicHash::Algorithm
case QCryptographicHash::Blake2s_160:
case QCryptographicHash::Blake2s_224:
case QCryptographicHash::Blake2s_256:
-#endif
return true;
case QCryptographicHash::NumAlgorithms: ;
};
@@ -1213,7 +1174,6 @@ static constexpr int qt_hash_block_size(QCryptographicHash::Algorithm method)
switch (method) {
case QCryptographicHash::Sha1:
return SHA1_Message_Block_Size;
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
case QCryptographicHash::Md4:
return 64;
case QCryptographicHash::Md5:
@@ -1248,7 +1208,6 @@ static constexpr int qt_hash_block_size(QCryptographicHash::Algorithm method)
case QCryptographicHash::Blake2s_224:
case QCryptographicHash::Blake2s_256:
return BLAKE2S_BLOCKBYTES;
-#endif // QT_CRYPTOGRAPHICHASH_ONLY_SHA1
case QCryptographicHash::NumAlgorithms:
#if !defined(Q_CC_GNU_ONLY) || Q_CC_GNU >= 900
// GCC 8 has trouble with Q_UNREACHABLE() in constexpr functions
diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h
index 8c4f70457f8..180be4ab1fd 100644
--- a/src/corelib/tools/qcryptographichash.h
+++ b/src/corelib/tools/qcryptographichash.h
@@ -21,12 +21,9 @@ class Q_CORE_EXPORT QCryptographicHash
Q_GADGET
public:
enum Algorithm {
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
Md4,
Md5,
-#endif
Sha1 = 2,
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
Sha224,
Sha256,
Sha384,
@@ -60,7 +57,6 @@ public:
Blake2s_160,
Blake2s_224,
Blake2s_256,
-#endif
NumAlgorithms
};
Q_ENUM(Algorithm)
diff --git a/src/network/ssl/qpassworddigestor.cpp b/src/network/ssl/qpassworddigestor.cpp
index 94de14abd42..184c3107549 100644
--- a/src/network/ssl/qpassworddigestor.cpp
+++ b/src/network/ssl/qpassworddigestor.cpp
@@ -61,9 +61,7 @@ Q_NETWORK_EXPORT QByteArray deriveKeyPbkdf1(QCryptographicHash::Algorithm algori
// https://tools.ietf.org/html/rfc8018#section-5.1
if (algorithm != QCryptographicHash::Sha1
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
&& algorithm != QCryptographicHash::Md5
-#endif
) {
qWarning("The only supported algorithms for pbkdf1 are SHA-1 and MD5!");
return QByteArray();
diff --git a/src/plugins/tls/openssl/qdtls_openssl_p.h b/src/plugins/tls/openssl/qdtls_openssl_p.h
index 0b6d141d0f9..c7e698a7687 100644
--- a/src/plugins/tls/openssl/qdtls_openssl_p.h
+++ b/src/plugins/tls/openssl/qdtls_openssl_p.h
@@ -83,11 +83,7 @@ public:
QDtlsPrivateOpenSSL *dtlsPrivate = nullptr;
QByteArray secret;
-#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
- QCryptographicHash::Algorithm hashAlgorithm = QCryptographicHash::Sha1;
-#else
QCryptographicHash::Algorithm hashAlgorithm = QCryptographicHash::Sha256;
-#endif
private:
diff --git a/src/plugins/tls/shared/qdtls_base_p.h b/src/plugins/tls/shared/qdtls_base_p.h
index a8faad6a268..d21e81c7a16 100644
--- a/src/plugins/tls/shared/qdtls_base_p.h
+++ b/src/plugins/tls/shared/qdtls_base_p.h
@@ -68,11 +68,7 @@ public:
QString peerVfyName;
QByteArray secret;
-#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
- QCryptographicHash::Algorithm hashAlgorithm = QCryptographicHash::Sha1;
-#else
QCryptographicHash::Algorithm hashAlgorithm = QCryptographicHash::Sha256;
-#endif
};
QT_END_NAMESPACE
diff --git a/src/plugins/tls/shared/qtlskey_generic.cpp b/src/plugins/tls/shared/qtlskey_generic.cpp
index 4645ef47036..5813c32e7f8 100644
--- a/src/plugins/tls/shared/qtlskey_generic.cpp
+++ b/src/plugins/tls/shared/qtlskey_generic.cpp
@@ -277,13 +277,11 @@ EncryptionData readPbes2(const QList<QAsn1Element> &element, const QByteArray &p
// Maps OIDs to the hash function it specifies
const QMap<QByteArray, QCryptographicHash::Algorithm> pbes1OidHashFunctionMap {
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
// PKCS5
//{PKCS5_MD2_DES_CBC_OID, QCryptographicHash::Md2}, No MD2
//{PKCS5_MD2_RC2_CBC_OID, QCryptographicHash::Md2},
{PKCS5_MD5_DES_CBC_OID, QCryptographicHash::Md5},
{PKCS5_MD5_RC2_CBC_OID, QCryptographicHash::Md5},
-#endif
{PKCS5_SHA1_DES_CBC_OID, QCryptographicHash::Sha1},
{PKCS5_SHA1_RC2_CBC_OID, QCryptographicHash::Sha1},
// PKCS12 (unimplemented)
diff --git a/tests/auto/network/ssl/qdtls/tst_qdtls.cpp b/tests/auto/network/ssl/qdtls/tst_qdtls.cpp
index 372ee3a1810..28240630ae8 100644
--- a/tests/auto/network/ssl/qdtls/tst_qdtls.cpp
+++ b/tests/auto/network/ssl/qdtls/tst_qdtls.cpp
@@ -232,11 +232,7 @@ void tst_QDtls::construction()
const auto params = dtls.cookieGeneratorParameters();
QVERIFY(params.secret.size() > 0);
-#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
- QCOMPARE(params.hash, QCryptographicHash::Sha1);
-#else
QCOMPARE(params.hash, QCryptographicHash::Sha256);
-#endif
QCOMPARE(dtls.dtlsConfiguration(), QSslConfiguration::defaultDtlsConfiguration());
diff --git a/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp b/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp
index 167a1961045..e99d7645ab7 100644
--- a/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp
+++ b/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp
@@ -85,11 +85,7 @@ private:
HandshakePtr dtls;
const QCryptographicHash::Algorithm defaultHash =
-#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
- QCryptographicHash::Sha1;
-#else
QCryptographicHash::Sha256;
-#endif
using CookieParams = QDtlsClientVerifier::GeneratorParameters;
diff --git a/tests/auto/network/ssl/qpassworddigestor/tst_qpassworddigestor.cpp b/tests/auto/network/ssl/qpassworddigestor/tst_qpassworddigestor.cpp
index 1876c955af3..77b5351f3ca 100644
--- a/tests/auto/network/ssl/qpassworddigestor/tst_qpassworddigestor.cpp
+++ b/tests/auto/network/ssl/qpassworddigestor/tst_qpassworddigestor.cpp
@@ -23,12 +23,10 @@ void tst_QPasswordDigestor::inputSanityChecks()
{
const QByteArray pass("password");
const QByteArray salt("saltsalt");
-#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
//1. PBKDF1 supports only SHA1 and (if not disabled in Qt) MD5 algorithms.
QTest::ignoreMessage(QtWarningMsg, "The only supported algorithms for pbkdf1 are SHA-1 and MD5!");
auto derivedKey = QPasswordDigestor::deriveKeyPbkdf1(QCryptographicHash::Sha224, pass, salt, 2, 48);
QCOMPARE(derivedKey, QByteArray());
-#endif // QT_CRYPTOGRAPHICHASH_ONLY_SHA1
// 2. Salt size must be == 8:
QTest::ignoreMessage(QtWarningMsg, "The salt must be 8 bytes long!");