Pull out KDFs into their own class hierarchy

In preparation for multiple KDFs in KDBX 4
This commit is contained in:
angelsl 2017-11-12 20:20:57 +08:00 committed by Jonathan White
parent 6aaa89a23c
commit 2e19af5032
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
18 changed files with 555 additions and 265 deletions

View file

@ -21,6 +21,7 @@
#include <QImage>
#include <QTextCodec>
#include "crypto/kdf/AesKdf.h"
#include "core/Database.h"
#include "core/Endian.h"
#include "core/Entry.h"
@ -159,10 +160,10 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
raiseError("Invalid number of transform rounds");
return nullptr;
}
if (!m_db->setTransformRounds(m_transformRounds)) {
raiseError(tr("Unable to calculate master key"));
return nullptr;
}
AesKdf* kdf = new AesKdf();
kdf->setRounds(m_transformRounds);
kdf->setSeed(m_transformSeed);
db->setKdf(kdf);
qint64 contentPos = m_device->pos();
@ -397,12 +398,11 @@ QByteArray KeePass1Reader::key(const QByteArray& password, const QByteArray& key
key.setPassword(password);
key.setKeyfileData(keyfileData);
bool ok;
QString errorString;
QByteArray transformedKey = key.transform(m_transformSeed, m_transformRounds, &ok, &errorString);
QByteArray transformedKey;
bool result = key.transform(*m_db->kdf(), transformedKey);
if (!ok) {
raiseError(errorString);
if (!result) {
raiseError("Key transformation failed");
return QByteArray();
}