aboutsummaryrefslogblamecommitdiffstats
path: root/t/shake512.c
blob: 705e3b4a8b3c439b6917b247172b570853392a50 (plain) (tree)
1
2
3
4


                                                         
                       



















                                                                               
                       





               
                                           























































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


#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


static struct testcase testcases[] = {
	{1, 0, "",
	 "ae1b4eea1eaf5ea633e66045f03ff11b8b7d3193119075442117bd786dfd939f"
	 "25a53a30fae503488d42683c1917b3964f6b1cf5d27c2b40cbaf53c5b749666a"},
	{1, 0, MSG1600,
	 "9701303d390f51968c25b6eee54816d19ab149a1c06b0625940bb8e04a1ceccd"
	 "d88010234f53abbbaf181f49761a3ecefaee56de7b59b5aaf0031e3c1552c9ac"}
};


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


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


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_shake512_hasher(&hasher, 8));
	ASSERT(!strcmp(hasher.algorithm_string, "SHAKE512[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, "ae"));

	ASSERT(!libhashsum_init_shake512_hasher(&hasher, 32));
	ASSERT(!strcmp(hasher.algorithm_string, "SHAKE512[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, "ae1b4eea"));

	ASSERT(!libhashsum_init_shake512_hasher(&hasher, 32));
	ASSERT(!strcmp(hasher.algorithm_string, "SHAKE512[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, "9701303d"));

	ASSERT(!libhashsum_init_shake512_hasher(&hasher, 512));
	ASSERT(!strcmp(hasher.algorithm_string, "SHAKE512"));
	ASSERT(!hasher.finalise_const(&hasher, MSG1600, 1600/8, 0));
	ASSERT(hasher.hash_size == 512/8);
	hex(hexsum, hasher.hash_output, hasher.hash_size);
	ASSERT(!strcmp(hexsum, "9701303d390f51968c25b6eee54816d19ab149a1c06b0625940bb8e04a1ceccd"
	                       "d88010234f53abbbaf181f49761a3ecefaee56de7b59b5aaf0031e3c1552c9ac"));

	ASSERT(!libhashsum_init_shake512_hasher(&hasher, 1024));
	ASSERT(!strcmp(hasher.algorithm_string, "SHAKE512[n=1024]"));
	ASSERT(!hasher.finalise_const(&hasher, MSG1600, 1600/8, 0));
	ASSERT(hasher.hash_size == 1024/8);
	hex(hexsum, hasher.hash_output, hasher.hash_size);
	ASSERT(!strcmp(hexsum, "9701303d390f51968c25b6eee54816d19ab149a1c06b0625940bb8e04a1ceccd"
	                       "d88010234f53abbbaf181f49761a3ecefaee56de7b59b5aaf0031e3c1552c9ac"
	                       "40dfaf6aac934fd644dbc4a3d753e1f3845a5901f415dff2a88440f6a8f5688f"
	                       "f26e68ecc6ad23acf18e0a54be745db919fab01f77a251d5f66b01e2426bf020"));

	return 0;
}