mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-28 00:39:43 -05:00
Use QtConcurrentRun instead of subclassing QThread.
This commit is contained in:
parent
2e84c96ab7
commit
9ef105e1ae
@ -52,7 +52,6 @@ set(keepassx_SOURCES
|
|||||||
gui/GroupView.cpp
|
gui/GroupView.cpp
|
||||||
gui/MainWindow.cpp
|
gui/MainWindow.cpp
|
||||||
keys/CompositeKey.cpp
|
keys/CompositeKey.cpp
|
||||||
keys/CompositeKey_p.h
|
|
||||||
keys/Key.h
|
keys/Key.h
|
||||||
keys/PasswordKey.cpp
|
keys/PasswordKey.cpp
|
||||||
streams/HashedBlockStream.cpp
|
streams/HashedBlockStream.cpp
|
||||||
@ -73,7 +72,6 @@ set(keepassx_MOC
|
|||||||
gui/GroupModel.h
|
gui/GroupModel.h
|
||||||
gui/GroupView.h
|
gui/GroupView.h
|
||||||
gui/MainWindow.h
|
gui/MainWindow.h
|
||||||
keys/CompositeKey_p.h
|
|
||||||
streams/HashedBlockStream.h
|
streams/HashedBlockStream.h
|
||||||
streams/LayeredStream.h
|
streams/LayeredStream.h
|
||||||
streams/qtiocompressor.h
|
streams/qtiocompressor.h
|
||||||
|
@ -16,11 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CompositeKey.h"
|
#include "CompositeKey.h"
|
||||||
#include "CompositeKey_p.h"
|
|
||||||
|
|
||||||
#include "crypto/CryptoHash.h"
|
#include "crypto/CryptoHash.h"
|
||||||
#include "crypto/SymmetricCipher.h"
|
#include "crypto/SymmetricCipher.h"
|
||||||
|
|
||||||
|
#include <QtCore/QtConcurrentRun>
|
||||||
|
|
||||||
CompositeKey::~CompositeKey()
|
CompositeKey::~CompositeKey()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_keys);
|
qDeleteAll(m_keys);
|
||||||
@ -47,46 +48,30 @@ QByteArray CompositeKey::transform(const QByteArray& seed, int rounds) const
|
|||||||
{
|
{
|
||||||
QByteArray key = rawKey();
|
QByteArray key = rawKey();
|
||||||
|
|
||||||
KeyTransformation* transform1 = new KeyTransformation(key.left(16), seed, rounds);
|
QFuture<QByteArray> future1 = QtConcurrent::run(transformKeyRaw, key.left(16), seed, rounds);
|
||||||
KeyTransformation* transform2 = new KeyTransformation(key.right(16), seed, rounds);
|
QFuture<QByteArray> future2 = QtConcurrent::run(transformKeyRaw, key.right(16), seed, rounds);
|
||||||
|
|
||||||
transform1->start();
|
|
||||||
transform2->start();
|
|
||||||
|
|
||||||
transform1->wait();
|
|
||||||
transform2->wait();
|
|
||||||
|
|
||||||
QByteArray transformed;
|
QByteArray transformed;
|
||||||
transformed.append(transform1->result());
|
transformed.append(future1.result());
|
||||||
transformed.append(transform2->result());
|
transformed.append(future2.result());
|
||||||
|
|
||||||
return CryptoHash::hash(transformed, CryptoHash::Sha256);
|
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<rounds; i++) {
|
||||||
|
cipher.processInPlace(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void CompositeKey::addKey(const Key& key)
|
void CompositeKey::addKey(const Key& key)
|
||||||
{
|
{
|
||||||
m_keys.append(key.clone());
|
m_keys.append(key.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyTransformation::KeyTransformation(const QByteArray& key, const QByteArray& seed, int rounds)
|
|
||||||
: m_key(key)
|
|
||||||
, m_seed(seed)
|
|
||||||
, m_rounds(rounds)
|
|
||||||
, m_result(key)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeyTransformation::run()
|
|
||||||
{
|
|
||||||
QByteArray iv(16, 0);
|
|
||||||
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Ecb, SymmetricCipher::Encrypt, m_seed, iv);
|
|
||||||
|
|
||||||
for (int i=0; i<m_rounds; i++) {
|
|
||||||
cipher.processInPlace(m_result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray KeyTransformation::result()
|
|
||||||
{
|
|
||||||
return m_result;
|
|
||||||
}
|
|
||||||
|
@ -34,6 +34,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Key*> m_keys;
|
QList<Key*> m_keys;
|
||||||
|
|
||||||
|
static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed, int rounds);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_COMPOSITEKEY_H
|
#endif // KEEPASSX_COMPOSITEKEY_H
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KEEPASSX_COMPOSITEKEY_P_H
|
|
||||||
#define KEEPASSX_COMPOSITEKEY_P_H
|
|
||||||
|
|
||||||
#include <QtCore/QThread>
|
|
||||||
|
|
||||||
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
|
|
Loading…
Reference in New Issue
Block a user