Add CompositeKey::transformKeyBenchmark().

This method tests how many key transformation rounds can be calculated
within a specific time.
This commit is contained in:
Felix Geyer
2012-05-07 14:38:10 +02:00
parent d5fc1bf0b4
commit 7790f2e7ba
4 changed files with 89 additions and 0 deletions

View File

@@ -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);
}