summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2019-11-28 19:42:23 +0100
committerLinus Jahn <lnj@kaidan.im>2020-07-31 15:05:18 +0200
commit5d69aa3ee1214cf689e2357bff8688f2ff138471 (patch)
tree7889ec6c3761977faea4f659d867c8a5ba6a3e35 /tests
parent06f7a24574376fae099f276337f5564d27a5787b (diff)
QCryptographicHash: Add BLAKE2b and BLAKE2s hashing algorithms
BLAKE2 does not specify requirements about specific hash sizes and since QCryptographicHash does not support dynamic hash sizes, only the most common hash sizes could be covered by this. The supported hash sizes were chosen to match the ones supported by the Linux kernel. The new hashing algorithms for QCryptographicHash are: * BLAKE2b (160 bit, 256 bit, 384 bit, 512 bit) * BLAKE2s (128 bit, 160 bit, 224 bit, 256 bit) [ChangeLog][QtCore][QCryptographicHash] Added BLAKE2b and BLAKE2s hashing algorithms. Fixes: QTBUG-78198 Change-Id: Id9e0180a974093982fdf1cdd6180988a2e5e9f4f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
index 3eef7631c8..436734f05a 100644
--- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
+++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
@@ -44,6 +44,8 @@ private slots:
void sha1();
void sha3_data();
void sha3();
+ void blake2_data();
+ void blake2();
void files_data();
void files();
void hashLength();
@@ -264,6 +266,110 @@ void tst_QCryptographicHash::sha3()
QCOMPARE(result, expectedResult);
}
+void tst_QCryptographicHash::blake2_data()
+{
+ QTest::addColumn<QCryptographicHash::Algorithm>("algorithm");
+ QTest::addColumn<QByteArray>("data");
+ QTest::addColumn<QByteArray>("expectedResult");
+
+#define ROW(Tag, Algorithm, Input, Result) \
+ QTest::newRow(Tag) << Algorithm << QByteArrayLiteral(Input) << QByteArray::fromHex(Result)
+
+ // BLAKE2b
+ ROW("blake2b_160_pangram",
+ QCryptographicHash::Blake2b_160,
+ "The quick brown fox jumps over the lazy dog",
+ "3c523ed102ab45a37d54f5610d5a983162fde84f");
+
+ ROW("blake2b_160_pangram_dot",
+ QCryptographicHash::Blake2b_160,
+ "The quick brown fox jumps over the lazy dog.",
+ "d0c8bb0bdd830296d1d4f4348176699ccccc16bb");
+
+ ROW("blake2b_256_pangram",
+ QCryptographicHash::Blake2b_256,
+ "The quick brown fox jumps over the lazy dog",
+ "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9");
+
+ ROW("blake2b_256_pangram_dot",
+ QCryptographicHash::Blake2b_256,
+ "The quick brown fox jumps over the lazy dog.",
+ "69d7d3b0afba81826d27024c17f7f183659ed0812cf27b382eaef9fdc29b5712");
+
+ ROW("blake2b_384_pangram",
+ QCryptographicHash::Blake2b_384,
+ "The quick brown fox jumps over the lazy dog",
+ "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d");
+
+ ROW("blake2b_384_pangram_dot",
+ QCryptographicHash::Blake2b_384,
+ "The quick brown fox jumps over the lazy dog.",
+ "16d65de1a3caf1c26247234c39af636284c7e19ca448c0de788272081410778852c94d9cef6b939968d4f872c7f78337");
+
+ ROW("blake2b_512_pangram",
+ QCryptographicHash::Blake2b_512,
+ "The quick brown fox jumps over the lazy dog",
+ "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918");
+
+ ROW("blake2b_512_pangram_dot",
+ QCryptographicHash::Blake2b_512,
+ "The quick brown fox jumps over the lazy dog.",
+ "87af9dc4afe5651b7aa89124b905fd214bf17c79af58610db86a0fb1e0194622a4e9d8e395b352223a8183b0d421c0994b98286cbf8c68a495902e0fe6e2bda2");
+
+ // BLAKE2s
+ ROW("blake2s_128_pangram",
+ QCryptographicHash::Blake2s_128,
+ "The quick brown fox jumps over the lazy dog",
+ "96fd07258925748a0d2fb1c8a1167a73");
+
+ ROW("blake2s_128_pangram_dot",
+ QCryptographicHash::Blake2s_128,
+ "The quick brown fox jumps over the lazy dog.",
+ "1f298f2e1f9c2490e506c2308f64e7c0");
+
+ ROW("blake2s_160_pangram",
+ QCryptographicHash::Blake2s_160,
+ "The quick brown fox jumps over the lazy dog",
+ "5a604fec9713c369e84b0ed68daed7d7504ef240");
+
+ ROW("blake2s_160_pangram_dot",
+ QCryptographicHash::Blake2s_160,
+ "The quick brown fox jumps over the lazy dog.",
+ "cd4a863226463aac852662d16275d399966e3ffe");
+
+ ROW("blake2s_224_pangram",
+ QCryptographicHash::Blake2s_224,
+ "The quick brown fox jumps over the lazy dog",
+ "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912");
+
+ ROW("blake2s_224_pangram_dot",
+ QCryptographicHash::Blake2s_224,
+ "The quick brown fox jumps over the lazy dog.",
+ "fd1557500ef49f308882969507acd18a13e155c26f8fcd82f9bf2ff7");
+
+ ROW("blake2s_256_pangram",
+ QCryptographicHash::Blake2s_256,
+ "The quick brown fox jumps over the lazy dog",
+ "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812");
+
+ ROW("blake2s_256_pangram_dot",
+ QCryptographicHash::Blake2s_256,
+ "The quick brown fox jumps over the lazy dog.",
+ "95bca6e1b761dca1323505cc629949a0e03edf11633cc7935bd8b56f393afcf2");
+
+#undef ROW
+}
+
+void tst_QCryptographicHash::blake2()
+{
+ QFETCH(QCryptographicHash::Algorithm, algorithm);
+ QFETCH(QByteArray, data);
+ QFETCH(QByteArray, expectedResult);
+
+ const auto result = QCryptographicHash::hash(data, algorithm);
+ QCOMPARE(result, expectedResult);
+}
+
void tst_QCryptographicHash::files_data() {
QTest::addColumn<QString>("filename");
QTest::addColumn<QCryptographicHash::Algorithm>("algorithm");