@@ -159,12 +159,7 @@ void DatabaseSettingsWidgetEncryption::initialize()
159159 // Set up KDF algorithms
160160 loadKdfAlgorithms ();
161161
162- // Perform Benchmark if requested
163162 if (isNewDatabase) {
164- if (IS_ARGON2 (m_ui->kdfComboBox ->currentData ())) {
165- m_ui->memorySpinBox ->setValue (16 );
166- m_ui->parallelismSpinBox ->setValue (2 );
167- }
168163 benchmarkTransformRounds ();
169164 }
170165
@@ -225,16 +220,16 @@ void DatabaseSettingsWidgetEncryption::loadKdfParameters()
225220 // Set Argon2 parameters
226221 auto argon2Kdf = kdf.staticCast <Argon2Kdf>();
227222 m_ui->transformRoundsSpinBox ->setValue (argon2Kdf->rounds ());
228- m_ui->memorySpinBox ->setValue (static_cast < int > (argon2Kdf->memory ()) / ( 1 << 10 ));
223+ m_ui->memorySpinBox ->setValue (Argon2Kdf::toMebibytes (argon2Kdf->memory ()));
229224 m_ui->parallelismSpinBox ->setValue (argon2Kdf->parallelism ());
230225 } else if (!dbIsArgon2 && !kdfIsArgon2) {
231226 // Set AES KDF parameters
232227 m_ui->transformRoundsSpinBox ->setValue (kdf->rounds ());
233228 } else {
234229 // Set reasonable defaults and then benchmark
235230 if (kdfIsArgon2) {
236- m_ui->memorySpinBox ->setValue (16 );
237- m_ui->parallelismSpinBox ->setValue (2 );
231+ m_ui->memorySpinBox ->setValue (Argon2Kdf::toMebibytes (ARGON2_DEFAULT_MEMORY) );
232+ m_ui->parallelismSpinBox ->setValue (ARGON2_DEFAULT_PARALLELISM );
238233 }
239234 benchmarkTransformRounds ();
240235 }
@@ -343,7 +338,7 @@ bool DatabaseSettingsWidgetEncryption::saveSettings()
343338 kdf->setRounds (m_ui->transformRoundsSpinBox ->value ());
344339 if (IS_ARGON2 (kdf->uuid ())) {
345340 auto argon2Kdf = kdf.staticCast <Argon2Kdf>();
346- argon2Kdf->setMemory (static_cast <quint64> (m_ui->memorySpinBox ->value ()) * ( 1 << 10 ));
341+ argon2Kdf->setMemory (Argon2Kdf::toKibibytes (m_ui->memorySpinBox ->value ()));
347342 argon2Kdf->setParallelism (static_cast <quint32>(m_ui->parallelismSpinBox ->value ()));
348343 }
349344
@@ -377,8 +372,8 @@ void DatabaseSettingsWidgetEncryption::benchmarkTransformRounds(int millisecs)
377372 auto argon2Kdf = kdf.staticCast <Argon2Kdf>();
378373 // Set a small static number of rounds for the benchmark
379374 argon2Kdf->setRounds (4 );
380- if (!argon2Kdf->setMemory (static_cast <quint64> (m_ui->memorySpinBox ->value ()) * ( 1 << 10 ))) {
381- m_ui->memorySpinBox ->setValue (static_cast < int > (argon2Kdf->memory () / ( 1 << 10 )));
375+ if (!argon2Kdf->setMemory (Argon2Kdf::toKibibytes (m_ui->memorySpinBox ->value ()))) {
376+ m_ui->memorySpinBox ->setValue (Argon2Kdf::toMebibytes (argon2Kdf->memory ()));
382377 }
383378 if (!argon2Kdf->setParallelism (static_cast <quint32>(m_ui->parallelismSpinBox ->value ()))) {
384379 m_ui->parallelismSpinBox ->setValue (argon2Kdf->parallelism ());
0 commit comments