summarylogtreecommitdiffstats
path: root/0003-Use-the-correct-cipher-for-benchmark.patch
blob: ea306e230cfb20f80373b4e52a806d372e907a18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
From bb693692988026dabe68e8294fe9e17f99fe1499 Mon Sep 17 00:00:00 2001
From: Timothy Redaelli <timothy.redaelli@gmail.com>
Date: Thu, 6 Aug 2015 15:12:37 +0200
Subject: [PATCH 3/3] Use the correct cipher for benchmark

---
 src/gui/DatabaseSettingsWidget.cpp | 10 +++++++++-
 src/keys/CompositeKey.cpp          | 11 ++++++-----
 src/keys/CompositeKey.h            |  3 ++-
 src/keys/CompositeKey_p.h          |  4 +++-
 4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/gui/DatabaseSettingsWidget.cpp b/src/gui/DatabaseSettingsWidget.cpp
index 34c55b5c..ee50eae3 100644
--- a/src/gui/DatabaseSettingsWidget.cpp
+++ b/src/gui/DatabaseSettingsWidget.cpp
@@ -21,9 +21,11 @@
 #include "core/Database.h"
 #include "core/Group.h"
 #include "core/Metadata.h"
+#include "crypto/SymmetricCipher.h"
 #include "format/KeePass2.h"
 #include "keys/CompositeKey.h"
 
+
 DatabaseSettingsWidget::DatabaseSettingsWidget(QWidget* parent)
     : DialogyWidget(parent)
     , m_ui(new Ui::DatabaseSettingsWidget())
@@ -143,7 +145,13 @@ void DatabaseSettingsWidget::reject()
 void DatabaseSettingsWidget::transformRoundsBenchmark()
 {
     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-    int rounds = CompositeKey::transformKeyBenchmark(1000);
+    int rounds;
+    if (m_ui->AlgorithmComboBox->currentIndex() == 0) {
+        rounds = CompositeKey::transformKeyBenchmark(1000, SymmetricCipher::Aes256);
+    }
+    else {
+        rounds = CompositeKey::transformKeyBenchmark(1000, SymmetricCipher::Twofish);
+    }
     if (rounds != -1) {
         m_ui->transformRoundsSpinBox->setValue(rounds);
     }
diff --git a/src/keys/CompositeKey.cpp b/src/keys/CompositeKey.cpp
index 5bf9cae5..4326449b 100644
--- a/src/keys/CompositeKey.cpp
+++ b/src/keys/CompositeKey.cpp
@@ -145,10 +145,10 @@ void CompositeKey::addKey(const Key& key)
     m_keys.append(key.clone());
 }
 
-int CompositeKey::transformKeyBenchmark(int msec)
+int CompositeKey::transformKeyBenchmark(int msec, SymmetricCipher::Algorithm algo)
 {
-    TransformKeyBenchmarkThread thread1(msec);
-    TransformKeyBenchmarkThread thread2(msec);
+    TransformKeyBenchmarkThread thread1(msec, algo);
+    TransformKeyBenchmarkThread thread2(msec, algo);
 
     thread1.start();
     thread2.start();
@@ -160,8 +160,9 @@ int CompositeKey::transformKeyBenchmark(int msec)
 }
 
 
-TransformKeyBenchmarkThread::TransformKeyBenchmarkThread(int msec)
+TransformKeyBenchmarkThread::TransformKeyBenchmarkThread(int msec, SymmetricCipher::Algorithm algo)
     : m_msec(msec)
+    , algo(algo)
     , m_rounds(0)
 {
     Q_ASSERT(msec > 0);
@@ -178,7 +179,7 @@ void TransformKeyBenchmarkThread::run()
     QByteArray seed = QByteArray(32, '\x4B');
     QByteArray iv(16, 0);
 
-    SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Ecb,
+    SymmetricCipher cipher(algo, SymmetricCipher::Ecb,
                            SymmetricCipher::Encrypt);
     cipher.init(seed, iv);
 
diff --git a/src/keys/CompositeKey.h b/src/keys/CompositeKey.h
index 3290d367..0163c914 100644
--- a/src/keys/CompositeKey.h
+++ b/src/keys/CompositeKey.h
@@ -20,6 +20,7 @@
 
 #include <QList>
 
+#include "crypto/SymmetricCipher.h"
 #include "keys/Key.h"
 
 class CompositeKey : public Key
@@ -38,7 +39,7 @@ public:
                          bool* ok, QString* errorString) const;
     void addKey(const Key& key);
 
-    static int transformKeyBenchmark(int msec);
+    static int transformKeyBenchmark(int msec, SymmetricCipher::Algorithm algo);
 
 private:
     static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed,
diff --git a/src/keys/CompositeKey_p.h b/src/keys/CompositeKey_p.h
index 27fa7abc..9f321b2c 100644
--- a/src/keys/CompositeKey_p.h
+++ b/src/keys/CompositeKey_p.h
@@ -19,19 +19,21 @@
 #define KEEPASSX_COMPOSITEKEY_P_H
 
 #include <QThread>
+#include "crypto/SymmetricCipher.h"
 
 class TransformKeyBenchmarkThread : public QThread
 {
     Q_OBJECT
 
 public:
-    explicit TransformKeyBenchmarkThread(int msec);
+    explicit TransformKeyBenchmarkThread(int msec, SymmetricCipher::Algorithm algo);
     int rounds();
 
 protected:
     void run();
 
 private:
+    SymmetricCipher::Algorithm algo;
     int m_msec;
     int m_rounds;
 };
-- 
2.5.0