aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2020-10-31 19:50:42 +0100
committerLNJ <lnj@kaidan.im>2020-10-31 20:05:32 +0100
commit7b46c85e651a0fba7d4c14d2ae1fa766ed306a77 (patch)
tree62bf72da60f9a6152de53a13894b49e15df9fb0a /src/base
parente2cf93b29007afb4e71a5591c50843be9ad58adc (diff)
downloadqxmpp-7b46c85e651a0fba7d4c14d2ae1fa766ed306a77.tar.gz
Add SCRAM-SHA3-512 SASL algorithm
QCryptographicHash::Sha3_512 was accidentially using Keccak-512 before Qt 5.9.2, thus we can only use SCRAM-SHA3-512 when using Qt >= 5.9.2.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/QXmppSasl.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/base/QXmppSasl.cpp b/src/base/QXmppSasl.cpp
index ebc3c99c..6c3c394d 100644
--- a/src/base/QXmppSasl.cpp
+++ b/src/base/QXmppSasl.cpp
@@ -34,6 +34,10 @@
#include <QUrlQuery>
#include <QtEndian>
+#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 2)
+#define QT_HAS_SHA3_SUPPORT
+#endif
+
const char *ns_xmpp_sasl = "urn:ietf:params:xml:ns:xmpp-sasl";
static QByteArray forcedNonce;
@@ -43,6 +47,9 @@ static const QMap<QString, QCryptographicHash::Algorithm> SCRAM_ALGORITHMS = {
{ QStringLiteral("SCRAM-SHA-1"), QCryptographicHash::Sha1 },
{ QStringLiteral("SCRAM-SHA-256"), QCryptographicHash::Sha256 },
{ QStringLiteral("SCRAM-SHA-512"), QCryptographicHash::Sha512 },
+#ifdef QT_HAS_SHA3_SUPPORT
+ { QStringLiteral("SCRAM-SHA3-512"), QCryptographicHash::RealSha3_512 },
+#endif
};
// Returns the hash length in bytes (QCH::hashLength() only exists since 5.12).
@@ -57,6 +64,9 @@ int hashLength(QCryptographicHash::Algorithm algorithm)
case QCryptographicHash::Sha256:
return 256 / 8;
case QCryptographicHash::Sha512:
+#ifdef QT_HAS_SHA3_SUPPORT
+ case QCryptographicHash::RealSha3_512:
+#endif
return 512 / 8;
default:
return QCryptographicHash::hash({}, algorithm).size();
@@ -299,6 +309,9 @@ QXmppSaslClient::~QXmppSaslClient()
QStringList QXmppSaslClient::availableMechanisms()
{
return {
+#ifdef QT_HAS_SHA3_SUPPORT
+ QStringLiteral("SCRAM-SHA3-512"),
+#endif
QStringLiteral("SCRAM-SHA-512"),
QStringLiteral("SCRAM-SHA-256"),
QStringLiteral("SCRAM-SHA-1"),