40 #if defined( _WIN32_WCE ) && _WIN32_WCE < 400
49 #include "../cryptlib.h"
60 #if defined( _WINDOWS ) || defined( WIN32 ) || defined( _WIN32 ) || \
68 #define BYTE unsigned char
77 #define printf wcPrintf
80 void wcPrintf(
const char *format, ... );
81 void wcPuts(
const char *
string );
87 #if defined( __WINDOWS__ ) || defined( __UNIX__ )
96 #define USE_32BIT_TIME
98 #if defined( USE_32BIT_TIME )
99 typedef long HIRES_TIME;
100 #elif defined( _MSC_VER )
101 typedef __int64 HIRES_TIME;
102 #elif defined( __GNUC__ )
103 typedef long long HIRES_TIME;
105 typedef unsigned long HIRES_TIME;
119 void wcPrintf(
const char *format, ... )
121 wchar_t wcBuffer[ 1024 ];
125 va_start( argPtr, format );
126 vsprintf( buffer, format, argPtr );
128 mbstowcs( wcBuffer, buffer, strlen( buffer ) + 1 );
129 NKDbgPrintfW( wcBuffer );
132 void wcPuts(
const char *
string )
134 wcPrintf(
"%s\n",
string );
140 #ifdef USE_32BIT_TIME
142 static HIRES_TIME timeDiff( HIRES_TIME startTime )
144 HIRES_TIME timeLSB, timeDifference;
148 LARGE_INTEGER performanceCount;
151 QueryPerformanceCounter( &performanceCount );
152 timeLSB = performanceCount.LowPart;
154 FILETIME dummyTime, kernelTime, userTime;
158 GetThreadTimes( GetCurrentThread(), &dummyTime, &dummyTime,
159 &kernelTime, &userTime );
160 timeLSB = userTime.dwLowDateTime;
166 gettimeofday( &tv, NULL );
167 timeLSB = tv.tv_usec;
175 if( startTime < timeLSB )
176 timeDifference = timeLSB - startTime;
180 timeDifference = ( 0xFFFFFFFFUL - startTime ) + 1 + timeLSB;
183 timeDifference = ( 1000000L - startTime ) + timeLSB;
185 if( timeDifference <= 0 )
187 printf(
"Error: Time difference = %X, startTime = %X, endTime = %X.\n",
188 timeDifference, startTime, timeLSB );
191 return( timeDifference );
196 static HIRES_TIME timeDiff( HIRES_TIME startTime )
198 HIRES_TIME timeValue;
202 LARGE_INTEGER performanceCount;
205 QueryPerformanceCounter( &performanceCount );
206 timeValue = performanceCount.QuadPart;
208 FILETIME dummyTime, kernelTime, userTime;
212 GetThreadTimes( GetCurrentThread(), &dummyTime, &dummyTime,
213 &kernelTime, &userTime );
214 timeLSB = userTime.dwLowDateTime;
220 gettimeofday( &tv, NULL );
221 timeValue = ( ( ( HIRES_TIME ) tv.tv_sec ) << 32 ) | tv.tv_usec;
226 return( timeValue - startTime );
252 printf(
"crypt%sQueryCapability() reports algorithm %d is not "
253 "available, status = %d.\n", isDevice ?
"Device" :
"",
259 printf(
"%s, ", cryptQueryInfo.
algoName );
262 printf(
"%s/%s, block size %d bits, keysize %d bits, ",
294 printf(
"crypt%sCreateContext() failed with error code %d.\n",
295 isDevice ?
"Device" :
"", status );
309 printf(
"Encryption mode %d selection failed with status %d.\n",
324 puts(
" Load of full-length key failed, using shorter 128-"
331 printf(
"Key load failed with error code %d.\n", status );
335 if( decryptContext == NULL )
346 printf(
"crypt%sCreateContext() failed with error code %d.\n",
347 ( cryptDevice !=
CRYPT_UNUSED ) ?
"Device" :
"", status );
361 printf(
"Encryption mode %d selection failed with status %d.\n",
369 key, adjustKey ? 16 : length );
372 printf(
"Key load failed with error code %d.\n", status );
403 static void printTimes( HIRES_TIME times[ NO_TESTS + 1 ][ 8 ],
404 const int noTimes,
long ticksPerSec )
406 long pubTimeMS, privTimeMS, throughput;
409 for( i = 0; i < noTimes; i++ )
411 HIRES_TIME timeSum = 0, timeAvg, timeDelta;
412 HIRES_TIME timeMin = 1000000L;
413 HIRES_TIME timeCorrSum10 = 0;
416 HIRES_TIME timeCorrSumSD = 0;
418 int timesCountSD = 0;
420 int j, timesCount10 = 0;
423 for( j = 1; j < NO_TESTS + 1; j++ )
424 timeSum += times[ j ][ i ];
425 timeAvg = timeSum / NO_TESTS;
426 timeDelta = timeSum / 10;
436 for( j = 1; j < NO_TESTS + 1; j++ )
438 if( times[ j ][ i ] < timeMin )
439 timeMin = times[ j ][ i ];
446 for( j = 1; j < NO_TESTS + 1; j++ )
448 if( times[ j ][ i ] > timeAvg - timeDelta && \
449 times[ j ][ i ] < timeAvg + timeDelta )
451 timeCorrSum10 += times[ j ][ i ];
455 if( timesCount10 <= 0 )
457 printf(
"Error: No times within +/-%d of %d.\n",
458 timeDelta, timeAvg );
461 avgTime = timeCorrSum10 / timesCount10;
462 if( noTimes <= 2 && i == 0 )
464 printf(
"Pub: min.= %d, avg.= %d ", (
long ) timeMin,
466 pubTimeMS = ( avgTime * 1000 ) / ticksPerSec;
469 if( noTimes <= 2 && i == 1 )
471 printf(
"Priv: min.= %d, avg.= %d ", (
long ) timeMin,
473 privTimeMS = ( avgTime * 1000 ) / ticksPerSec;
477 printf(
"%7d", (
long ) avgTime );
480 const long mbTime = ( long ) avgTime * 16;
482 if( mbTime > ticksPerSec )
485 throughput = ticksPerSec / mbTime;
489 printf(
"(%4d)", ( timeCorrSum10 / timesCount10 ) - timeMin );
494 for( j = 1; j < NO_TESTS + 1; j++ )
496 const HIRES_TIME timeDev = times[ j ][ i ] - timeAvg;
498 timeCorrSumSD += ( timeDev * timeDev );
500 stdDev = timeCorrSumSD / NO_TESTS;
501 stdDev = sqrt( stdDev );
506 timeDelta = ( HIRES_TIME ) stdDev * 2;
507 for( j = 1; j < NO_TESTS + 1; j++ )
509 if( times[ j ][ i ] > timeAvg - timeDelta && \
510 times[ j ][ i ] < timeAvg + timeDelta )
512 timeCorrSumSD += times[ j ][ i ];
516 if( timesCountSD == 0 )
518 printf(
"%6d", timeCorrSumSD / timesCountSD );
522 printf(
" (dF = %4d, dM = %4d)\n",
523 ( timeCorrSumSD / timesCountSD ) - timeMin,
524 abs( ( timeCorrSumSD / timesCountSD ) - \
525 ( timeCorrSum10 / timesCount10 ) ) );
532 printf(
"\n Public-key op.time = " );
536 printf(
"%ld", pubTimeMS );
537 printf(
" ms, private-key op.time = %ld ms.\n", privTimeMS );
541 if( throughput <= 0 )
542 puts(
", throughput < 1 MB/s." );
544 printf(
", throughput %d MB/s.\n", throughput );
549 BYTE *buffer,
const int length )
553 memset( buffer,
'*', length );
554 timeVal = timeDiff( 0 );
556 return( timeDiff( timeVal ) );
566 encOne( cryptContext, buffer, 8 ) : 0;
567 times[ index++ ] = encOne( cryptContext, buffer, 16 );
568 times[ index++ ] = encOne( cryptContext, buffer, 64 );
569 times[ index++ ] = encOne( cryptContext, buffer, 1024 );
570 times[ index++ ] = encOne( cryptContext, buffer, 4096 );
571 times[ index++ ] = encOne( cryptContext, buffer, 8192 );
572 times[ index++ ] = encOne( cryptContext, buffer, 65536L );
578 BYTE *buffer,
long ticksPerSec )
581 HIRES_TIME times[ NO_TESTS + 1 ][ 8 ],
timeVal, timeSum = 0;
584 memset( buffer, 0, 100000L );
587 if( !checkLowlevelInfo( cryptDevice, cryptAlgo, cryptMode ) )
589 for( i = 0; i < 10; i++ )
591 timeVal = timeDiff( 0 );
592 status = loadContexts( &cryptContext, NULL, cryptDevice,
593 cryptAlgo, cryptMode,
594 (
BYTE * )
"12345678901234567890",
599 timeVal = timeDiff( timeVal );
606 printf(
"setup time = %d ticks.\n", timeSum / 10 );
607 puts(
" 8 16 64 1K 4K 8K 64K" );
608 puts(
" ----- ----- ----- ----- ----- ----- -----" );
612 for( i = 0; i < NO_TESTS + 1; i++ )
613 encTest( cryptContext, cryptAlgo, buffer, times[ i ] );
614 printTimes( times, 7, ticksPerSec );
617 for( i = 0; i < NO_TESTS + 1; i++ )
618 encTest( cryptContext, cryptAlgo, buffer + 1, times[ i ] );
619 printTimes( times, 7, ticksPerSec );
622 for( i = 0; i < NO_TESTS + 1; i++ )
623 encTest( cryptContext, cryptAlgo, buffer + 4, times[ i ] );
624 printTimes( times, 7, ticksPerSec );
628 for( i = 0; i < 1000; i++ )
629 timeVal += encOne( cryptContext, buffer, 1024 );
630 printf(
"Aligned: %d, ", timeVal / 1000 );
632 for( i = 0; i < 1000; i++ )
633 timeVal += encOne( cryptContext, buffer + 1, 1024 );
634 printf(
"misaligned + 1: %d, ", timeVal / 1000 );
636 for( i = 0; i < 1000; i++ )
637 timeVal += encOne( cryptContext, buffer + 4, 1024 );
638 printf(
"misaligned + 4: %d.\n", timeVal / 1000 );
643 static void performanceTests(
const CRYPT_DEVICE cryptDevice,
648 if( ( buffer = malloc( 100000L ) ) == NULL )
650 puts(
"Couldn't 100K allocate test buffer." );
688 #include "../crypt.h"
693 #define CRYPT_IATTRIBUTE_KEY_SPKI 8015
695 static const BYTE dh1024SPKI[] = {
696 0x30, 0x82, 0x01, 0x21,
697 0x30, 0x82, 0x01, 0x17,
698 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3E, 0x02, 0x01,
699 0x30, 0x82, 0x01, 0x0A,
700 0x02, 0x81, 0x81, 0x00,
701 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
702 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
703 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
704 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
705 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
706 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
707 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
708 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
709 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
710 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
711 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
712 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
713 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
714 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
715 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81,
716 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
720 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
721 0xE4, 0x87, 0xED, 0x51, 0x10, 0xB4, 0x61, 0x1A,
722 0x62, 0x63, 0x31, 0x45, 0xC0, 0x6E, 0x0E, 0x68,
723 0x94, 0x81, 0x27, 0x04, 0x45, 0x33, 0xE6, 0x3A,
724 0x01, 0x05, 0xDF, 0x53, 0x1D, 0x89, 0xCD, 0x91,
725 0x28, 0xA5, 0x04, 0x3C, 0xC7, 0x1A, 0x02, 0x6E,
726 0xF7, 0xCA, 0x8C, 0xD9, 0xE6, 0x9D, 0x21, 0x8D,
727 0x98, 0x15, 0x85, 0x36, 0xF9, 0x2F, 0x8A, 0x1B,
728 0xA7, 0xF0, 0x9A, 0xB6, 0xB6, 0xA8, 0xE1, 0x22,
729 0xF2, 0x42, 0xDA, 0xBB, 0x31, 0x2F, 0x3F, 0x63,
730 0x7A, 0x26, 0x21, 0x74, 0xD3, 0x1B, 0xF6, 0xB5,
731 0x85, 0xFF, 0xAE, 0x5B, 0x7A, 0x03, 0x5B, 0xF6,
732 0xF7, 0x1C, 0x35, 0xFD, 0xAD, 0x44, 0xCF, 0xD2,
733 0xD7, 0x4F, 0x92, 0x08, 0xBE, 0x25, 0x8F, 0xF3,
734 0x24, 0x94, 0x33, 0x28, 0xF6, 0x73, 0x29, 0xC0,
735 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
747 printf(
"cryptCreateContext() failed with error code %d.\n",
752 "DH key", strlen(
"DH key" ) );
758 sizeof( dh1024SPKI ) );
764 printf(
"DH key load failed, status = %d, line %d.\n", status,
772 const int nLen;
const BYTE n[ 128 ];
773 const int eLen;
const BYTE e[ 3 ];
774 const int dLen;
const BYTE d[ 128 ];
775 const int pLen;
const BYTE p[ 64 ];
776 const int qLen;
const BYTE q[ 64 ];
777 const int uLen;
const BYTE u[ 64 ];
778 const int e1Len;
const BYTE e1[ 64 ];
779 const int e2Len;
const BYTE e2[ 64 ];
782 static const RSA_KEY rsa1024Key = {
785 { 0x9C, 0x4D, 0x98, 0x18, 0x67, 0xF9, 0x45, 0xBC,
786 0xB6, 0x75, 0x53, 0x5D, 0x2C, 0xFA, 0x55, 0xE4,
787 0x51, 0x54, 0x9F, 0x0C, 0x16, 0xB1, 0xAF, 0x89,
788 0xF6, 0xF3, 0xE7, 0x78, 0xB1, 0x2B, 0x07, 0xFB,
789 0xDC, 0xDE, 0x64, 0x23, 0x34, 0x87, 0xDA, 0x0B,
790 0xE5, 0xB3, 0x17, 0x16, 0xA4, 0xE3, 0x7F, 0x23,
791 0xDF, 0x96, 0x16, 0x28, 0xA6, 0xD2, 0xF0, 0x0A,
792 0x59, 0xEE, 0x06, 0xB3, 0x76, 0x6C, 0x64, 0x19,
793 0xD9, 0x76, 0x41, 0x25, 0x66, 0xD1, 0x93, 0x51,
794 0x52, 0x06, 0x6B, 0x71, 0x50, 0x0E, 0xAB, 0x30,
795 0xA5, 0xC8, 0x41, 0xFC, 0x30, 0xBC, 0x32, 0xD7,
796 0x4B, 0x22, 0xF2, 0x45, 0x4C, 0x94, 0x68, 0xF1,
797 0x92, 0x8A, 0x4C, 0xF9, 0xD4, 0x5E, 0x87, 0x92,
798 0xA8, 0x54, 0x93, 0x92, 0x94, 0x48, 0xA4, 0xA3,
799 0xEE, 0x19, 0x7F, 0x6E, 0xD3, 0x14, 0xB1, 0x48,
800 0xCE, 0x93, 0xD1, 0xEA, 0x4C, 0xE1, 0x9D, 0xEF },
804 { 0x01, 0x00, 0x01 },
808 { 0x37, 0xE2, 0x66, 0x67, 0x13, 0x85, 0xC4, 0xB1,
809 0x5C, 0x6B, 0x46, 0x8B, 0x21, 0xF1, 0xBF, 0x94,
810 0x0A, 0xA0, 0x3E, 0xDD, 0x8B, 0x9F, 0xAC, 0x2B,
811 0x9F, 0xE8, 0x44, 0xF2, 0x9A, 0x25, 0xD0, 0x8C,
812 0xF4, 0xC3, 0x6E, 0xFA, 0x47, 0x65, 0xEB, 0x48,
813 0x25, 0xB0, 0x8A, 0xA8, 0xC5, 0xFB, 0xB1, 0x11,
814 0x9A, 0x77, 0x87, 0x24, 0xB1, 0xC0, 0xE9, 0xA2,
815 0x49, 0xD5, 0x19, 0x00, 0x41, 0x6F, 0x2F, 0xBA,
816 0x9F, 0x28, 0x47, 0xF9, 0xB8, 0xBA, 0xFF, 0xF4,
817 0x8B, 0x20, 0xC9, 0xC9, 0x39, 0xAB, 0x52, 0x0E,
818 0x8A, 0x5A, 0xAF, 0xB3, 0xA3, 0x93, 0x4D, 0xBB,
819 0xFE, 0x62, 0x9B, 0x02, 0xCC, 0xA7, 0xB4, 0xAE,
820 0x86, 0x65, 0x88, 0x19, 0xD7, 0x44, 0xA7, 0xE4,
821 0x18, 0xB6, 0xCE, 0x01, 0xCD, 0xDF, 0x36, 0x81,
822 0xD5, 0xE1, 0x62, 0xF8, 0xD0, 0x27, 0xF1, 0x86,
823 0xA8, 0x58, 0xA7, 0xEB, 0x39, 0x79, 0x56, 0x41 },
827 { 0xCF, 0xDA, 0xF9, 0x99, 0x6F, 0x05, 0x95, 0x84,
828 0x09, 0x90, 0xB3, 0xAB, 0x39, 0xB7, 0xDD, 0x1D,
829 0x7B, 0xFC, 0xFD, 0x10, 0x35, 0xA0, 0x18, 0x1D,
830 0x9A, 0x11, 0x30, 0x90, 0xD4, 0x3B, 0xF0, 0x5A,
831 0xC1, 0xA6, 0xF4, 0x53, 0xD0, 0x94, 0xA0, 0xED,
832 0xE0, 0xE4, 0xE0, 0x8E, 0x44, 0x18, 0x42, 0x42,
833 0xE1, 0x2C, 0x0D, 0xF7, 0x30, 0xE2, 0xB8, 0x09,
834 0x73, 0x50, 0x28, 0xF6, 0x55, 0x85, 0x57, 0x03 },
838 { 0xC0, 0x81, 0xC4, 0x82, 0x6E, 0xF6, 0x1C, 0x92,
839 0x83, 0xEC, 0x17, 0xFB, 0x30, 0x98, 0xED, 0x6E,
840 0x89, 0x92, 0xB2, 0xA1, 0x21, 0x0D, 0xC1, 0x95,
841 0x49, 0x99, 0xD3, 0x79, 0xD3, 0xBD, 0x94, 0x93,
842 0xB9, 0x28, 0x68, 0xFF, 0xDE, 0xEB, 0xE8, 0xD2,
843 0x0B, 0xED, 0x7C, 0x08, 0xD0, 0xD5, 0x59, 0xE3,
844 0xC1, 0x76, 0xEA, 0xC1, 0xCD, 0xB6, 0x8B, 0x39,
845 0x4E, 0x29, 0x59, 0x5F, 0xFA, 0xCE, 0x83, 0xA5 },
849 { 0x4B, 0x87, 0x97, 0x1F, 0x27, 0xED, 0xAA, 0xAF,
850 0x42, 0xF4, 0x57, 0x82, 0x3F, 0xEC, 0x80, 0xED,
851 0x1E, 0x91, 0xF8, 0xB4, 0x33, 0xDA, 0xEF, 0xC3,
852 0x03, 0x53, 0x0F, 0xCE, 0xB9, 0x5F, 0xE4, 0x29,
853 0xCC, 0xEE, 0x6A, 0x5E, 0x11, 0x0E, 0xFA, 0x66,
854 0x85, 0xDC, 0xFC, 0x48, 0x31, 0x0C, 0x00, 0x97,
855 0xC6, 0x0A, 0xF2, 0x34, 0x60, 0x6B, 0xF7, 0x68,
856 0x09, 0x4E, 0xCF, 0xB1, 0x9E, 0x33, 0x9A, 0x41 },
860 { 0x6B, 0x2A, 0x0D, 0xF8, 0x22, 0x7A, 0x71, 0x8C,
861 0xE2, 0xD5, 0x9D, 0x1C, 0x91, 0xA4, 0x8F, 0x37,
862 0x0D, 0x5E, 0xF1, 0x26, 0x73, 0x4F, 0x78, 0x3F,
863 0x82, 0xD8, 0x8B, 0xFE, 0x8F, 0xBD, 0xDB, 0x7D,
864 0x1F, 0x4C, 0xB1, 0xB9, 0xA8, 0xD7, 0x88, 0x65,
865 0x3C, 0xC7, 0x24, 0x53, 0x95, 0x1E, 0x20, 0xC3,
866 0x94, 0x8E, 0x7F, 0x20, 0xCC, 0x2E, 0x88, 0x0E,
867 0x2F, 0x4A, 0xCB, 0xE3, 0xBD, 0x52, 0x02, 0xFB },
871 { 0x10, 0x27, 0xD3, 0xD2, 0x0E, 0x75, 0xE1, 0x17,
872 0xFA, 0xB2, 0x49, 0xA0, 0xEF, 0x07, 0x26, 0x85,
873 0xEC, 0x4D, 0xBF, 0x67, 0xFE, 0x5A, 0x25, 0x30,
874 0xDE, 0x28, 0x66, 0xB3, 0x06, 0xAE, 0x16, 0x55,
875 0xFF, 0x68, 0x00, 0xC7, 0xD8, 0x71, 0x7B, 0xEC,
876 0x84, 0xCB, 0xBD, 0x69, 0x0F, 0xFD, 0x97, 0xB9,
877 0xA1, 0x76, 0xD5, 0x64, 0xC6, 0x5A, 0xD7, 0x7C,
878 0x4B, 0xAE, 0xF4, 0xAD, 0x35, 0x63, 0x37, 0x71 }
886 const RSA_KEY *rsaKeyTemplate = &rsa1024Key;
895 if( cryptContext != NULL )
905 printf(
"crypt%sCreateContext() failed with error code %d.\n",
906 isDevice ?
"Device" :
"", status );
910 "RSA public key", strlen(
"RSA public key" ) );
920 printf(
"Key load failed with error code %d.\n", status );
923 if( decryptContext == NULL )
940 printf(
"crypt%sCreateContext() failed with error code %d.\n",
941 isDevice ?
"Device" :
"", status );
945 "RSA private key", strlen(
"RSA private key" ) );
962 printf(
"Key load failed with error code %d.\n", status );
970 const int pLen;
const BYTE p[ 128 ];
971 const int qLen;
const BYTE q[ 20 ];
972 const int gLen;
const BYTE g[ 128 ];
973 const int xLen;
const BYTE x[ 20 ];
974 const int yLen;
const BYTE y[ 128 ];
977 static const DLP_KEY dlp1024Key = {
980 { 0x03, 0x16, 0x6D, 0x9C, 0x64, 0x0C, 0x65, 0x25,
981 0xDB, 0x73, 0xD0, 0x7D, 0x8B, 0xB2, 0x48, 0xD3,
982 0x70, 0x53, 0xE1, 0x68, 0x0C, 0x2E, 0x98, 0xF7,
983 0xD9, 0xCA, 0x72, 0x10, 0x03, 0x7C, 0x8D, 0x30,
984 0x02, 0xFB, 0xF2, 0xA1, 0x57, 0x61, 0x0B, 0xA0,
985 0x4A, 0x6D, 0x5B, 0x99, 0xCC, 0xB8, 0xD9, 0x0F,
986 0x9F, 0xD4, 0x3C, 0x67, 0x97, 0x35, 0xDE, 0x8D,
987 0x48, 0xE4, 0x7B, 0x7C, 0xEB, 0x69, 0xA4, 0x9F,
988 0x5C, 0x67, 0xA3, 0x6B, 0x27, 0x49, 0xF9, 0x98,
989 0x0D, 0x3B, 0x85, 0xBC, 0xEC, 0x33, 0x39, 0xB1,
990 0x86, 0xFF, 0xAF, 0x98, 0x34, 0x88, 0x30, 0xC3,
991 0x58, 0x62, 0x65, 0xE0, 0xE4, 0xDF, 0xC7, 0xD3,
992 0x2E, 0x36, 0x4F, 0x21, 0x7C, 0x35, 0x86, 0x59,
993 0x02, 0x3C, 0x0D, 0x94, 0x86, 0xC7, 0xC6, 0x59,
994 0x9C, 0x02, 0x66, 0x55, 0x68, 0x1A, 0x77, 0xD2,
995 0x00, 0x6B, 0x61, 0x41, 0x52, 0x26, 0x18, 0x6B },
999 { 0xE8, 0x5A, 0x93, 0xE9, 0x4D, 0x15, 0xB5, 0x96,
1000 0x7E, 0xE3, 0x2A, 0x47, 0x8E, 0xD4, 0xAC, 0x72,
1001 0x3D, 0x82, 0xB6, 0x49 },
1005 { 0x00, 0xA0, 0xED, 0xFF, 0x76, 0x7C, 0x99, 0xA3,
1006 0x43, 0x81, 0x12, 0x78, 0x0F, 0x3D, 0x60, 0xCA,
1007 0xA7, 0x5D, 0xA4, 0xCF, 0xC7, 0x45, 0xDE, 0x99,
1008 0xAF, 0x2F, 0x5A, 0xD2, 0x2B, 0xF1, 0x49, 0xC7,
1009 0x6E, 0xA4, 0x29, 0x78, 0xD7, 0xB1, 0xC0, 0x96,
1010 0x06, 0x3F, 0x0E, 0xD5, 0x83, 0xCB, 0x41, 0x47,
1011 0x91, 0xFD, 0x93, 0x7C, 0xBA, 0x9A, 0x08, 0xBA,
1012 0xF0, 0xFE, 0xFE, 0xE1, 0x32, 0x64, 0x14, 0x80,
1013 0x46, 0x21, 0xAD, 0x11, 0xC7, 0x99, 0x3A, 0xB5,
1014 0x2E, 0xA4, 0xAD, 0xBE, 0xE2, 0x5E, 0x51, 0x3D,
1015 0xBB, 0xEA, 0x43, 0x8F, 0x4E, 0x38, 0x4C, 0xDC,
1016 0x11, 0x4D, 0xE4, 0x4E, 0x40, 0x48, 0x38, 0x40,
1017 0x23, 0x38, 0xC5, 0x86, 0x0E, 0x7B, 0xF0, 0xC7,
1018 0x9B, 0xBC, 0x20, 0x7B, 0x2E, 0x27, 0x5D, 0x2A,
1019 0x10, 0x4A, 0x7E, 0x30, 0x45, 0x8C, 0x6F, 0x2C,
1020 0x77, 0x31, 0x54, 0xA4, 0xCF, 0xEC, 0x36, 0x83 },
1024 { 0xDF, 0x75, 0x2D, 0x11, 0x5F, 0xDB, 0xF9, 0x7A,
1025 0x6F, 0x3F, 0x46, 0xC2, 0xE5, 0xBA, 0x19, 0xF8,
1026 0xD8, 0x07, 0xEB, 0x7C },
1030 { 0x01, 0xFE, 0x13, 0x25, 0xBB, 0xBE, 0xC8, 0xAA,
1031 0x81, 0x0A, 0x67, 0x12, 0xB9, 0x2D, 0xE3, 0xD4,
1032 0x3C, 0xCD, 0x85, 0x5C, 0x86, 0xD3, 0x9E, 0xB7,
1033 0xE6, 0x06, 0x09, 0xA2, 0x94, 0x2D, 0xB3, 0x50,
1034 0x59, 0x9F, 0x19, 0x2A, 0x60, 0xA3, 0xD9, 0xC0,
1035 0x61, 0xE4, 0x8D, 0x13, 0xE1, 0x84, 0xC9, 0x43,
1036 0x62, 0x26, 0x8E, 0xD7, 0x91, 0xDC, 0xBD, 0xAA,
1037 0x21, 0x03, 0xA7, 0x96, 0xF2, 0x8F, 0x2F, 0xBF,
1038 0x22, 0x67, 0xAB, 0x54, 0xB4, 0x8E, 0x76, 0xDC,
1039 0x64, 0xCF, 0x6D, 0x21, 0xDD, 0x9B, 0x41, 0x53,
1040 0x11, 0x48, 0x93, 0x12, 0x75, 0x75, 0x1B, 0x1F,
1041 0xDA, 0x2B, 0x8E, 0x5C, 0x75, 0xDC, 0x5C, 0x77,
1042 0xE7, 0xBE, 0x25, 0x6B, 0xB9, 0x9B, 0x5F, 0x63,
1043 0x11, 0xAF, 0x54, 0xEC, 0xFE, 0x08, 0xDE, 0x1E,
1044 0x4D, 0x38, 0xE3, 0x77, 0x26, 0x2C, 0xDB, 0xDB,
1045 0xAB, 0xC8, 0x60, 0x5F, 0x88, 0x5C, 0x98, 0xFE }
1053 const DLP_KEY *dlpKeyTemplate = &dlp1024Key;
1062 if( signContext != NULL )
1072 printf(
"crypt%sCreateContext() failed with error code %d.\n",
1073 isDevice ?
"Device" :
"", status );
1077 "DSA private key", strlen(
"DSA private key" ) );
1090 printf(
"Key load failed with error code %d.\n", status );
1093 if( sigCheckContext == NULL )
1110 printf(
"crypt%sCreateContext() failed with error code %d.\n",
1111 isDevice ?
"Device" :
"", status );
1115 "DSA public key", strlen(
"DSA public key" ) );
1128 printf(
"Key load failed with error code %d.\n", status );
1139 HIRES_TIME times[] )
1145 memset( buffer,
'*', 128 );
1147 timeVal = timeDiff( 0 );
1149 times[ 0 ] = timeDiff( timeVal );
1152 printf(
"Couldn't encrypt data, status = %d.\n", status );
1155 timeVal = timeDiff( 0 );
1157 times[ 1 ] = timeDiff( timeVal );
1160 printf(
"Couldn't decrypt data, status = %d.\n", status );
1166 static BOOLEAN testRSA(
long ticksPerSec )
1169 HIRES_TIME times[ NO_TESTS + 1 ][ 8 ];
1172 memset( times, 0,
sizeof( times ) );
1175 if( !loadRSAKey(
CRYPT_UNUSED, &cryptContext, &decryptContext ) )
1179 printf(
"RSA 1024-bit " );
1180 for( i = 0; i < NO_TESTS + 1; i++ )
1184 status = encRSATest( cryptContext, decryptContext, times[ i ] );
1188 printTimes( times, 2, ticksPerSec );
1199 static BOOLEAN testDSA(
long ticksPerSec )
1202 HIRES_TIME times[ NO_TESTS + 1 ][ 8 ];
1205 memset( times, 0,
sizeof( times ) );
1208 if( !loadDSAKey(
CRYPT_UNUSED, &signContext, &sigCheckContext ) )
1212 printf(
"DSA 1024-bit " );
1213 for( i = 0; i < NO_TESTS + 1; i++ )
1221 setDLPParams( &dlpParams,
"********************", 20, buffer, 128 );
1222 timeVal = timeDiff( 0 );
1225 times[ i ][ 0 ] = timeDiff( timeVal );
1228 printf(
"Couldn't create DSA signature, status = %d.\n",
1232 sigSize = dlpParams.
outLen;
1234 timeVal = timeDiff( 0 );
1235 setDLPParams( &dlpParams,
"********************", 20, NULL, 0 );
1236 dlpParams.inParam2 =
buffer;
1237 dlpParams.
inLen2 = sigSize;
1240 times[ i ][ 1 ] = timeDiff( timeVal );
1243 printf(
"Couldn't verify DSA signature, status = %d.\n",
1248 printTimes( times, 2, ticksPerSec );
1259 static BOOLEAN testDH(
long ticksPerSec )
1262 HIRES_TIME times[ NO_TESTS + 1 ][ 8 ];
1265 memset( times, 0,
sizeof( times ) );
1267 printf(
"DH 1024-bit " );
1268 for( i = 0; i < NO_TESTS + 1; i++ )
1280 memset( keyAgreeParams.publicValue,
'*', 128 );
1282 timeVal = timeDiff( 0 );
1285 times[ i ][ 0 ] = timeDiff( timeVal );
1288 printf(
"Couldn't perform DH key agreement, status = %d.\n",
1296 printTimes( times, 1, ticksPerSec );
1309 int main(
int argc,
char **argv )
1313 LARGE_INTEGER performanceCount;
1325 printf(
"cryptInit() failed with error code %d.\n", status );
1334 puts(
"Forcing RNG reseed, this may take a few seconds..." );
1341 printf(
"Times given in clock ticks of frequency " );
1343 QueryPerformanceFrequency( &performanceCount );
1344 ticksPerSec = performanceCount.LowPart;
1345 printf(
"%ld", ticksPerSec );
1348 ticksPerSec = 1000000;
1350 printf(
" ticks per second,\nresult rows are alignment offsets +0, "
1351 "+1, +4 with %d tests per result.\n\n", NO_TESTS );
1353 status = testDH( ticksPerSec );
1356 puts(
" (Did you make the cryptapi.c changes described at the "
1357 "start of timings.c?)" );
1359 testRSA( ticksPerSec );
1360 status = testDSA( ticksPerSec );
1363 puts(
" (Did you make the cryptapi.c changes described at the "
1364 "start of timings.c?)" );