#include #include #include #include "sha.h" typedef struct test TEST; struct test { int num; const char *data; int datalen; int hashlen; const unsigned char *expected; } ; static char a_x_1000000[1000000]; static TEST tests[] = { { 0, "abc", 3, 20, "\x01\x64\xb8\xa9\x14\xcd\x2a\x5e\x74\xc4" "\xf7\xff\x08\x2c\x4d\x97\xf1\xed\xf8\x80" }, { 1, "abc", 3, 20, "\xa9\x99\x3e\x36\x47\x06\x81\x6a\xba\x3e" "\x25\x71\x78\x50\xc2\x6c\x9c\xd0\xd8\x9d" }, { 256, "abc", 3, 32, "\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23" "\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad" }, { 384, "abc", 3, 48, "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50\x07" "\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff\x5b\xed" "\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34\xc8\x25\xa7" }, { 512, "abc", 3, 64, "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31" "\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a" "\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd" "\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f" }, { 0, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56, 20, "\xd2\x51\x6e\xe1\xac\xfa\x5b\xaf\x33\xdf" "\xc1\xc4\x71\xe4\x38\x44\x9e\xf1\x34\xc8" }, { 1, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56, 20, "\x84\x98\x3e\x44\x1c\x3b\xd2\x6e\xba\xae" "\x4a\xa1\xf9\x51\x29\xe5\xe5\x46\x70\xf1" }, { 256, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56, 32, "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39" "\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1" }, { 384, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", 112, 48, "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b\x47" "\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0\xf7\x12" "\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91\x74\x60\x39" }, { 512, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", 112, 64, "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14\x3f" "\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88\x90\x18" "\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4\xb5\x43\x3a" "\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b\x87\x4b\xe9\x09" }, #ifndef TRACE { 0, &a_x_1000000[0], 1000000, 20, "\x32\x32\xaf\xfa\x48\x62\x8a\x26\x65\x3b" "\x5a\xaa\x44\x54\x1f\xd9\x0d\x69\x06\x03" }, { 1, &a_x_1000000[0], 1000000, 20, "\x34\xaa\x97\x3c\xd4\xc4\xda\xa4\xf6\x1e" "\xeb\x2b\xdb\xad\x27\x31\x65\x34\x01\x6f" }, { 256, &a_x_1000000[0], 1000000, 32, "\xcd\xc7\x6e\x5c\x99\x14\xfb\x92\x81\xa1\xc7\xe2\x84\xd7\x3e\x67" "\xf1\x80\x9a\x48\xa4\x97\x20\x0e\x04\x6d\x39\xcc\xc7\x11\x2c\xd0" }, { 384, &a_x_1000000[0], 1000000, 48, "\x9d\x0e\x18\x09\x71\x64\x74\xcb\x08\x6e\x83\x4e\x31\x0a\x4a\x1c" "\xed\x14\x9e\x9c\x00\xf2\x48\x52\x79\x72\xce\xc5\x70\x4c\x2a\x5b" "\x07\xb8\xb3\xdc\x38\xec\xc4\xeb\xae\x97\xdd\xd8\x7f\x3d\x89\x85" }, { 512, &a_x_1000000[0], 1000000, 64, "\xe7\x18\x48\x3d\x0c\xe7\x69\x64\x4e\x2e\x42\xc7\xbc\x15\xb4\x63" "\x8e\x1f\x98\xb1\x3b\x20\x44\x28\x56\x32\xa8\x03\xaf\xa9\x73\xeb" "\xde\x0f\xf2\x44\x87\x7e\xa6\x0a\x4c\xb0\x43\x2c\xe5\x77\xc3\x1b" "\xeb\x00\x9c\x5c\x2c\x49\xaa\x2e\x4e\xad\xb2\x17\xad\x8c\xc0\x9b" }, #endif { -1 } }; int main(void); int main(void) { int i; void *h; unsigned char *result; int j; memset(&a_x_1000000[0],'a',1000000); i = shaX_max_hashsize(); if ((i < 1) || (i > 10240)) { printf("shaX_max_hashlen() -> %d (unreasonable)\n",i); exit(1); } result = malloc(i); for (i=0;tests[i].num>=0;i++) { h = shaX_init(tests[i].num); if (! h) { printf("test %d: shaX_init(%d) failed\n",i,tests[i].num); exit(1); } if (shaX_hashsize(h) != tests[i].hashlen) { printf("test %d: type %d hash size wrong (returns %d, expected %d)\n",i,tests[i].num,shaX_hashsize(h),tests[i].hashlen); exit(1); } shaX_process_bytes(h,tests[i].data,tests[i].datalen); shaX_result(h,result); if (bcmp(result,tests[i].expected,tests[i].hashlen)) { printf("test %d: result wrong\n",i); printf("want: "); for (j=0;j