mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 07:19:42 -05:00
parent
225e5dac66
commit
cf4e574c50
@ -38,6 +38,7 @@ SymmetricCipherBackend* SymmetricCipher::createBackend(SymmetricCipher::Algorith
|
||||
{
|
||||
switch (algo) {
|
||||
case SymmetricCipher::Aes256:
|
||||
case SymmetricCipher::Twofish:
|
||||
return new SymmetricCipherGcrypt(algo, mode, direction);
|
||||
|
||||
case SymmetricCipher::Salsa20:
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
enum Algorithm
|
||||
{
|
||||
Aes256,
|
||||
Twofish,
|
||||
Salsa20
|
||||
};
|
||||
|
||||
|
@ -21,12 +21,11 @@
|
||||
|
||||
SymmetricCipherGcrypt::SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
|
||||
SymmetricCipher::Direction direction)
|
||||
: m_algo(GCRY_CIPHER_AES256)
|
||||
: m_algo(gcryptAlgo(algo))
|
||||
, m_mode(gcryptMode(mode))
|
||||
, m_direction(direction)
|
||||
{
|
||||
Q_ASSERT(Crypto::initalized());
|
||||
Q_ASSERT(algo == SymmetricCipher::Aes256);
|
||||
}
|
||||
|
||||
SymmetricCipherGcrypt::~SymmetricCipherGcrypt()
|
||||
@ -34,6 +33,21 @@ SymmetricCipherGcrypt::~SymmetricCipherGcrypt()
|
||||
gcry_cipher_close(m_ctx);
|
||||
}
|
||||
|
||||
int SymmetricCipherGcrypt::gcryptAlgo(SymmetricCipher::Algorithm algo)
|
||||
{
|
||||
switch (algo) {
|
||||
case SymmetricCipher::Aes256:
|
||||
return GCRY_CIPHER_AES256;
|
||||
|
||||
case SymmetricCipher::Twofish:
|
||||
return GCRY_CIPHER_TWOFISH;
|
||||
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int SymmetricCipherGcrypt::gcryptMode(SymmetricCipher::Mode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
|
@ -41,6 +41,7 @@ public:
|
||||
int blockSize() const;
|
||||
|
||||
private:
|
||||
static int gcryptAlgo(SymmetricCipher::Algorithm algo);
|
||||
static int gcryptMode(SymmetricCipher::Mode mode);
|
||||
|
||||
gcry_cipher_hd_t m_ctx;
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <QtCore/QtGlobal>
|
||||
|
||||
#include "core/Uuid.h"
|
||||
|
||||
namespace KeePass1
|
||||
{
|
||||
const quint32 SIGNATURE_1 = 0x9AA2D903;
|
||||
|
@ -272,7 +272,8 @@ SymmetricCipherStream* KeePass1Reader::testKeys(const QString& password, const Q
|
||||
SymmetricCipher::Cbc, SymmetricCipher::Decrypt, finalKey, m_encryptionIV));
|
||||
}
|
||||
else {
|
||||
// TODO twofish
|
||||
cipherStream.reset(new SymmetricCipherStream(m_device, SymmetricCipher::Twofish,
|
||||
SymmetricCipher::Cbc, SymmetricCipher::Decrypt, finalKey, m_encryptionIV));
|
||||
}
|
||||
|
||||
cipherStream->open(QIODevice::ReadOnly);
|
||||
|
@ -179,6 +179,23 @@ void TestKeePass1Reader::testCompositeKey()
|
||||
delete db;
|
||||
}
|
||||
|
||||
void TestKeePass1Reader::testTwofish()
|
||||
{
|
||||
QString name = "Twofish";
|
||||
|
||||
KeePass1Reader reader;
|
||||
|
||||
QString dbFilename = QString("%1/%2.kdb").arg(QString(KEEPASSX_TEST_DATA_DIR), name);
|
||||
|
||||
Database* db = reader.readDatabase(dbFilename, "masterpw", QByteArray());
|
||||
QVERIFY(db);
|
||||
QVERIFY(!reader.hasError());
|
||||
QCOMPARE(db->rootGroup()->children().size(), 1);
|
||||
QCOMPARE(db->rootGroup()->children().at(0)->name(), name);
|
||||
|
||||
delete db;
|
||||
}
|
||||
|
||||
void TestKeePass1Reader::cleanupTestCase()
|
||||
{
|
||||
delete m_db;
|
||||
|
@ -35,6 +35,7 @@ private Q_SLOTS:
|
||||
void testFileKey();
|
||||
void testFileKey_data();
|
||||
void testCompositeKey();
|
||||
void testTwofish();
|
||||
void cleanupTestCase();
|
||||
|
||||
private:
|
||||
|
BIN
tests/data/Twofish.kdb
Normal file
BIN
tests/data/Twofish.kdb
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user