#include #include "sha1.h" static const struct { const char *input; const char result[20]; } tests[] = { { "abc", "\xa9\x99\x3e\x36\x47\x06\x81\x6a\xba\x3e\x25\x71\x78\x50\xc2\x6c" "\x9c\xd0\xd8\x9d" }, { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "\x84\x98\x3e\x44\x1c\x3b\xd2\x6e\xba\xae\x4a\xa1\xf9\x51\x29\xe5" "\xe5\x46\x70\xf1" } }; int main (void) { struct SHA1Context ctx; char sum[20]; int result = 0; int cnt; for (cnt = 0; cnt < (int) (sizeof (tests) / sizeof (tests[0])); ++cnt) { SHA1Init (&ctx); SHA1Update (&ctx, tests[cnt].input, strlen (tests[cnt].input)); SHA1Final (sum, &ctx); result |= memcmp (tests[cnt].result, sum, 20); } if( result ) puts("whoops"); else puts("Good job!"); return result; }