Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorangelsl <angelsl@in04.sg>2017-11-12 21:23:01 +0300
committerJonathan White <support@dmapps.us>2018-01-13 22:23:26 +0300
commit6a0d05e1ef6c15a77c543ecba927ad77fb2f395c (patch)
tree673989b25267da1fa16e1b0b9d7506886ed16a6c /tests
parent4532108678e5b86cd064c9d234db55055a86a17c (diff)
Add support for various algorithms for kdbx4
* Add SHA512 support to CryptoHash * Add ChaCha20 support * Add HMAC support * Add new HmacBlockStream, used in KDBX 4 * Add support for ChaCha20 protected stream
Diffstat (limited to 'tests')
-rw-r--r--tests/TestCryptoHash.cpp13
-rw-r--r--tests/TestKeePass2RandomStream.cpp2
-rw-r--r--tests/TestSymmetricCipher.cpp50
-rw-r--r--tests/TestSymmetricCipher.h1
4 files changed, 65 insertions, 1 deletions
diff --git a/tests/TestCryptoHash.cpp b/tests/TestCryptoHash.cpp
index c166f5595..469ce8192 100644
--- a/tests/TestCryptoHash.cpp
+++ b/tests/TestCryptoHash.cpp
@@ -44,4 +44,17 @@ void TestCryptoHash::test()
cryptoHash3.addData(QString("ssX").toLatin1());
QCOMPARE(cryptoHash3.result(),
QByteArray::fromHex("0b56e5f65263e747af4a833bd7dd7ad26a64d7a4de7c68e52364893dca0766b4"));
+
+ CryptoHash cryptoHash2(CryptoHash::Sha512);
+ QCOMPARE(cryptoHash2.result(),
+ QByteArray::fromHex("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"));
+
+ QByteArray result3 = CryptoHash::hash(source2, CryptoHash::Sha512);
+ QCOMPARE(result3, QByteArray::fromHex("0d41b612584ed39ff72944c29494573e40f4bb95283455fae2e0be1e3565aa9f48057d59e6ffd777970e282871c25a549a2763e5b724794f312c97021c42f91d"));
+
+ CryptoHash cryptoHash4(CryptoHash::Sha512);
+ cryptoHash4.addData(QString("KeePa").toLatin1());
+ cryptoHash4.addData(QString("ssX").toLatin1());
+ QCOMPARE(cryptoHash4.result(),
+ QByteArray::fromHex("0d41b612584ed39ff72944c29494573e40f4bb95283455fae2e0be1e3565aa9f48057d59e6ffd777970e282871c25a549a2763e5b724794f312c97021c42f91d"));
}
diff --git a/tests/TestKeePass2RandomStream.cpp b/tests/TestKeePass2RandomStream.cpp
index 03dfbe507..bef7af540 100644
--- a/tests/TestKeePass2RandomStream.cpp
+++ b/tests/TestKeePass2RandomStream.cpp
@@ -58,7 +58,7 @@ void TestKeePass2RandomStream::test()
}
- KeePass2RandomStream randomStream;
+ KeePass2RandomStream randomStream(KeePass2::Salsa20);
bool ok;
QVERIFY(randomStream.init(key));
QByteArray randomStreamData;
diff --git a/tests/TestSymmetricCipher.cpp b/tests/TestSymmetricCipher.cpp
index c1e947063..bfa3c3db8 100644
--- a/tests/TestSymmetricCipher.cpp
+++ b/tests/TestSymmetricCipher.cpp
@@ -342,6 +342,56 @@ void TestSymmetricCipher::testSalsa20()
QCOMPARE(cipherTextB.mid(448, 64), expectedCipherText4);
}
+void TestSymmetricCipher::testChaCha20()
+{
+ // https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
+ bool ok;
+
+ {
+ QByteArray key = QByteArray::fromHex("0000000000000000000000000000000000000000000000000000000000000000");
+ QByteArray iv = QByteArray::fromHex("0000000000000000");
+ SymmetricCipher cipher(SymmetricCipher::ChaCha20, SymmetricCipher::Stream, SymmetricCipher::Encrypt);
+ QVERIFY(cipher.init(key, iv));
+ QCOMPARE(cipher.process(QByteArray(64, 0), &ok),
+ QByteArray::fromHex(
+ "76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee6586"));
+ QVERIFY(ok);
+ }
+
+ {
+ QByteArray key = QByteArray::fromHex("0000000000000000000000000000000000000000000000000000000000000001");
+ QByteArray iv = QByteArray::fromHex("0000000000000000");
+ SymmetricCipher cipher(SymmetricCipher::ChaCha20, SymmetricCipher::Stream, SymmetricCipher::Encrypt);
+ QVERIFY(cipher.init(key, iv));
+ QCOMPARE(cipher.process(QByteArray(64, 0), &ok),
+ QByteArray::fromHex(
+ "4540f05a9f1fb296d7736e7b208e3c96eb4fe1834688d2604f450952ed432d41bbe2a0b6ea7566d2a5d1e7e20d42af2c53d792b1c43fea817e9ad275ae546963"));
+ QVERIFY(ok);
+ }
+
+ {
+ QByteArray key = QByteArray::fromHex("0000000000000000000000000000000000000000000000000000000000000000");
+ QByteArray iv = QByteArray::fromHex("0000000000000001");
+ SymmetricCipher cipher(SymmetricCipher::ChaCha20, SymmetricCipher::Stream, SymmetricCipher::Encrypt);
+ QVERIFY(cipher.init(key, iv));
+ QCOMPARE(cipher.process(QByteArray(60, 0), &ok),
+ QByteArray::fromHex(
+ "de9cba7bf3d69ef5e786dc63973f653a0b49e015adbff7134fcb7df137821031e85a050278a7084527214f73efc7fa5b5277062eb7a0433e445f41e3"));
+ QVERIFY(ok);
+ }
+
+ {
+ QByteArray key = QByteArray::fromHex("0000000000000000000000000000000000000000000000000000000000000000");
+ QByteArray iv = QByteArray::fromHex("0100000000000000");
+ SymmetricCipher cipher(SymmetricCipher::ChaCha20, SymmetricCipher::Stream, SymmetricCipher::Encrypt);
+ QVERIFY(cipher.init(key, iv));
+ QCOMPARE(cipher.process(QByteArray(64, 0), &ok),
+ QByteArray::fromHex(
+ "ef3fdfd6c61578fbf5cf35bd3dd33b8009631634d21e42ac33960bd138e50d32111e4caf237ee53ca8ad6426194a88545ddc497a0b466e7d6bbdb0041b2f586b"));
+ QVERIFY(ok);
+ }
+}
+
void TestSymmetricCipher::testPadding()
{
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
diff --git a/tests/TestSymmetricCipher.h b/tests/TestSymmetricCipher.h
index cad13841a..40e3b49cf 100644
--- a/tests/TestSymmetricCipher.h
+++ b/tests/TestSymmetricCipher.h
@@ -34,6 +34,7 @@ private slots:
void testTwofish256CbcEncryption();
void testTwofish256CbcDecryption();
void testSalsa20();
+ void testChaCha20();
void testPadding();
void testStreamReset();
};