int sha3_384_test(void) { #ifndef LTC_TEST return CRYPT_NOP; #else unsigned char buf[200], hash[384 / 8]; int i; hash_state c; const unsigned char c1 = 0xa3; const unsigned char sha3_384_0xa3_200_times[384 / 8] = { 0x18, 0x81, 0xde, 0x2c, 0xa7, 0xe4, 0x1e, 0xf9, 0x5d, 0xc4, 0x73, 0x2b, 0x8f, 0x5f, 0x00, 0x2b, 0x18, 0x9c, 0xc1, 0xe4, 0x2b, 0x74, 0x16, 0x8e, 0xd1, 0x73, 0x26, 0x49, 0xce, 0x1d, 0xbc, 0xdd, 0x76, 0x19, 0x7a, 0x31, 0xfd, 0x55, 0xee, 0x98, 0x9f, 0x2d, 0x70, 0x50, 0xdd, 0x47, 0x3e, 0x8f }; XMEMSET(buf, c1, sizeof(buf)); /* SHA3-384 as a single buffer. [FIPS 202] */ sha3_384_init(&c); sha3_process(&c, buf, sizeof(buf)); sha3_done(&c, hash); if (compare_testvector(hash, sizeof(hash), sha3_384_0xa3_200_times, sizeof(sha3_384_0xa3_200_times), "SHA3-384", 0)) { return CRYPT_FAIL_TESTVECTOR; } /* SHA3-384 in two steps. [FIPS 202] */ sha3_384_init(&c); sha3_process(&c, buf, sizeof(buf) / 2); sha3_process(&c, buf + sizeof(buf) / 2, sizeof(buf) / 2); sha3_done(&c, hash); if (compare_testvector(hash, sizeof(hash), sha3_384_0xa3_200_times, sizeof(sha3_384_0xa3_200_times), "SHA3-384", 1)) { return CRYPT_FAIL_TESTVECTOR; } /* SHA3-384 byte-by-byte: 200 steps. [FIPS 202] */ i = 200; sha3_384_init(&c); while (i--) { sha3_process(&c, &c1, 1); } sha3_done(&c, hash); if (compare_testvector(hash, sizeof(hash), sha3_384_0xa3_200_times, sizeof(sha3_384_0xa3_200_times), "SHA3-384", 2)) { return CRYPT_FAIL_TESTVECTOR; } return CRYPT_OK; #endif }
static int calc_steps_and_compare_hash_384(const uint8_t *msg1, size_t msg1_len, const uint8_t *msg2, size_t msg2_len, const uint8_t *expected) { static unsigned char hash[SHA3_384_DIGEST_LENGTH]; keccak_state_t state; sha3_384_init(&state); sha3_update(&state, msg1, msg1_len); sha3_update(&state, msg2, msg2_len); sha3_384_final(&state, hash); return (memcmp(expected, hash, sizeof(hash)) == 0); }