diff --git a/CMakeLists.txt b/CMakeLists.txt index 1aab0947..9c4d78d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,8 @@ endif() option(IRIS_ENABLE_INSTALL "Enable installation" ON) option(IRIS_ENABLE_JINGLE_SCTP "Enable SCTP over ICE Jingle transport / data channels" ON) -option(IRIS_BUNDLED_QCA "Adds: DTLS, Blake2b and other useful for XMPP crypto-stuff" ${IRIS_DEFAULT_BUNDLED_QCA}) +# note Blake2b is needed only with Qt5. Qt6 has its own implementation +option(IRIS_BUNDLED_QCA "Adds: DTLS, Blake2b (needed with Qt5) and other useful for XMPP crypto-stuff" ${IRIS_DEFAULT_BUNDLED_QCA}) option(IRIS_BUNDLED_USRSCTP "Compile compatible UsrSCTP lib (required for datachannel Jingle transport)" ${IRIS_DEFAULT_BUNDLED_USRSCTP}) option(IRIS_BUILD_TOOLS "Build tools and examples" OFF) option(IRIS_ENABLE_DEBUG "Enable debugging code paths" OFF) @@ -101,7 +102,7 @@ if(IRIS_ENABLE_JINGLE_SCTP) include(IrisSCTP) endif() -if(NOT IRIS_BUNDLED_QCA) +if(NOT IRIS_BUNDLED_QCA AND QT_DEFAULT_MAJOR_VERSION LESS 6) find_package(B2 QUIET) if(B2_FOUND) message(STATUS "Found B2: ${B2_LIBRARY}") diff --git a/src/xmpp/CMakeLists.txt b/src/xmpp/CMakeLists.txt index aaf3999e..1749b8ee 100644 --- a/src/xmpp/CMakeLists.txt +++ b/src/xmpp/CMakeLists.txt @@ -95,7 +95,6 @@ set(XMPP_HEADERS_PRIVATE sasl/scramsha1signature.h zlib/zlibcompressor.h zlib/zlibdecompressor.h - blake2/blake2qt.h base/timezone.h ) @@ -154,8 +153,6 @@ target_sources(iris PRIVATE zlib/zlibcompressor.cpp zlib/zlibdecompressor.cpp - blake2/blake2qt.cpp - jid/jid.cpp sasl/digestmd5proplist.cpp @@ -183,17 +180,20 @@ if(IRIS_ENABLE_JINGLE_SCTP) ) endif() -if(B2_FOUND) - message(STATUS "Building with system blake2 library") - target_link_libraries(iris PRIVATE ${B2_LIBRARY}) -else() - if(NOT IRIS_BUNDLED_QCA) - message(STATUS "No system blake2 and bundled QCA is disabled. Expect slow hashing.") +if(QT_DEFAULT_MAJOR_VERSION LESS 6) + target_sources(iris blake2/blake2qt.cpp blake2/blake2qt.h) + if(B2_FOUND) + message(STATUS "Building with system blake2 library") + target_link_libraries(iris PRIVATE ${B2_LIBRARY}) + else() + if(NOT IRIS_BUNDLED_QCA) + message(STATUS "No system blake2 and bundled QCA is disabled. Expect slow hashing.") + endif() + target_sources(iris PRIVATE + blake2/blake2b-ref.c + blake2/blake2s-ref.c + ) endif() - target_sources(iris PRIVATE - blake2/blake2b-ref.c - blake2/blake2s-ref.c - ) endif() target_link_libraries(iris diff --git a/src/xmpp/xmpp-im/xmpp_hash.cpp b/src/xmpp/xmpp-im/xmpp_hash.cpp index f820a251..f96e1d3b 100644 --- a/src/xmpp/xmpp-im/xmpp_hash.cpp +++ b/src/xmpp/xmpp-im/xmpp_hash.cpp @@ -48,12 +48,18 @@ static const std::array hashTypes { HashDesc { "blake2b-256", Hash::Type::Blake2b256 }, HashDesc { "blake2b-512", Hash::Type::Blake2b512 } }; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) using HashVariant = std::variant; +#else +using HashVariant = std::variant; +#endif HashVariant findHasher(Hash::Type hashType) { QString qcaType; - QCryptographicHash::Algorithm qtType = QCryptographicHash::Algorithm(-1); - Blake2Hash::DigestSize blakeDS = Blake2Hash::DigestSize(-1); + QCryptographicHash::Algorithm qtType = QCryptographicHash::Algorithm(-1); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + Blake2Hash::DigestSize blakeDS = Blake2Hash::DigestSize(-1); +#endif switch (hashType) { case Hash::Type::Sha1: @@ -76,6 +82,7 @@ HashVariant findHasher(Hash::Type hashType) qtType = QCryptographicHash::Sha3_512; qcaType = "sha3_512"; break; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) case Hash::Type::Blake2b256: qcaType = "blake2b_256"; blakeDS = Blake2Hash::Digest256; @@ -84,6 +91,16 @@ HashVariant findHasher(Hash::Type hashType) qcaType = "blake2b_512"; blakeDS = Blake2Hash::Digest512; break; +#else + case Hash::Type::Blake2b256: + qtType = QCryptographicHash::Blake2b_256; + qcaType = "blake2b_256"; + break; + case Hash::Type::Blake2b512: + qtType = QCryptographicHash::Blake2b_512; + qcaType = "blake2b_512"; + break; +#endif case Hash::Type::Unknown: default: qDebug("invalid hash type"); @@ -99,12 +116,15 @@ HashVariant findHasher(Hash::Type hashType) if (qtType != QCryptographicHash::Algorithm(-1)) { return HashVariant { std::in_place_type, qtType }; - } else if (blakeDS != Blake2Hash::DigestSize(-1)) { + } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + else if (blakeDS != Blake2Hash::DigestSize(-1)) { Blake2Hash bh(blakeDS); if (bh.isValid()) { return HashVariant { std::in_place_type, std::move(bh) }; } } +#endif return nullptr; } @@ -156,6 +176,7 @@ bool Hash::compute(const QByteArray &ba) std::visit( [&ba, this](auto &&arg) { using T = std::decay_t; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if constexpr (std::is_same_v) { arg.update(ba); v_data = arg.final().toByteArray(); @@ -166,6 +187,16 @@ bool Hash::compute(const QByteArray &ba) if (arg.addData(ba)) v_data = arg.final(); } +#else + // Qt6 claims to have openssl backend and it doesn't copy data (?) + if constexpr (std::is_same_v) { + arg.addData(ba); + v_data = arg.result(); + } else if constexpr (std::is_same_v) { + arg.update(ba); + v_data = arg.final().toByteArray(); + } +#endif }, hasher); @@ -183,6 +214,7 @@ bool Hash::compute(QIODevice *dev) std::visit( [dev, this](auto &&arg) { using T = std::decay_t; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if constexpr (std::is_same_v) { arg.update(dev); v_data = arg.final().toByteArray(); @@ -193,6 +225,15 @@ bool Hash::compute(QIODevice *dev) if (arg.addData(dev)) v_data = arg.final(); } +#else + if constexpr (std::is_same_v) { + arg.addData(dev); + v_data = arg.result(); + } else if constexpr (std::is_same_v) { + arg.update(dev); + v_data = arg.final().toByteArray(); + } +#endif }, hasher); @@ -306,13 +347,22 @@ bool StreamHash::addData(const QByteArray &data) std::visit( [&data, &ret](auto &&arg) { using T = std::decay_t; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if constexpr (std::is_same_v) { arg.update(data); } else if constexpr (std::is_same_v) { arg.addData(data); } else if constexpr (std::is_same_v) { ret = arg.addData(data); - } else + } +#else + if constexpr (std::is_same_v) { + arg.addData(data); + } else if constexpr (std::is_same_v) { + arg.update(data); + } +#endif + else ret = false; }, d->hasher); @@ -324,6 +374,7 @@ Hash StreamHash::final() auto data = std::visit( [](auto &&arg) { using T = std::decay_t; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if constexpr (std::is_same_v) { return arg.final().toByteArray(); } else if constexpr (std::is_same_v) { @@ -331,6 +382,13 @@ Hash StreamHash::final() } else if constexpr (std::is_same_v) { return arg.final(); } +#else + if constexpr (std::is_same_v) { + return arg.result(); + } else if constexpr (std::is_same_v) { + return arg.final().toByteArray(); + } +#endif return QByteArray(); }, d->hasher);