#include "environ.h"
#include "sha.h"
/* ********************************* */
/* Test routines */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
/* Size of buffer for speedtest */
#define TEST_BLOCK_SIZE (SHF_DIGESTSIZE * 100L)
/* Number of bytes of testdata to process. */
static char expected1 [] = "0164B8A914CD2A5E74C4F7FF082C4D97F1EDF880";
static char expected2 [] = "A9993E364706816ABA3E25717850C26C9CD0D89D";
static char expect2 [] = "84983E441C3BD26EBAAE4AA1F95129E5E54670F1";
static char expect3 [] = "34AA973CD4C4DAA4F61EEB2BDBAD27316534016F";
int main () {
time_t endTime, startTime;
BITS8 data[TEST_BLOCK_SIZE];
BITS32 i;
sha_digest aresult;
char aresultstr [41];
int loopindex;
printf ("Testing original SHA-0\n");
shaInit (NULL, 0); shaUpdate (NULL, (BITS8 *) "abc", 3);
shaFinal (NULL, aresult);shaString(aresult, aresultstr);
if ( strcmp (aresultstr, expected1) != 0) {
printf ("Expected: %s, got: %s \n", expected1, aresultstr);
puts ("Error in SHF version 0 implementation");
return 1;
} else {
printf ("SHF version 0 passed!!!!!\n");
}
printf ("Testing SHA-1\n");
shaInit (NULL, 1); shaUpdate (NULL, (BITS8 *) "abc", 3);
shaFinal (NULL, aresult);shaString(aresult, aresultstr);
if ( strcmp (aresultstr, expected2) != 0) {
printf ("Expected: %s, got: %s\n", expected1, aresultstr);
puts ("Error in SHF version 1 implementation");
return 1;
} else {
printf ("SHF version 1 passed!!!!!\n");
}
printf ("The revised SHF standard has more tests than the old one:\n");
printf ("Buffer spanning test...\n");
shaInit (NULL, 1);
shaUpdate (NULL, (BITS8 *)
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
shaFinal (NULL, aresult);shaString(aresult, aresultstr);
if ( strcmp (aresultstr, expect2) != 0) {
printf ("Expected: %s, got: %s\n", expect2, aresultstr);
puts ("Error in SHF version 1 buffer packing implementation");
return 1;
} else {
printf ("SHF Buffer spanning passed!!!!!\n");
}
/* The standard has a LARGE test, let us do that. */
/* We can also use it for our timing test.
/* get start time */
printf ("SHF million 'a's test (and time trial)...\n");
time (&startTime);
shaInit (NULL, 1);
for (i = 0; i<1000000; i++)
shaUpdate (NULL, (BITS8 *) "a", 1);
shaFinal (NULL, aresult); shaString(aresult, aresultstr);
time(&endTime);
if ( strcmp (aresultstr, expect3) != 0) {
printf ("Expected: %s, got %s\n", expect3, aresultstr);
puts ("Error in SHF version 1 million a's test");
return 1;
} else {
printf ("SHF million a's passed!!!!!\n");
}
printf("Seconds to process test input: %ld\n", (long)(endTime - startTime));
if (endTime-startTime > 0) {
printf("Characters processed per second: %ld\n",
(long)(1000000/(long)(endTime-startTime)));
} else {
printf ("Measured time was zero...\n");
}
return 0;
}
This page is http://www.cc.utah.edu/~nahaj/c/sha/testa.c.html
© Copyright 2000 by John Halleck, All Rights Reserved.
This snapshot was last modified on August 23rd, 2000
And the underlying file was last modified on May 30th, 2000