/* * Copyright Ó 1992 by Xerox Corporation. All rights reserved. * September 30, 1992 * Runs the three tests from the SHS document * */ #include #include "SHS.h" void onefile(f) FILE *f; { SHS_CTX *ctx = (SHS_CTX *) malloc( sizeof(SHS_CTX) ); unsigned char hash[20]; int j; SHSInit(ctx); while (1) { char buf[520]; int nread = fread(buf, 1, 520, f); if (nread==0) break; SHSUpdate( ctx, buf, nread ); }; SHSFinal( hash, ctx ); printf("test ints: %08X %08X %08X %08X %08X\n", ctx->state[0], ctx->state[1], ctx->state[2], ctx->state[3], ctx->state[4] ); printf("test chars: "); for (j=0; j<20; j++) { printf("%02X", hash[j]); if (j%4==3) printf(" "); }; printf("\n"); } void millionAs() { SHS_CTX *ctx = (SHS_CTX *) malloc( sizeof(SHS_CTX) ); unsigned char hash[20]; char *a = "a"; int j; SHSInit(ctx); for (j=0; j<1000000; j++) { SHSUpdate( ctx, a, 1 ); }; SHSFinal( hash, ctx ); printf("test ints: %08X %08X %08X %08X %08X\n", ctx->state[0], ctx->state[1], ctx->state[2], ctx->state[3], ctx->state[4] ); printf("test chars: "); for (j=0; j<20; j++) { printf("%02X", hash[j]); if (j%4==3) printf(" "); }; printf("\n"); } main() { FILE *f = fopen("test2", "r"); printf("correct: %08X %08X %08X %08X %08X\n", 0x164B8A9, 0x14CD2A5E, 0x74C4F7FF, 0x82C4D97, 0xF1EDF880 ); onefile(f); fclose(f); f = fopen("test3", "r"); printf("correct: %08X %08X %08X %08X %08X\n", 0xD2516EE1, 0xACFA5BAF, 0x33DFC1C4, 0x71E43844, 0x9EF134C8 ); onefile(f); fclose(f); printf("correct: %08X %08X %08X %08X %08X\n", 0x3232AFFA, 0x48628A26, 0x653B5AAA, 0x44541FD9, 0xD690603 ); millionAs(); }