From 41061cfde8067317d7b13363a5bcadfc9630db71 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Fri, 1 Apr 2022 07:10:11 -0400 Subject: [PATCH] Improve speed of AES KDF transform * Remove parallel left/right block calculations in favor of calculating both blocks simultaneously. This brings the calculation within parity of 2.6.6. * Fix #7682 --- src/crypto/kdf/AesKdf.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/crypto/kdf/AesKdf.cpp b/src/crypto/kdf/AesKdf.cpp index 481b7e461..119765785 100644 --- a/src/crypto/kdf/AesKdf.cpp +++ b/src/crypto/kdf/AesKdf.cpp @@ -62,30 +62,19 @@ QVariantMap AesKdf::writeParameters() bool AesKdf::transform(const QByteArray& raw, QByteArray& result) const { - QByteArray resultLeft; - QByteArray resultRight; - - QFuture future = QtConcurrent::run(transformKeyRaw, raw.left(16), m_seed, m_rounds, &resultLeft); - - bool rightResult = transformKeyRaw(raw.right(16), m_seed, m_rounds, &resultRight); - bool leftResult = future.result(); - - if (!rightResult || !leftResult) { - return false; - } - - QByteArray transformed; - transformed.append(resultLeft); - transformed.append(resultRight); - - result = CryptoHash::hash(transformed, CryptoHash::Sha256); - return true; + return transformKeyRaw(raw, m_seed, m_rounds, &result); } bool AesKdf::transformKeyRaw(const QByteArray& key, const QByteArray& seed, int rounds, QByteArray* result) { - *result = key; - return SymmetricCipher::aesKdf(seed, rounds, *result); + if (!result) { + return false; + } + + auto out = key; + SymmetricCipher::aesKdf(seed, rounds, out); + *result = CryptoHash::hash(out, CryptoHash::Sha256); + return true; } QSharedPointer AesKdf::clone() const