static int calc_and_compare_hash_384(const uint8_t *msg, size_t msg_len, const uint8_t *expected) { static unsigned char hash[SHA3_384_DIGEST_LENGTH]; sha3_384(hash, msg, msg_len); return (memcmp(expected, hash, sizeof(hash)) == 0); }
static void sha3_384_t (ut_test_t *const t) { const char *const msg = "abc"; const char *const expected_msg_digest_as_string = "ec01498288516fc9" "26459f58e2c6ad8d" "f9b473cb0fc08c25" "96da7cf0e49be4b2" "98d88cea927ac7f5" "39f1edf228376d25"; char msg_digest[sha3_384_digest_lenght]; char msg_digest_as_string[sha3_384_digest_lenght * 2 + 1]; // Two hex digit per byte plus string termination. size_t msg_len = strlen(msg); sha3_384(msg_digest, msg, msg_len); sha3_msg_digest_to_string(msg_digest_as_string, msg_digest, sha3_384_digest_lenght); ut_assert(t, strcmp(expected_msg_digest_as_string, msg_digest_as_string) == 0); }
int sha3_test(const unsigned char *input, unsigned long input_bits, int print) { unsigned char *hash; hash = sha3_224(input, input_bits); if (hash) { if (print) { sha3_print_hash(hash, 224UL, "sha3_224(input, %lu) =", input_bits); } free(hash); } else { return EXIT_FAILURE; } hash = sha3_256(input, input_bits); if (hash) { if (print) { sha3_print_hash(hash, 256UL, "sha3_256(input, %lu) =", input_bits); } free(hash); } else { return EXIT_FAILURE; } hash = sha3_384(input, input_bits); if (hash) { if (print) { sha3_print_hash(hash, 384UL, "sha3_384(input, %lu) =", input_bits); } free(hash); } else { return EXIT_FAILURE; } hash = sha3_512(input, input_bits); if (hash) { if (print) { sha3_print_hash(hash, 512UL, "sha3_512(input, %lu) =", input_bits); } free(hash); } else { return EXIT_FAILURE; } return EXIT_SUCCESS; }