11 #if defined( __MVS__ ) || defined( __VMCMS__ )
13 #pragma convlit( suspend )
43 #define NO_OBJECTS 10000
45 static void testStressObjects(
void )
51 printf(
"Running object stress test." );
52 assert( handleArray != NULL );
53 for( i = 0; i < NO_OBJECTS; i++ )
58 printf(
"cryptEncrypt() failed at %d with status %d.\n", i,
62 for( i = 0; i < NO_OBJECTS; i++ )
64 status =
cryptEncrypt( handleArray[ i ],
"12345678", 8 );
66 printf(
"cryptEncrypt() failed at %d with status %d.\n", i, status );
69 for( i = 0; i < NO_OBJECTS; i++ )
73 printf(
"cryptEncrypt() failed at %d with status %d.\n", i,
77 for( i = 0; i < NO_OBJECTS; i++ )
82 printf(
"cryptEncrypt() failed at %d with status %d.\n", i,
86 for( i = 0; i < NO_OBJECTS; i++ )
90 printf(
"cryptEncrypt() failed at %d with status %d.\n", i,
105 #define DATABUFFER_SIZE 2048
106 #define MAX_BLOCKS 16
108 #define roundUp( size, roundSize ) \
109 ( ( ( size ) + ( ( roundSize ) - 1 ) ) & ~( ( roundSize ) - 1 ) )
121 CRYPT_FUNCTION cryptFunction )
129 for( i = 0; i < noBlocks - 1; i++ )
131 int noBytes = rand() % ( DATABUFFER_SIZE - offset - \
132 ( blockSize * ( noBlocks - i ) ) );
136 noBytes =
roundUp( noBytes, blockSize );
137 status = cryptFunction( cryptContext, buffer + offset, noBytes );
142 status = cryptFunction( cryptContext, buffer + offset,
143 DATABUFFER_SIZE - offset );
145 status = cryptFunction( cryptContext,
"", 0 );
153 BYTE buffer1[ DATABUFFER_SIZE ], buffer2[ DATABUFFER_SIZE ];
158 int length1, length2, i;
161 memset( buffer1,
'*', DATABUFFER_SIZE );
162 memcpy( buffer1,
"12345678", 8 );
163 memcpy( buffer2, buffer1, DATABUFFER_SIZE );
166 printf(
"Testing algorithm %d, mode %d, for %d-byte buffer with\n block "
167 "count ", cryptAlgo, ( cryptMode ==
CRYPT_UNUSED ) ? 0 : cryptMode,
169 for( i = 1; i <= MAX_BLOCKS; i++ )
174 memcpy( buffer1, buffer2, DATABUFFER_SIZE );
175 printf(
"%d%s ", i, ( i == MAX_BLOCKS ) ?
"." :
"," );
190 "1234567887654321", cryptQueryInfo.
blockSize );
198 "12345678876543211234567887654321",
203 status = processData( cryptContext, buffer1, i, blockSize,
231 "1234567887654321", cryptQueryInfo.
blockSize );
239 "12345678876543211234567887654321",
244 status = processData( cryptContext, buffer1, i, blockSize,
262 if( ( length1 != length2 ) || memcmp( hash1, hash2, length1 ) )
264 puts(
"Error: Hash value of identical buffers differs." );
269 if( memcmp( buffer1, buffer2, DATABUFFER_SIZE ) )
271 printf(
"Decrypted data != encrypted data for algorithm %d.\n",
281 static void testDataProcessing(
void )
285 int errorCount = 0,
status;
291 &cryptQueryInfo ) ) )
299 printf(
"\nAlgorithm %d ECB mode processing failed with "
300 "status %d.\n", cryptAlgo, status );
307 printf(
"\nAlgorithm %d CBC mode processing failed with "
308 "status %d.\n", cryptAlgo, status );
315 printf(
"\nAlgorithm %d CFB mode processing failed with "
316 "status %d.\n", cryptAlgo, status );
323 printf(
"\nAlgorithm %d GCM mode processing failed with "
324 "status %d.\n", cryptAlgo, status );
332 printf(
"\nAlgorithm %d OFB mode processing failed with "
333 "status %d.\n", cryptAlgo, status );
347 printf(
"\nAlgorithm %d processing failed with status %d.\n",
362 printf(
"\nAlgorithm %d processing failed with status %d.\n",
369 printf(
"%d errors detected.\n", errorCount );
396 static void testKernelChecks(
void )
401 printf(
"Running kernel smoke test:\n Contexts" );
402 for( subType = 0; subType < 500; subType++ )
406 smokeTestAttributes( cryptHandle );
408 printf(
"\n Certs" );
409 for( subType = 0; subType < 500; subType++ )
413 smokeTestAttributes( cryptHandle );
415 printf(
"\n Envelopes" );
416 for( subType = 0; subType < 500; subType++ )
420 smokeTestAttributes( cryptHandle );
422 printf(
"\n Sessions" );
423 for( subType = 0; subType < 500; subType++ )
427 smokeTestAttributes( cryptHandle );
445 #ifdef WINDOWS_THREADS
447 #define NO_SIMPLE_THREADS 45
449 static void randSleep(
void )
451 Sleep( ( rand() % 150 ) + 1 );
454 unsigned __stdcall processDataThread(
void *arg )
458 int threadNo = ( int ) arg;
462 memset( buffer,
'*', 1024 );
469 "123456781234567812345678", 24 );
487 printf(
"\nEncryption failed with status %d.\n", status );
489 printf(
"%d ", threadNo );
495 static void testStressThreads(
void )
497 HANDLE hThreadArray[ NO_SIMPLE_THREADS ];
501 for( i = 0; i < NO_SIMPLE_THREADS; i++ )
505 hThreadArray[ i ] = (
HANDLE ) \
506 _beginthreadex( NULL, 0, &processDataThread, (
void * ) i, 0,
508 if( hThreadArray[ i ] == 0 )
509 printf(
"Thread %d couldn't be created.\n", i );
511 printf(
"Threads completed: " );
514 if( WaitForMultipleObjects( NO_SIMPLE_THREADS, hThreadArray,
TRUE,
515 15000 ) == WAIT_TIMEOUT )
516 puts(
"\nNot all threads completed in 15s." );
519 for( i = 0; i < NO_SIMPLE_THREADS; i++ )
520 CloseHandle( hThreadArray[ i ] );
524 #if defined( UNIX_THREADS ) || defined( WINDOWS_THREADS )
527 void *envelopeDataThread(
void *arg )
529 unsigned __stdcall envelopeDataThread(
void *arg )
532 static const char *envData =
"qwertyuiopasdfghjklzxcvbnm";
534 const unsigned uThread = ( unsigned ) arg;
535 const time_t startTime = time( NULL );
538 printf(
"Thread %d started.\n", uThread );
543 for( count = 0; count < 150; count++ )
562 status =
cryptPushData( cryptEnvelope, envData, strlen( envData ),
573 printf(
"%c", uThread +
'0' );
576 printf(
"Thread %u exited after %d seconds.\n", uThread,
577 time( NULL ) - startTime );
580 pthread_exit( NULL );
587 static void testContinuousThreads(
void )
589 unsigned threadID1, threadID2;
591 pthread_t thread1, thread2;
593 HANDLE hThread1, hThread2;
598 pthread_create( &thread1, NULL, envelopeDataThread, (
void * ) 1 );
599 pthread_create( &thread2, NULL, envelopeDataThread, (
void * ) 2 );
601 hThread1 = (
HANDLE ) _beginthreadex( NULL, 0, envelopeDataThread,
602 (
void * ) 1, 0, &threadID1 );
603 hThread2 = (
HANDLE ) _beginthreadex( NULL, 0, envelopeDataThread,
604 (
void * ) 2, 0, &threadID2 );
607 printf(
"Hit a key..." );
624 #ifdef WINDOWS_THREADS
626 #define NO_COMPLEX_THREADS 4
628 unsigned __stdcall signTest(
void *arg )
634 const int count = *( (
int * ) arg );
637 printf(
"SignTest %d.\n", count );
639 for( i = 0; i < count; i++ )
671 _endthreadex( status );
680 unsigned __stdcall encTest(
void *arg )
685 const int count = *( (
int * ) arg );
688 printf(
"EncTest %d.\n", count );
690 for( i = 0; i < count; i++ )
695 if( ( filePtr = fopen(
"testdata/cert5.der",
"rb" ) ) != NULL )
697 certSize = fread( buffer, 1, 1024, filePtr );
723 _endthreadex( status );
732 int testStressThreadsComplex(
void )
734 HANDLE hThreads[ NO_COMPLEX_THREADS ];
739 for( i = 0; i < 1000; i++ )
744 hThreads[ 0 ] = (
HANDLE ) \
745 _beginthreadex( NULL, 0, encTest, &i, 0, &dwThreadId );
746 hThreads[ 1 ] = (
HANDLE ) \
747 _beginthreadex( NULL, 0, signTest, &i, 0, &dwThreadId );
748 hThreads[ 2 ] = (
HANDLE ) \
749 _beginthreadex( NULL, 0, encTest, &i, 0, &dwThreadId );
750 hThreads[ 3 ] = (
HANDLE ) \
751 _beginthreadex( NULL, 0, signTest, &i, 0, &dwThreadId );
753 WaitForMultipleObjects( NO_COMPLEX_THREADS, hThreads,
TRUE,
756 for( j = 0; j < NO_COMPLEX_THREADS; j++ )
757 CloseHandle( hThreads[ j ] );
772 testDataProcessing();
775 #if defined( UNIX_THREADS ) || defined( WINDOWS_THREADS )
776 testStressThreadsSimple();
777 testStressThreadsComplex();