mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Add CompositeKey::transformKeyBenchmark().
This method tests how many key transformation rounds can be calculated within a specific time.
This commit is contained in:
parent
d5fc1bf0b4
commit
7790f2e7ba
@ -99,6 +99,7 @@ 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
|
||||
|
@ -16,8 +16,10 @@
|
||||
*/
|
||||
|
||||
#include "CompositeKey.h"
|
||||
#include "CompositeKey_p.h"
|
||||
|
||||
#include <QtCore/QtConcurrentRun>
|
||||
#include <QtCore/QTime>
|
||||
|
||||
#include "crypto/CryptoHash.h"
|
||||
#include "crypto/SymmetricCipher.h"
|
||||
@ -103,3 +105,48 @@ void CompositeKey::addKey(const Key& key)
|
||||
{
|
||||
m_keys.append(key.clone());
|
||||
}
|
||||
|
||||
int CompositeKey::transformKeyBenchmark(int msec)
|
||||
{
|
||||
TransformKeyBenchmarkThread thread1(msec);
|
||||
TransformKeyBenchmarkThread thread2(msec);
|
||||
|
||||
thread1.start();
|
||||
thread2.start();
|
||||
|
||||
thread1.wait();
|
||||
thread2.wait();
|
||||
|
||||
return qMin(thread1.rounds(), thread2.rounds());
|
||||
}
|
||||
|
||||
|
||||
TransformKeyBenchmarkThread::TransformKeyBenchmarkThread(int msec)
|
||||
: m_msec(msec)
|
||||
, m_rounds(0)
|
||||
{
|
||||
Q_ASSERT(msec > 0);
|
||||
}
|
||||
|
||||
int TransformKeyBenchmarkThread::rounds()
|
||||
{
|
||||
return m_rounds;
|
||||
}
|
||||
|
||||
void TransformKeyBenchmarkThread::run()
|
||||
{
|
||||
QByteArray key = QByteArray('\x7E', 32);
|
||||
QByteArray seed = QByteArray('\x4B', 32);
|
||||
QByteArray iv(16, 0);
|
||||
|
||||
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Ecb,
|
||||
SymmetricCipher::Encrypt, seed, iv);
|
||||
|
||||
QTime t;
|
||||
t.start();
|
||||
|
||||
do {
|
||||
cipher.processInPlace(key, 100);
|
||||
m_rounds += 100;
|
||||
} while (t.elapsed() < m_msec);
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ public:
|
||||
QByteArray transform(const QByteArray& seed, int rounds) const;
|
||||
void addKey(const Key& key);
|
||||
|
||||
static int transformKeyBenchmark(int msec);
|
||||
|
||||
private:
|
||||
static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed,
|
||||
int rounds);
|
||||
|
39
src/keys/CompositeKey_p.h
Normal file
39
src/keys/CompositeKey_p.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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 TransformKeyBenchmarkThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TransformKeyBenchmarkThread(int msec);
|
||||
int rounds();
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
||||
private:
|
||||
int m_msec;
|
||||
int m_rounds;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_COMPOSITEKEY_P_H
|
Loading…
Reference in New Issue
Block a user