diff --git a/sha1test.c b/sha1test.c index 37b338e..20dc787 100644 --- a/sha1test.c +++ b/sha1test.c @@ -1,30 +1,54 @@ #include "sha1.h" #include +#include +#include +#include int main(void) { - struct sha1_context context = {{0}, 0,0,0,0,0, {0}, 0,0,0,0,0, - {0x61,0x62,0x63,0x80, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x18 - }, - {0}}; - - sha1_init(&context); - sha1_processchunk(&context); - - printf("abcde = %08lx %08lx %08lx %08lx %08lx\n", context.a, context.b, context.c, context.d, context.e); - printf("h[..] = %08lx %08lx %08lx %08lx %08lx\n", context.h0, context.h1, context.h2, context.h3, context.h4); + unsigned int i; + unsigned long tick_count; + long double bytes_per_sec; + + struct sha1_context *context, **context_hndl; + struct sha1_context context_init = {{0}, 0,0,0,0,0, {0}, 0,0,0,0,0, + {0x61,0x62,0x63,0x80, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x18 + }, + {0}}; + + context_hndl = (struct sha1_context **)NewHandle(sizeof(struct sha1_context), + userid(), attrFixed|attrPage|attrBank|attrNoCross, 0x000000); + if (toolerror()) + return 0; + context = *context_hndl; + *context = context_init; + + sha1_init(context); + sha1_processchunk(context); + + printf("abcde = %08lx %08lx %08lx %08lx %08lx\n", context->a, context->b, context->c, context->d, context->e); + printf("h[..] = %08lx %08lx %08lx %08lx %08lx\n", context->h0, context->h1, context->h2, context->h3, context->h4); + + tick_count = GetTick(); + for (i = 0; i < 1000; i++) { + sha1_processchunk(context); + } + tick_count = GetTick() - tick_count; + + bytes_per_sec = (long double)1000 * 64 * 60 / tick_count; + printf("Time for 1000 iters = %lu ticks (%lf bytes/sec)\n", tick_count, bytes_per_sec); }