/* See LICENSE file for copyright and license details. */ #ifdef SUPPORT_BLAKE256 # define TEST # include "../common.h" static struct testcase testcases[] = { {1, 0, "", "716f6e863f744b9ac22c97ec7b76ea5f5908bc5b2f67c61510bfc4751384ea7a"}, {0, 1, "\xff", "9151be4536b8f5a0550713425a55cfeadecf71cdb170c647d9bc2d5d56110cc8"}, {0, 1, "\x7f", "9151be4536b8f5a0550713425a55cfeadecf71cdb170c647d9bc2d5d56110cc8"}, {0, 1, "\x01", "9151be4536b8f5a0550713425a55cfeadecf71cdb170c647d9bc2d5d56110cc8"}, {0, 1, "\xfe", "81a10984912cd57c12e923b46142b2b434dfe1a0ef29c03de05555f9f2fee9b4"}, {0, 1, "\x7e", "81a10984912cd57c12e923b46142b2b434dfe1a0ef29c03de05555f9f2fee9b4"}, {1, 1, "\x00", "81a10984912cd57c12e923b46142b2b434dfe1a0ef29c03de05555f9f2fee9b4"}, {1, 2, "\x03", "eae1614ea36088a8fd69a4614c2d98fada81134baa991aebfb743cd297669b01"}, {1, 3, "\x03", "4ac92b8903f7076563a6309eb9bd386807d28fe721fc8128af86e88967739443"}, {1, 4, "\x01", "c575142b6e471398bf9fc90a5660bb97f24cb106443b76e22b58084e82667b5d"}, {1, 5, "\x12", "45bc790b0180778efe9fd0381528ba9e9ec4460685375e1283e519e338b4c55d"}, {1, 6, "\x0a", "673acd73e1ea3c418e7707cf543155e9dc0c52c6d4aa8a9b0559680b06992d48"}, {1, 7, "\x19", "46bf46a9db7079a34f1b2b4ceffc8236730c2b5ec2a9f0d105ab5b66be9f6fd8"}, {1, 8, "\xcc", "e104256a2bc501f459d03fac96b9014f593e22d30f4de525fa680c3aa189eb4f"}, {1, 9, "\x98\x00", "1088da8ca79a1498f7d4629654307d63715f26edf916c8fb8c09d2039d28c8bc"}, {1, 10, "\x9d\x02", "1b34cb31b73d6966f038cdd3d93fe973776f9f4bd5bd9b1008ae105edc53add3"}, {1, 11, "\xaa\x01", "6df64c36384f863cbed1ccf0a615c04b808b73f35131e3f95adfcb93e54e8df0"}, {1, 12, "\x98\x0c", "37e539c6dfb9c94bc392090a41ae4eca0fe3eff478ef401cf163a73486754ef4"}, {1, 13, "\x50\x0c", "10ec14653844b6cbda11d908680f27de195a00446b773eb64480168074fb9439"}, {1, 14, "\x4d\x24", "8f9d0cb5d596260935d8057c260c218091ba666ac14b1a46f2d918484cfbe173"}, {1, 15, "\xcb\x7b", "891837f7f166cd0603379a2803fe27fed35853f5c4b6feed0fc74b4502d6105c"}, {1, 16, "\x41\xfb", "8f341148be7e354fdf38b693d8c6b4e0bd57301a734f6fd35cd85b8491c3ddcd"}, {1, 17, "\x4f\xf4\x00", "ddfc63311a6e1996b257af4ec0750bcbe400d7d507eea84aee9fc44b88127236"}, {1, 18, "\xfd\x04\x02", "5b452b7b003fab1abe488ba0dca0a6f5945d797a94f52e93d6e921af1a157fc4"}, {1, 19, "\x42\x4d\x00", "6733ca84f1652ff5d5252d4affa42d3ebda3fbd21a9a8fc07297dad28df7273c"}, {1, 20, "\x3f\xde\x07", "1e5c24058d33f16a7cef6ad102e3a19b59e595598dd4ddc2c9b8182abbb89b84"}, {1, 21, "\x33\x57\x16", "29a77b3fa2b97407791da3fa792e40555a2cae9fa85d559ba633ac2e817d6b5e"}, {1, 22, "\x05\x1e\x3e", "3ef17d53fb61fe2f543a935820f244e25cc8c0ae30d9774ff22427a3fb820d7a"}, {1, 23, "\x71\x7f\x31", "b2224450512df4c070084e17f6c8a423c5e22a66a77f4eb5792418832dcb05a0"}, {1, 24, "\x1f\x87\x7c", "bc334d1069099f10c601883ac6f3e7e9787c6aa53171f76a21923cc5ad3ab937"}, {1, 25, "\xeb\x35\xcf\x01", "7360eb4415d316866b8a748fcd90b7a014c6d62a18218a48cdf681538dcac8ec"}, {1, 26, "\xb4\x06\xc4\x01", "9e4a8d15be6cfd06425f224035a90ccb5fc8bf92e4d315bc6efe3d9c93085943"}, {1, 27, "\xce\xe8\x80\x02", "643cf377e140bb1f5d2710927c84ab23b0c258b6c0ab47da4b592180086c24d2"}, {1, 28, "\xc5\x84\xdb\x0e", "94b4d7f4830fda2e6ba7346f38456d28346589dec8b7dc6e61e3ec3580243c5e"}, {1, 29, "\x53\x58\x7b\x13", "2d7508d69c7fb9bfacf35fafc118840b8ad42fabae5f27adc9d74154f2e3a78a"}, {1, 30, "\x69\xa3\x05\x0d", "eec86da7600c3953f088084364b37a3d2bb6522876b82f9cf9cfed764746d53d"}, {1, 31, "\xc9\x37\x5e\x73", "7ff30cb54acd2e019c3664c42f37002d67132098d313525e5bced93470d19a56"}, {1, 32, "\xc1\xec\xfd\xfc", "b672a16f53982bab1e77685b71c0a5f6703ffd46a1c834be69f614bd128d658e"}, {1, 33, "\x8d\x73\xe8\xa2\x01", "3b171d80684fcbb88067e7519e0af3ab3d378254d36633b3eb8585553717ecf0"}, {1, 34, "\x06\xf2\x52\x20\x01", "d71133d28291531730403dbc363bf3d5a4c3db80861b7c3afbc4c769fedfd3aa"}, {1, 35, "\x3e\xf6\xc3\x6f\x04", "2e9830df74711da1a21e815aa6ab37013ebded7de7088ae8d5fdb5174440fe0b"}, {1, 36, "\x01\x27\xa1\xd3\x02", "5ba9f0532fbd0b44f0f7efd9988aa2e062a813797c732242ea5239f571adfb0f"}, {1, 37, "\x6a\x6a\xb6\xc2\x08", "e03567eefd4e515a73999fac87deb90726bdc488f4be6aa8a974c7b4ee13fc65"}, {1, 38, "\xaf\x31\x75\xe1\x06", "238036d9eeb9b09d9c9703b484833cc88097f27e34b8a94bef9f5e121b6d5575"}, {1, 39, "\xb6\x66\x09\xed\x61", "284e01f8b5604db347cd9d4ab95cc8d62d3640aeaf7502a2439fe780c598ba39"}, {1, 40, "\x21\xf1\x34\xac\x57", "d9134b2899057a7d8d320cc99e3e116982bc99d3c69d260a7f1ed3da8be68d99"}, {1, 41, "\x3d\xc2\xaa\xdf\xfc\x01", "3e64d5852d9a09ea76007a7b159430c3715598017850ec288316e13b80fd61c7"}, {1, 42, "\x92\x02\x73\x6d\x22\x02", "95f5bcf07e8a6c02b26f9fe29a5deb7faa5c03ab0e6180239924f5d48c7125af"}, {1, 43, "\xf2\x19\xbd\x62\x98\x04", "0fcf4c343c9d94bf3dea22069a28d23ff953bde89cd0dee4d1a521d4a302f8a3"}, {1, 44, "\xf3\x51\x1e\xe2\xc4\x0d", "c32364fa782462bc3a3af38e03fb4f052bd238ab756eaabdd5f8000006446184"}, {1, 45, "\x3e\xca\xb6\xbf\x77\x04", "511150cbab4c6be4d59d926b093a2d10fb6d9fb06169f47af2f1d75c07463428"}, {1, 46, "\xcd\x62\xf6\x88\xf4\x19", "a08519ce60cfef0554e8cd1a4d3cbe82504fe97b8b933cfccff5faac85bc787b"}, {1, 47, "\xc2\xcb\xaa\x33\xa9\x1f", "cc8eb0c743b2440399632474ba84980bebc9f6eedbbce3e31fdc497e0ba32d9d"}, {1, 48, "\xc6\xf5\x0b\xb7\x4e\x29", "637923bd29a35aa3ecbbd2a50549fc32c14cf0fdcaf41c3194dd7414fd224815"}, {1, 49, "\x79\xf1\xb4\xcc\xc6\x2a\x00", "106cd7e18e3bd16353cf561411d87b609536856d57180155b60d7bc0a73b9d45"} }; #else # define TEST_UNSUPPORTED # include "../common.h" #endif static int kat_test(void) { TEST_MAIN("BLAKE256", BLAKE256, 1); } int main(void) { #ifdef SUPPORT_BLAKE256 struct libhashsum_hasher hasher1, hasher2; char salt1[16], salt2[16]; #endif int r = kat_test(); if (r) return r; #ifdef SUPPORT_BLAKE256 memset(salt1, 0, sizeof(salt1)); memset(salt2, 0xAB, sizeof(salt2)); ASSERT(!libhashsum_init_blake256_hasher(&hasher1, NULL)); ASSERT(!libhashsum_init_blake256_hasher(&hasher2, salt1)); ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE256")); ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE256")); ASSERT(!hasher1.finalise_const(&hasher1, NULL, 0, 0)); ASSERT(!hasher2.finalise_const(&hasher2, NULL, 0, 0)); ASSERT(!memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size)); ASSERT(!libhashsum_init_blake256_hasher(&hasher1, NULL)); ASSERT(!libhashsum_init_blake256_hasher(&hasher2, salt1)); ASSERT(!hasher1.finalise_const(&hasher1, "testdata", 8U, 0)); ASSERT(!hasher2.finalise_const(&hasher2, "testdata", 8U, 0)); ASSERT(!memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size)); ASSERT(!libhashsum_init_blake256_hasher(&hasher1, salt1)); ASSERT(!libhashsum_init_blake256_hasher(&hasher2, salt2)); ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE256")); ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE256[salt=abababababababababababababababab]")); ASSERT(!hasher1.finalise_const(&hasher1, NULL, 0, 0)); ASSERT(!hasher2.finalise_const(&hasher2, NULL, 0, 0)); ASSERT(memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size)); ASSERT(!libhashsum_init_blake256_hasher(&hasher1, salt1)); ASSERT(!libhashsum_init_blake256_hasher(&hasher2, salt2)); ASSERT(!hasher1.finalise_const(&hasher1, "testdata", 8U, 0)); ASSERT(!hasher2.finalise_const(&hasher2, "testdata", 8U, 0)); ASSERT(memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size)); ASSERT(!libhashsum_init_hasher_from_string(&hasher1, "BLAKE256[salt=00000000000000000000000000000000]")); ASSERT(!libhashsum_init_hasher_from_string(&hasher2, "BLAKE256[salt=abababababababababababababababab]")); ASSERT(!strcmp(hasher1.algorithm_string, "BLAKE256")); ASSERT(!strcmp(hasher2.algorithm_string, "BLAKE256[salt=abababababababababababababababab]")); ASSERT(!hasher1.finalise_const(&hasher1, NULL, 0, 0)); ASSERT(!hasher2.finalise_const(&hasher2, NULL, 0, 0)); ASSERT(memcmp(hasher1.hash_output, hasher2.hash_output, hasher1.hash_size)); #endif return 0; }