Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Geyer <debfx@fobos.de>2012-05-07 16:38:10 +0400
committerFelix Geyer <debfx@fobos.de>2012-05-07 16:41:31 +0400
commit7790f2e7baa6231bf268bed515ce2c774bf98f93 (patch)
tree204fa04f5fbd90b4f74f14f43f7cfd26378bcd1d /src
parentd5fc1bf0b4f9deb5e848d70f00e255661ac9d2b3 (diff)
Add CompositeKey::transformKeyBenchmark().
This method tests how many key transformation rounds can be calculated within a specific time.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/keys/CompositeKey.cpp47
-rw-r--r--src/keys/CompositeKey.h2
-rw-r--r--src/keys/CompositeKey_p.h39
4 files changed, 89 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d446d58da..680c8307b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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
diff --git a/src/keys/CompositeKey.cpp b/src/keys/CompositeKey.cpp
index 0c7c43537..0dbcacce9 100644
--- a/src/keys/CompositeKey.cpp
+++ b/src/keys/CompositeKey.cpp
@@ -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);
+}
diff --git a/src/keys/CompositeKey.h b/src/keys/CompositeKey.h
index 3fa438681..e95d521fd 100644
--- a/src/keys/CompositeKey.h
+++ b/src/keys/CompositeKey.h
@@ -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);
diff --git a/src/keys/CompositeKey_p.h b/src/keys/CompositeKey_p.h
new file mode 100644
index 000000000..c704f086b
--- /dev/null
+++ b/src/keys/CompositeKey_p.h
@@ -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