Skip to content

Commit 8d6041d

Browse files
committed
Changed benchmark menu so you can click all tabs and make benchmark sortable
1 parent 456764b commit 8d6041d

12 files changed

+199
-192
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ set(LIBRARY_SOURCES
6161
src/encryptionengine_fileops.cpp
6262
src/encryptionengine_keyderivation.cpp
6363
src/encryptionengine_crypto.cpp
64-
src/encryptionengine_benchmark.cpp
6564
include/encryptionengine.h
6665
src/encryptionworker.cpp
6766
include/encryptionworker.h

include/encryptionengine.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class EncryptionEngine
3030
void runBenchmark();
3131
void benchmarkCipher(const QString& algorithm, const QString& kdf, bool useHardwareAcceleration);
3232

33+
const EVP_CIPHER* getCipher(const QString& algorithm); // Move to public
34+
const EVP_CIPHER* getHardwareAcceleratedCipher(const QString& algorithm); // Move to public
35+
3336
private:
3437
QByteArray lastIv; // Store the last used IV
3538
bool m_aesNiSupported;
@@ -39,15 +42,12 @@ class EncryptionEngine
3942
bool performStandardDecryption(EVP_CIPHER_CTX* ctx, const EVP_CIPHER* cipher, const QByteArray& key, const QByteArray& iv, QFile& inputFile, QFile& outputFile);
4043
bool performAuthenticatedEncryption(EVP_CIPHER_CTX* ctx, const EVP_CIPHER* cipher, const QByteArray& key, const QByteArray& iv, QFile& inputFile, QFile& outputFile);
4144
bool performAuthenticatedDecryption(EVP_CIPHER_CTX* ctx, const EVP_CIPHER* cipher, const QByteArray& key, const QByteArray& iv, QFile& inputFile, QFile& outputFile);
45+
QByteArray performKeyDerivation(const QByteArray& passwordWithKeyfile, const QByteArray& salt, const QString& kdf, int iterations, int keySize);
4246

4347
QByteArray deriveKey(const QString& password, const QByteArray& salt, const QStringList& keyfilePaths, const QString& kdf, int iterations);
4448
QByteArray readKeyfile(const QString& keyfilePath);
45-
const EVP_CIPHER* getCipher(const QString& algorithm);
4649

4750
bool checkHardwareSupport();
48-
const EVP_CIPHER* getHardwareAcceleratedCipher(const QString& algorithm);
49-
50-
void benchmarkCipher(const QString& algorithm, bool useHardwareAcceleration);
5151
};
5252

5353
#endif // ENCRYPTIONENGINE_H

include/encryptionworker.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ class EncryptionWorker : public QObject
1313
explicit EncryptionWorker(QObject *parent = nullptr);
1414
void setParameters(const QString &path, const QString &password, const QString &algorithm,
1515
const QString &kdf, int iterations, bool useHMAC, bool encrypt, bool isFile, const QString &customHeader, const QStringList &keyfilePaths);
16+
void setBenchmarkParameters(const QStringList &algorithms, const QStringList &kdfs);
1617

1718
public slots:
1819
void process();
20+
void runBenchmark();
1921

2022
signals:
2123
void progress(int value);
@@ -36,7 +38,11 @@ public slots:
3638
QStringList keyfilePaths;
3739
EncryptionEngine engine;
3840

41+
QStringList benchmarkAlgorithms;
42+
QStringList benchmarkKdfs;
43+
3944
qint64 getFileSizeInBytes(const QString &path);
45+
void benchmarkCipher(const QString &algorithm, const QString &kdf, bool useHardwareAcceleration);
4046
};
4147

4248
#endif // ENCRYPTIONWORKER_H

include/mainwindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private slots:
6767
void checkHardwareAcceleration();
6868

6969
static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
70-
void updateBenchmarkTable(int iterations, double mbps, double ms, const QString &cipher, const QString &kdf);
70+
void updateBenchmarkTable(int iterations, double mbps, double ms, const QString &cipher, const QString &kdf); // Add this line
7171

7272
void safeConnect(const QObject* sender, const char* signal, const QObject* receiver, const char* method);
7373

resources/darktheme.qss

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,30 @@ CustomListWidget {
141141
border-radius: 5px;
142142
}
143143

144-
/* Large Encrypt and Decrypt buttons */
144+
/* Existing styles for Encrypt/Decrypt buttons */
145145
QPushButton#fileEncryptButton, QPushButton#fileDecryptButton, QPushButton#folderEncryptButton, QPushButton#folderDecryptButton {
146-
font-size: 18px;
147-
padding: 15px;
148-
border: 2px solid #777777;
149-
background-color: #444444;
150-
border-radius: 10px;
146+
background-color: #5A5A5A;
147+
color: white;
148+
border: 1px solid #767676;
149+
border-radius: 5px;
150+
padding: 5px;
151+
min-height: 50px;
151152
}
152153

153154
QPushButton#fileEncryptButton:hover, QPushButton#fileDecryptButton:hover, QPushButton#folderEncryptButton:hover, QPushButton#folderDecryptButton:hover {
154-
background-color: #555555;
155-
border: 2px solid #888888;
155+
background-color: #707070;
156+
}
157+
158+
/* Add styles for Benchmark button */
159+
QPushButton#benchmarkButton {
160+
background-color: #5A5A5A;
161+
color: white;
162+
border: 1px solid #767676;
163+
border-radius: 5px;
164+
padding: 5px;
165+
min-height: 50px;
166+
}
167+
168+
QPushButton#benchmarkButton:hover {
169+
background-color: #707070;
156170
}

resources/lighttheme.qss

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,30 @@ CustomListWidget {
141141
border-radius: 5px;
142142
}
143143

144-
/* Large Encrypt and Decrypt buttons */
144+
/* Existing styles for Encrypt/Decrypt buttons */
145145
QPushButton#fileEncryptButton, QPushButton#fileDecryptButton, QPushButton#folderEncryptButton, QPushButton#folderDecryptButton {
146-
font-size: 18px;
147-
padding: 15px;
148-
border: 2px solid #999999;
149-
background-color: #f0f0f0;
150-
border-radius: 10px;
146+
background-color: #F0F0F0;
147+
color: black;
148+
border: 1px solid #C0C0C0;
149+
border-radius: 5px;
150+
padding: 10px;
151+
min-height: 50px;
151152
}
152153

153154
QPushButton#fileEncryptButton:hover, QPushButton#fileDecryptButton:hover, QPushButton#folderEncryptButton:hover, QPushButton#folderDecryptButton:hover {
154-
background-color: #e0e0e0;
155-
border: 2px solid #bbbbbb;
155+
background-color: #E0E0E0;
156+
}
157+
158+
/* Add styles for Benchmark button */
159+
QPushButton#benchmarkButton {
160+
background-color: #F0F0F0;
161+
color: black;
162+
border: 1px solid #C0C0C0;
163+
border-radius: 5px;
164+
padding: 10px;
165+
min-height: 50px;
166+
}
167+
168+
QPushButton#benchmarkButton:hover {
169+
background-color: #E0E0E0;
156170
}

src/encryptionengine_benchmark.cpp

Lines changed: 0 additions & 86 deletions
This file was deleted.

src/encryptionengine_crypto.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ bool EncryptionEngine::cryptOperation(const QString& inputPath, const QString& o
6767

6868
bool success = false;
6969
if (encrypt) {
70-
success = performStandardEncryption(ctx, cipher, key, iv, inputFile, outputFile);
70+
success = useHMAC ? performAuthenticatedEncryption(ctx, cipher, key, iv, inputFile, outputFile)
71+
: performStandardEncryption(ctx, cipher, key, iv, inputFile, outputFile);
7172
} else {
72-
success = performStandardDecryption(ctx, cipher, key, iv, inputFile, outputFile);
73+
success = useHMAC ? performAuthenticatedDecryption(ctx, cipher, key, iv, inputFile, outputFile)
74+
: performStandardDecryption(ctx, cipher, key, iv, inputFile, outputFile);
7375
}
7476

7577
EVP_CIPHER_CTX_free(ctx);
@@ -228,6 +230,6 @@ const EVP_CIPHER* EncryptionEngine::getCipher(const QString& algorithm) {
228230
if (algorithm == "Blowfish") return EVP_bf_cbc();
229231
if (algorithm == "Camellia-256-CBC") return EVP_camellia_256_cbc();
230232
if (algorithm == "AES-128-CBC") return EVP_aes_128_cbc();
231-
232-
return nullptr;
233+
234+
return nullptr; // Ensure this correctly returns nullptr for unsupported ciphers
233235
}

src/encryptionengine_keyderivation.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <argon2.h>
55
#include <sodium.h>
66
#include <openssl/evp.h>
7+
#include <openssl/rand.h>
78

89
QByteArray EncryptionEngine::readKeyfile(const QString& keyfilePath) {
910
if (keyfilePath.isEmpty()) {
@@ -18,41 +19,22 @@ QByteArray EncryptionEngine::readKeyfile(const QString& keyfilePath) {
1819
}
1920

2021
QByteArray EncryptionEngine::deriveKey(const QString& password, const QByteArray& salt, const QStringList& keyfilePaths, const QString& kdf, int iterations) {
21-
QByteArray key(EVP_MAX_KEY_LENGTH, 0);
2222
QByteArray passwordWithKeyfile = password.toUtf8();
2323

2424
for (const QString &keyfilePath : keyfilePaths) {
2525
passwordWithKeyfile.append(readKeyfile(keyfilePath));
2626
}
2727

28-
if (kdf == "PBKDF2") {
29-
if (!PKCS5_PBKDF2_HMAC(passwordWithKeyfile.data(), passwordWithKeyfile.size(), reinterpret_cast<const unsigned char*>(salt.data()), salt.size(), iterations, EVP_sha256(), key.size(), reinterpret_cast<unsigned char*>(key.data()))) {
30-
qDebug() << "PBKDF2 key derivation failed";
31-
return QByteArray();
32-
}
33-
} else if (kdf == "Argon2") {
34-
if (argon2i_hash_raw(iterations, 1 << 16, 1, passwordWithKeyfile.data(), passwordWithKeyfile.size(), reinterpret_cast<const unsigned char*>(salt.data()), salt.size(), reinterpret_cast<unsigned char*>(key.data()), key.size()) != ARGON2_OK) {
35-
qDebug() << "Argon2 key derivation failed";
36-
return QByteArray();
37-
}
38-
} else if (kdf == "Scrypt") {
39-
unsigned long long opslimit = iterations;
40-
if (crypto_pwhash_scryptsalsa208sha256(reinterpret_cast<unsigned char*>(key.data()), static_cast<unsigned long long>(key.size()),
41-
passwordWithKeyfile.constData(), static_cast<unsigned long long>(passwordWithKeyfile.size()),
42-
reinterpret_cast<const unsigned char*>(salt.data()),
43-
opslimit,
44-
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE) != 0) {
45-
qDebug() << "Scrypt key derivation failed";
46-
return QByteArray();
47-
}
48-
}
49-
50-
return key;
28+
return performKeyDerivation(passwordWithKeyfile, salt, kdf, iterations, EVP_MAX_KEY_LENGTH);
5129
}
5230

5331
QByteArray EncryptionEngine::deriveKey(const QString &password, const QString &salt, const QString &kdf, int iterations, int keySize) {
54-
QByteArray key(keySize, 0);
5532
QByteArray passwordWithKeyfile = password.toUtf8();
33+
return performKeyDerivation(passwordWithKeyfile, salt.toUtf8(), kdf, iterations, keySize);
34+
}
35+
36+
QByteArray EncryptionEngine::performKeyDerivation(const QByteArray& passwordWithKeyfile, const QByteArray& salt, const QString& kdf, int iterations, int keySize) {
37+
QByteArray key(keySize, 0);
5638

5739
if (kdf == "PBKDF2") {
5840
if (!PKCS5_PBKDF2_HMAC(passwordWithKeyfile.data(), passwordWithKeyfile.size(), reinterpret_cast<const unsigned char*>(salt.data()), salt.size(), iterations, EVP_sha256(), key.size(), reinterpret_cast<unsigned char*>(key.data()))) {
@@ -74,6 +56,9 @@ QByteArray EncryptionEngine::deriveKey(const QString &password, const QString &s
7456
qDebug() << "Scrypt key derivation failed";
7557
return QByteArray();
7658
}
59+
} else {
60+
qDebug() << "Unknown KDF";
61+
return QByteArray();
7762
}
7863

7964
return key;

0 commit comments

Comments
 (0)