From 9ef105e1aeade472ffc9cc5eb858692095062590 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sat, 12 Nov 2011 01:49:19 +0100 Subject: [PATCH] Use QtConcurrentRun instead of subclassing QThread. --- src/CMakeLists.txt | 2 -- src/keys/CompositeKey.cpp | 53 ++++++++++++++------------------------- src/keys/CompositeKey.h | 2 ++ src/keys/CompositeKey_p.h | 41 ------------------------------ 4 files changed, 21 insertions(+), 77 deletions(-) delete mode 100644 src/keys/CompositeKey_p.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 36becd981..e982daa88 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,7 +52,6 @@ set(keepassx_SOURCES gui/GroupView.cpp gui/MainWindow.cpp keys/CompositeKey.cpp - keys/CompositeKey_p.h keys/Key.h keys/PasswordKey.cpp streams/HashedBlockStream.cpp @@ -73,7 +72,6 @@ set(keepassx_MOC gui/GroupModel.h gui/GroupView.h gui/MainWindow.h - keys/CompositeKey_p.h streams/HashedBlockStream.h streams/LayeredStream.h streams/qtiocompressor.h diff --git a/src/keys/CompositeKey.cpp b/src/keys/CompositeKey.cpp index a039a2da5..c5c50e110 100644 --- a/src/keys/CompositeKey.cpp +++ b/src/keys/CompositeKey.cpp @@ -16,11 +16,12 @@ */ #include "CompositeKey.h" -#include "CompositeKey_p.h" #include "crypto/CryptoHash.h" #include "crypto/SymmetricCipher.h" +#include + CompositeKey::~CompositeKey() { qDeleteAll(m_keys); @@ -47,46 +48,30 @@ QByteArray CompositeKey::transform(const QByteArray& seed, int rounds) const { QByteArray key = rawKey(); - KeyTransformation* transform1 = new KeyTransformation(key.left(16), seed, rounds); - KeyTransformation* transform2 = new KeyTransformation(key.right(16), seed, rounds); - - transform1->start(); - transform2->start(); - - transform1->wait(); - transform2->wait(); + QFuture future1 = QtConcurrent::run(transformKeyRaw, key.left(16), seed, rounds); + QFuture future2 = QtConcurrent::run(transformKeyRaw, key.right(16), seed, rounds); QByteArray transformed; - transformed.append(transform1->result()); - transformed.append(transform2->result()); + transformed.append(future1.result()); + transformed.append(future2.result()); return CryptoHash::hash(transformed, CryptoHash::Sha256); } +QByteArray CompositeKey::transformKeyRaw(const QByteArray& key, const QByteArray& seed, int rounds) { + QByteArray iv(16, 0); + SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Ecb, SymmetricCipher::Encrypt, seed, iv); + + QByteArray result = key; + + for (int i=0; i m_keys; + + static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed, int rounds); }; #endif // KEEPASSX_COMPOSITEKEY_H diff --git a/src/keys/CompositeKey_p.h b/src/keys/CompositeKey_p.h deleted file mode 100644 index c259bf526..000000000 --- a/src/keys/CompositeKey_p.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -* Copyright (C) 2010 Felix Geyer -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 2 or (at your option) -* version 3 of the License. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -#ifndef KEEPASSX_COMPOSITEKEY_P_H -#define KEEPASSX_COMPOSITEKEY_P_H - -#include - -class KeyTransformation : public QThread -{ - Q_OBJECT - -public: - KeyTransformation(const QByteArray& key, const QByteArray& seed, int rounds); - QByteArray result(); - -protected: - void run(); - -private: - QByteArray m_key; - QByteArray m_seed; - int m_rounds; - QByteArray m_result; -}; - -#endif // KEEPASSX_COMPOSITEKEY_P_H