summaryrefslogtreecommitdiff
path: root/tests/unit/core/test-core-crypto.cpp
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-09-10 14:02:58 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-09-13 15:09:34 +0200
commit684bfd64c6893d12b6a4f82fe61e33e7d14e0a4d (patch)
tree21e8df9781cd283b0f34e0710a98ed5b7d121b0e /tests/unit/core/test-core-crypto.cpp
parent29c4aa4620288991a1baf75a95e42dadb1cdf5dd (diff)
downloadweechat-684bfd64c6893d12b6a4f82fe61e33e7d14e0a4d.zip
api: add algorithms `sha512-224`, `sha512-256`, blake2b-*` and `blake2s-*` in hash functions (issue #2008)
Diffstat (limited to 'tests/unit/core/test-core-crypto.cpp')
-rw-r--r--tests/unit/core/test-core-crypto.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/unit/core/test-core-crypto.cpp b/tests/unit/core/test-core-crypto.cpp
index 4e6894063..df1fdf267 100644
--- a/tests/unit/core/test-core-crypto.cpp
+++ b/tests/unit/core/test-core-crypto.cpp
@@ -45,6 +45,10 @@ extern "C"
#define DATA_HASH_SHA512 "4469190d4e0d1fdc0afb6f408d9873c89b8ce89cc4db79fe0" \
"58255c55ad6821fa5e9bb068f9e578c8ae7cc825d85ff99c439d59e439bc589d95620a" \
"1e6b8ae6e"
+#define DATA_HASH_SHA512_224 "5c442c9389a2b72103e16a863e753f4ca98f232ba13e6" \
+ "946df97f955"
+#define DATA_HASH_SHA512_256 "d9157dc21fffaaea696a868d2c5b29ca7b622c9bcdd7d" \
+ "55031589c4a840d43cc"
#define DATA_HASH_SHA3_224 "26432a3a4ea998790be43386b1de417f88be43146a4af98" \
"2a9627d10"
#define DATA_HASH_SHA3_256 "226e3830306711cf653c1661765c304b37038e7457c35dd" \
@@ -54,6 +58,20 @@ extern "C"
#define DATA_HASH_SHA3_512 "31dfb5fc8f30ac7007acddc4fce562d408706833d0d2af2" \
"e5f61a179099592927ff7d100e278406c7f98d42575001e26e153b135c21f7ef5b00c8" \
"cef93ca048d"
+#define DATA_HASH_BLAKE2B_160 "4b69099962d678140e7c22f3f98edad60432ed3d"
+#define DATA_HASH_BLAKE2B_256 "21b3e26905be39894328222c10b009a64633109db228" \
+ "df8222d1ff61cf6bd6a8"
+#define DATA_HASH_BLAKE2B_384 "a3e35d3ac1b866a4836cefe4c29610792c30c5380dcf" \
+ "56fdffa29397b92110fba0d24df470f0aa4563d12f3e31511bab"
+#define DATA_HASH_BLAKE2B_512 "ef694e494cf17a4c5e43644d185ee48e2f16ec85e13d" \
+ "bd22dfcc415c7eb187baa08befe3422d630de486f07d417551730db8d29944c151bdfe" \
+ "d016e84510565c"
+#define DATA_HASH_BLAKE2S_128 "b0c4131eab265ea16b7b8b4770ac7b7d"
+#define DATA_HASH_BLAKE2S_160 "02d2dde62d0512368041ddbbda348404f3c8d528"
+#define DATA_HASH_BLAKE2S_224 "2f25961aff8a79b4ac9a1cfd956d2b590bb900466660" \
+ "0d595820acaf"
+#define DATA_HASH_BLAKE2S_256 "f0fa555b88a92ec73b25527da818338fcf295449e6c0" \
+ "04b8b0ec392e0fc44d7c"
/* Hash PBKDF2 */
#define DATA_HASH_SALT "this is a salt of 32 bytes xxxxx"
@@ -80,6 +98,10 @@ extern "C"
#define DATA_HMAC_SHA512 "940e5c280c08cd858f79a6085b4bdc54710ed339dd1008fa2" \
"1643b7bbeea8a5f61c77f395708505461af62776c9cb7be1c263f39055eb8478190cd8" \
"0ea5b0850"
+#define DATA_HMAC_SHA512_224 "521860f56b6c429a20357055dd1f18ea706543c2e2bab" \
+ "be06ff8c610"
+#define DATA_HMAC_SHA512_256 "1da19faaa2b3fca54a08c6694123c465e7da76ad8c672" \
+ "a5ad323e824e1c3b523"
#define DATA_HMAC_SHA3_224 "a08c7f1598ecc7ea54feeb920ef90b3748d59b3203caa74" \
"7316eb2d4"
#define DATA_HMAC_SHA3_256 "21aca280bc1ac1fa261b1169a321eb7a49e38a8ddec66a8" \
@@ -225,12 +247,26 @@ TEST(CoreCrypto, GetHashAlgo)
LONGS_EQUAL(GCRY_MD_SHA256, weecrypto_get_hash_algo ("sha256"));
LONGS_EQUAL(GCRY_MD_SHA384, weecrypto_get_hash_algo ("sha384"));
LONGS_EQUAL(GCRY_MD_SHA512, weecrypto_get_hash_algo ("sha512"));
+#if GCRYPT_VERSION_NUMBER >= 0x010904
+ LONGS_EQUAL(GCRY_MD_SHA512_224, weecrypto_get_hash_algo ("sha512-224"));
+ LONGS_EQUAL(GCRY_MD_SHA512_256, weecrypto_get_hash_algo ("sha512-256"));
+#endif
#if GCRYPT_VERSION_NUMBER >= 0x010700
LONGS_EQUAL(GCRY_MD_SHA3_224, weecrypto_get_hash_algo ("sha3-224"));
LONGS_EQUAL(GCRY_MD_SHA3_256, weecrypto_get_hash_algo ("sha3-256"));
LONGS_EQUAL(GCRY_MD_SHA3_384, weecrypto_get_hash_algo ("sha3-384"));
LONGS_EQUAL(GCRY_MD_SHA3_512, weecrypto_get_hash_algo ("sha3-512"));
#endif
+#if GCRYPT_VERSION_NUMBER >= 0x010800
+ LONGS_EQUAL(GCRY_MD_BLAKE2B_160, weecrypto_get_hash_algo ("blake2b-160"));
+ LONGS_EQUAL(GCRY_MD_BLAKE2B_256, weecrypto_get_hash_algo ("blake2b-256"));
+ LONGS_EQUAL(GCRY_MD_BLAKE2B_384, weecrypto_get_hash_algo ("blake2b-384"));
+ LONGS_EQUAL(GCRY_MD_BLAKE2B_512, weecrypto_get_hash_algo ("blake2b-512"));
+ LONGS_EQUAL(GCRY_MD_BLAKE2S_128, weecrypto_get_hash_algo ("blake2s-128"));
+ LONGS_EQUAL(GCRY_MD_BLAKE2S_160, weecrypto_get_hash_algo ("blake2s-160"));
+ LONGS_EQUAL(GCRY_MD_BLAKE2S_224, weecrypto_get_hash_algo ("blake2s-224"));
+ LONGS_EQUAL(GCRY_MD_BLAKE2S_256, weecrypto_get_hash_algo ("blake2s-256"));
+#endif
}
/*
@@ -259,12 +295,26 @@ TEST(CoreCrypto, Hash)
WEE_CHECK_HASH(1, DATA_HASH_SHA256, data, data_size, GCRY_MD_SHA256);
WEE_CHECK_HASH(1, DATA_HASH_SHA384, data, data_size, GCRY_MD_SHA384);
WEE_CHECK_HASH(1, DATA_HASH_SHA512, data, data_size, GCRY_MD_SHA512);
+#if GCRYPT_VERSION_NUMBER >= 0x010904
+ WEE_CHECK_HASH(1, DATA_HASH_SHA512_224, data, data_size, GCRY_MD_SHA512_224);
+ WEE_CHECK_HASH(1, DATA_HASH_SHA512_256, data, data_size, GCRY_MD_SHA512_256);
+#endif
#if GCRYPT_VERSION_NUMBER >= 0x010700
WEE_CHECK_HASH(1, DATA_HASH_SHA3_224, data, data_size, GCRY_MD_SHA3_224);
WEE_CHECK_HASH(1, DATA_HASH_SHA3_256, data, data_size, GCRY_MD_SHA3_256);
WEE_CHECK_HASH(1, DATA_HASH_SHA3_384, data, data_size, GCRY_MD_SHA3_384);
WEE_CHECK_HASH(1, DATA_HASH_SHA3_512, data, data_size, GCRY_MD_SHA3_512);
#endif
+#if GCRYPT_VERSION_NUMBER >= 0x010800
+ WEE_CHECK_HASH(1, DATA_HASH_BLAKE2B_160, data, data_size, GCRY_MD_BLAKE2B_160);
+ WEE_CHECK_HASH(1, DATA_HASH_BLAKE2B_256, data, data_size, GCRY_MD_BLAKE2B_256);
+ WEE_CHECK_HASH(1, DATA_HASH_BLAKE2B_384, data, data_size, GCRY_MD_BLAKE2B_384);
+ WEE_CHECK_HASH(1, DATA_HASH_BLAKE2B_512, data, data_size, GCRY_MD_BLAKE2B_512);
+ WEE_CHECK_HASH(1, DATA_HASH_BLAKE2S_128, data, data_size, GCRY_MD_BLAKE2S_128);
+ WEE_CHECK_HASH(1, DATA_HASH_BLAKE2S_160, data, data_size, GCRY_MD_BLAKE2S_160);
+ WEE_CHECK_HASH(1, DATA_HASH_BLAKE2S_224, data, data_size, GCRY_MD_BLAKE2S_224);
+ WEE_CHECK_HASH(1, DATA_HASH_BLAKE2S_256, data, data_size, GCRY_MD_BLAKE2S_256);
+#endif
}
/*
@@ -299,11 +349,25 @@ TEST(CoreCrypto, HashFile)
WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA384, filename, GCRY_MD_SHA384);
WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA512, filename, GCRY_MD_SHA512);
#if GCRYPT_VERSION_NUMBER >= 0x010700
+ WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA512_224, filename, GCRY_MD_SHA512_224);
+ WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA512_256, filename, GCRY_MD_SHA512_256);
+#endif
+#if GCRYPT_VERSION_NUMBER >= 0x010700
WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA3_224, filename, GCRY_MD_SHA3_224);
WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA3_256, filename, GCRY_MD_SHA3_256);
WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA3_384, filename, GCRY_MD_SHA3_384);
WEE_CHECK_HASH_FILE(1, DATA_HASH_SHA3_512, filename, GCRY_MD_SHA3_512);
#endif
+#if GCRYPT_VERSION_NUMBER >= 0x010800
+ WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2B_160, filename, GCRY_MD_BLAKE2B_160);
+ WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2B_256, filename, GCRY_MD_BLAKE2B_256);
+ WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2B_384, filename, GCRY_MD_BLAKE2B_384);
+ WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2B_512, filename, GCRY_MD_BLAKE2B_512);
+ WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2S_128, filename, GCRY_MD_BLAKE2S_128);
+ WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2S_160, filename, GCRY_MD_BLAKE2S_160);
+ WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2S_224, filename, GCRY_MD_BLAKE2S_224);
+ WEE_CHECK_HASH_FILE(1, DATA_HASH_BLAKE2S_256, filename, GCRY_MD_BLAKE2S_256);
+#endif
unlink (filename);
free (filename);
@@ -382,6 +446,10 @@ TEST(CoreCrypto, Hmac)
WEE_CHECK_HMAC(1, DATA_HMAC_SHA256, key, key_size, msg, msg_size, GCRY_MD_SHA256);
WEE_CHECK_HMAC(1, DATA_HMAC_SHA384, key, key_size, msg, msg_size, GCRY_MD_SHA384);
WEE_CHECK_HMAC(1, DATA_HMAC_SHA512, key, key_size, msg, msg_size, GCRY_MD_SHA512);
+#if GCRYPT_VERSION_NUMBER >= 0x010904
+ WEE_CHECK_HMAC(1, DATA_HMAC_SHA512_224, key, key_size, msg, msg_size, GCRY_MD_SHA512_224);
+ WEE_CHECK_HMAC(1, DATA_HMAC_SHA512_256, key, key_size, msg, msg_size, GCRY_MD_SHA512_256);
+#endif
#if GCRYPT_VERSION_NUMBER >= 0x010700
WEE_CHECK_HMAC(1, DATA_HMAC_SHA3_224, key, key_size, msg, msg_size, GCRY_MD_SHA3_224);
WEE_CHECK_HMAC(1, DATA_HMAC_SHA3_256, key, key_size, msg, msg_size, GCRY_MD_SHA3_256);