1 /****************************************************************************
5 ****************************************************************************/
12 /* Test the SHS implementation */
16 static SHS_LONG shsTestResults[][ 5 ] = {
17 { 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL, },
18 { 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L, },
19 { 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL, }
24 static SHS_LONG shsTestResults[][ 5 ] = {
25 { 0x0164B8A9L, 0x14CD2A5EL, 0x74C4F7FFL, 0x082C4D97L, 0xF1EDF880L },
26 { 0xD2516EE1L, 0xACFA5BAFL, 0x33DFC1C4L, 0x71E43844L, 0x9EF134C8L },
27 { 0x3232AFFAL, 0x48628A26L, 0x653B5AAAL, 0x44541FD9L, 0x0D690603L }
31 static int compareSHSresults(shsInfo, shsTestLevel)
37 /* Compare the returned digest and required values */
38 for( i = 0; i < 5; i++ )
39 if( shsInfo->digest[ i ] != shsTestResults[ shsTestLevel ][ i ] )
42 printf("\nExpected: ");
43 for (i = 0; i < 5; i++) {
44 printf("%8.8lx ", (unsigned long) shsTestResults[shsTestLevel][i]);
47 for (i = 0; i < 5; i++) {
48 printf("%8.8lx ", (unsigned long) shsInfo->digest[i]);
66 /* Make sure we've got the endianness set right. If the machine is
67 big-endian (up to 64 bits) the following value will be signed,
68 otherwise it will be unsigned. Unfortunately we can't test for odd
69 things like middle-endianness without knowing the size of the data
72 /* Test SHS against values given in SHS standards document */
73 printf( "Running SHS test 1 ... " );
75 shsUpdate( &shsInfo, ( SHS_BYTE * ) "abc", 3 );
77 if( compareSHSresults( &shsInfo, 0 ) == -1 )
80 puts( "SHS test 1 failed" );
84 puts( "passed, result= A9993E364706816ABA3E25717850C26C9CD0D89D" );
86 puts( "passed, result= 0164B8A914CD2A5E74C4F7FF082C4D97F1EDF880" );
89 printf( "Running SHS test 2 ... " );
91 shsUpdate( &shsInfo, ( SHS_BYTE * ) "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56 );
93 if( compareSHSresults( &shsInfo, 1 ) == -1 )
96 puts( "SHS test 2 failed" );
100 puts( "passed, result= 84983E441C3BD26EBAAE4AA1F95129E5E54670F1" );
102 puts( "passed, result= D2516EE1ACFA5BAF33DFC1C471E438449EF134C8" );
105 printf( "Running SHS test 3 ... " );
107 for( i = 0; i < 15625; i++ )
108 shsUpdate( &shsInfo, ( SHS_BYTE * ) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 64 );
109 shsFinal( &shsInfo );
110 if( compareSHSresults( &shsInfo, 2 ) == -1 )
113 puts( "SHS test 3 failed" );
117 puts( "passed, result= 34AA973CD4C4DAA4F61EEB2BDBAD27316534016F" );
119 puts( "passed, result= 3232AFFA48628A26653B5AAA44541FD90D690603" );
123 printf( "\nTesting speed for 100MB data... " );
125 secondCount = time( NULL );
126 for( i = 0; i < 500000U; i++ )
127 shsUpdate( &shsInfo, data, 200 );
128 secondCount = time( NULL ) - secondCount;
129 printf( "done. Time = %ld seconds, %ld kbytes/second.\n", \
130 secondCount, 100500L / secondCount );
133 puts( "\nAll SHS tests passed" );