aboutsummaryrefslogblamecommitdiffstats
path: root/shake128.c
blob: d0ac638c9089b7f35be4c5ace21d79a2bfd87bda (plain) (tree)























































































                                                                                                    
/* See LICENSE file for copyright and license details. */
#ifdef SUPPORT_SHAKE
# define TEST
# include "common.h"


#define MSG5 "\x13"
#define MSG30 "\x53\x58\x7B\x19"
#define MSG1600_32 "\xA3\xA3\xA3\xA3"
#define MSG1600_160 MSG1600_32 MSG1600_32 MSG1600_32 MSG1600_32 MSG1600_32
#define MSG1600_800 MSG1600_160 MSG1600_160 MSG1600_160 MSG1600_160 MSG1600_160
#define MSG1600 MSG1600_800 MSG1600_800
#define MSG1605 MSG1600_800 MSG1600_800 "\x03"
#define MSG1630 MSG1600_800 MSG1600_800 "\xA3\xA3\xA3\x23"


static struct testcase testcases[] = {
	{1, 0, "",      "7f9c2ba4e88f827d616045507605853e"},
	{1, 5, MSG5,    "2e0abfba83e6720bfbc225ff6b7ab9ff"},
	{1, 6, MSG30,   "6d5d39c55f3cca567feaf422dc64ba17"},
	{1, 0, MSG1600, "131ab8d2b594946b9c81333f9bb6e0ce"},
	{1, 5, MSG1605, "4ac38ebd1678b4a452792c5673f9777d"},
	{1, 6, MSG1630, "89846dc776ac0f014572ea79f5607734"}
};


#else
# define TEST_UNSUPPORTED
# include "common.h"
#endif


static int
main_test(void)
{
	TEST_MAIN("SHAKE128", SHAKE128);
}


int
main(void)
{
#ifdef SUPPORT_SHAKE
	struct libhashsum_hasher hasher;
	char hexsum[1024];
#endif

	int r = main_test();
	if (r)
		return r;

	ASSERT(!libhashsum_init_shake128_hasher(&hasher, 8));
	ASSERT(!strcmp(hasher.algorithm_string, "SHAKE128[n=8]"));
	ASSERT(!hasher.finalise_const(&hasher, "", 0, 0));
	ASSERT(hasher.hash_size == 1);
	hex(hexsum, hasher.hash_output, hasher.hash_size);
	ASSERT(!strcmp(hexsum, "7f"));

	ASSERT(!libhashsum_init_shake128_hasher(&hasher, 32));
	ASSERT(!strcmp(hasher.algorithm_string, "SHAKE128[n=32]"));
	ASSERT(!hasher.finalise_const(&hasher, "", 0, 0));
	ASSERT(hasher.hash_size == 4);
	hex(hexsum, hasher.hash_output, hasher.hash_size);
	ASSERT(!strcmp(hexsum, "7f9c2ba4"));

	ASSERT(!libhashsum_init_shake128_hasher(&hasher, 32));
	ASSERT(!strcmp(hasher.algorithm_string, "SHAKE128[n=32]"));
	ASSERT(!hasher.finalise_const(&hasher, MSG1600, 1600/8, 0));
	ASSERT(hasher.hash_size == 4);
	hex(hexsum, hasher.hash_output, hasher.hash_size);
	ASSERT(!strcmp(hexsum, "131ab8d2"));

	ASSERT(!libhashsum_init_shake128_hasher(&hasher, 128));
	ASSERT(!strcmp(hasher.algorithm_string, "SHAKE128"));
	ASSERT(!hasher.finalise_const(&hasher, MSG1600, 1600/8, 0));
	ASSERT(hasher.hash_size == 128/8);
	hex(hexsum, hasher.hash_output, hasher.hash_size);
	ASSERT(!strcmp(hexsum, "131ab8d2b594946b9c81333f9bb6e0ce"));

	ASSERT(!libhashsum_init_shake128_hasher(&hasher, 256));
	ASSERT(!strcmp(hasher.algorithm_string, "SHAKE128[n=256]"));
	ASSERT(!hasher.finalise_const(&hasher, MSG1600, 1600/8, 0));
	ASSERT(hasher.hash_size == 256/8);
	hex(hexsum, hasher.hash_output, hasher.hash_size);
	ASSERT(!strcmp(hexsum, "131ab8d2b594946b9c81333f9bb6e0ce75c3b93104fa3469d3917457385da037"));

	return 0;
}