Fix QCH:supportsAlgorithm() result for unsupported hashes in OpenSSL

OpenSSL doesn't support some Blake2s and Blake2b hashes and querying
these would automatically report that they are unsupported, while we are
actually using non-OpenSSL implementataion for these and therefore they
are always supported.

Change-Id: I300694459891c3103502705d6c8271caa47d8d01
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 86a517ac786c90b9ce8deb502c413287e31058c2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Jan Grulich 2023-02-15 15:40:25 +01:00 committed by Qt Cherry-pick Bot
parent 54aedff72f
commit a44e0ca93c

View File

@ -222,7 +222,21 @@ static constexpr const char * methodToName(QCryptographicHash::Algorithm method)
default: return nullptr;
}
}
#endif
/*
Checks whether given method is not provided by OpenSSL and whether we will
have a fallback to non-OpenSSL implementation.
*/
static constexpr bool useNonOpenSSLFallback(QCryptographicHash::Algorithm method) noexcept
{
if (method == QCryptographicHash::Blake2b_160 || method == QCryptographicHash::Blake2b_256 ||
method == QCryptographicHash::Blake2b_384 || method == QCryptographicHash::Blake2s_128 ||
method == QCryptographicHash::Blake2s_160 || method == QCryptographicHash::Blake2s_224)
return true;
return false;
}
#endif // USING_OPENSSL30
class QCryptographicHashPrivate
{
@ -913,6 +927,12 @@ bool QCryptographicHash::supportsAlgorithm(QCryptographicHash::Algorithm method)
bool QCryptographicHashPrivate::supportsAlgorithm(QCryptographicHash::Algorithm method)
{
#ifdef USING_OPENSSL30
// OpenSSL doesn't support Blake2b{60,236,384} and Blake2s{128,160,224}
// and these would automatically return FALSE in that case, while they are
// actually supported by our non-OpenSSL implementation.
if (useNonOpenSSLFallback(method))
return true;
OSSL_PROVIDER_load(nullptr, "legacy");
OSSL_PROVIDER_load(nullptr, "default");