13 #if defined( __MVS__ ) || defined( __VMCMS__ )
15 #pragma convlit( suspend )
17 #if defined( __ILEC400__ )
26 #if defined( _MSC_VER ) && ( _MSC_VER == 1200 ) && 0
27 #include "binaries/vld.h"
32 #if defined( _MSC_VER ) && ( _MSC_VER == 1200 ) && 0
34 #include "../../../Intel/VTune/tcheck/Include/libittnotify.h"
35 #include "../../../Intel/VTune/Analyzer/Include/VtuneApi.h"
36 #pragma comment( lib, "C:/Program Files/Intel/VTune/Analyzer/Lib/libittnotify.lib" )
37 #pragma comment( lib, "C:/Program Files/Intel/VTune/Analyzer/Lib/VtuneApi.lib " )
38 #define THREAD_DEBUG_SUSPEND() __itt_pause(); VTPause()
39 #define THREAD_DEBUG_RESUME() VTResume(); __itt_resume()
41 #define THREAD_DEBUG_SUSPEND()
42 #define THREAD_DEBUG_RESUME()
47 #if defined( CONFIG_SUITEB_TESTS ) && defined( _MSC_VER )
48 #pragma message( " Building Suite B command-line test configuration." )
61 #if defined( __MSDOS16__ ) && defined( __TURBOC__ )
62 extern unsigned _stklen = 16384;
69 void xxxCertCheck(
const char *certFileName,
const char *caFileNameOpt );
86 #if defined( CONFIG_SUITEB_TESTS )
88 int suiteBMain(
int argc,
char **argv );
112 static void updateConfig(
void )
115 const char *driverPath =
"c:/winnt/system32/acospkcs11.dll";
116 const char *driverPath =
"c:/winnt/system32/aetpkss1.dll";
117 const char *driverPath =
"c:/winnt/system32/aloaha_pkcs11.dll";
118 const char *driverPath =
"c:/winnt/system32/etpkcs11.dll";
119 const char *driverPath =
"c:/winnt/system32/psepkcs11.dll";
120 const char *driverPath =
"c:/winnt/system32/asepkcs.dll";
121 const char *driverPath =
"c:/winnt/system32/cryst32.dll";
122 const char *driverPath =
"c:/program files/luna/cryst201.dll";
123 const char *driverPath =
"c:/winnt/system32/pkcs201n.dll";
124 const char *driverPath =
"c:/winnt/system32/dkck201.dll";
125 const char *driverPath =
"c:/winnt/system32/dkck232.dll";
126 const char *driverPath =
"c:/program files/eracom/cprov sw/cryptoki.dll";
127 const char *driverPath =
"c:/program files/eracom/cprov runtime/cryptoki.dll";
128 const char *driverPath =
"c:/winnt/system32/sadaptor.dll";
129 const char *driverPath =
"c:/winnt/system32/ngp11v211.dll";
130 const char *driverPath =
"c:/winnt/system32/pk2priv.dll";
131 const char *driverPath =
"c:/program files/gemplus/gclib.dll";
132 const char *driverPath =
"c:/winnt/system32/cryptoki.dll";
133 const char *driverPath =
"c:/winnt/system32/csspkcs11.dll";
134 const char *driverPath =
"c:/winnt/system32/ibmpkcss.dll";
135 const char *driverPath =
"c:/winnt/system32/id2cbox.dll";
136 const char *driverPath =
"c:/winnt/system32/cknfast.dll";
137 const char *driverPath =
"/opt/nfast/toolkits/pkcs11/libcknfast.so";
138 const char *driverPath =
"/usr/lib/libcknfast.so";
139 const char *driverPath =
"softokn3.dll";
140 const char *driverPath =
"c:/winnt/system32/nxpkcs11.dll";
141 const char *driverPath =
"c:/winnt/system32/AuCryptoki2-0.dll";
142 const char *driverPath =
"c:/winnt/system32/opensc-pkcs11.dll";
143 const char *driverPath =
"c:/winnt/system32/micardoPKCS11.dll";
144 const char *driverPath =
"c:/winnt/system32/cryptoki22.dll";
145 const char *driverPath =
"c:/winnt/system32/p11card.dll";
146 const char *driverPath =
"c:/winnt/system32/slbck.dll";
147 const char *driverPath =
"c:/winnt/system32/SetTokI.dll";
148 const char *driverPath =
"c:/winnt/system32/siecap11.dll";
149 const char *driverPath =
"c:/winnt/system32/smartp11.dll";
150 const char *driverPath =
"c:/winnt/system32/SpyPK11.dll";
152 const char *driverPath =
"c:/program files/eracom/cprov sw/cryptoki.dll";
155 printf(
"Updating cryptlib configuration to load PKCS #11 driver\n "
156 "'%s'\n as default driver...", driverPath );
162 driverPath, strlen( driverPath ) );
165 printf(
"\n\nError updating PKCS #11 device driver profile, "
166 "status %d.\n", status );
174 printf(
"\n\nError comitting device driver profile update to disk, "
175 "status %d.\n", status );
179 puts(
" done.\n\nYou'll need to restart cryptlib for the changes to "
182 puts(
"\nPress a key to exit." );
192 static void updateConfigCert(
void )
209 puts(
"Couldn't reload cryptlib configuration." );
227 #define DO_SELFTEST 0x0001
228 #define DO_LOWLEVEL 0x0002
229 #define DO_RANDOM 0x0004
230 #define DO_CONFIG 0x0008
231 #define DO_DEVICE 0x0010
232 #define DO_MIDLEVEL 0x0020
233 #define DO_CERT 0x0040
234 #define DO_KEYSETFILE 0x0080
235 #define DO_KEYSETDBX 0x0100
236 #define DO_CERTPROCESS 0x0200
237 #define DO_HIGHLEVEL 0x0400
238 #define DO_ENVELOPE 0x0800
239 #define DO_SESSION 0x1000
240 #define DO_SESSIONLOOPBACK 0x2000
241 #define DO_USER 0x4000
243 #define DO_ALL 0xFFFF
247 static void usageExit(
void )
249 puts(
"Usage: testlib [-bcdefhiklmoprstu]" );
251 puts(
" Encryption function tests:" );
252 puts(
" -l = Test low-level functions" );
253 puts(
" -m = Test mid-level functions" );
254 puts(
" -i = Test high-level functions" );
257 puts(
" Subsystem tests:" );
258 puts(
" -c = Test certificate subsystem" );
259 puts(
" -d = Test device subsystem" );
260 puts(
" -f = Test file keyset subsystem" );
261 puts(
" -k = Test database keyset subsystem" );
262 puts(
" -e = Test envelope subsystem" );
263 puts(
" -s = Test session subsystem" );
264 puts(
" -t = Test session subsystem via loopback interface" );
265 puts(
" -u = Test user subsystem" );
268 puts(
" Miscellaneous tests:" );
269 puts(
" -r = Test entropy-gathering routines" );
270 puts(
" -b = Perform built-in self-test" );
271 puts(
" -o = Test configuration management routines" );
272 puts(
" -p = Test certificate processing" );
275 puts(
" Other options:" );
276 puts(
" -h = Display this help text" );
277 puts(
" -- = End of arg list" );
280 puts(
"Default is to test all cryptlib subsystems." );
286 static int processArgs(
int argc,
char **argv,
287 int *argFlags,
const char **zargPtrPtr )
289 const char *zargPtr = NULL;
305 while( argc > 0 && *argv[ 0 ] ==
'-' && moreArgs )
307 const char *argPtr = argv[ 0 ] + 1;
311 switch( toupper( *argPtr ) )
382 zargPtr = argPtr + 1;
383 if( *zargPtr ==
'\0' )
385 puts(
"Error: Missing argument for -z option." );
390 *zargPtrPtr = zargPtr;
394 printf(
"Error: Unknown argument '%c'.\n", *argPtr );
404 printf(
"Error: Unknown argument '%s'.\n", argv[ 0 ] );
421 static void testKludge(
const char *argPtr )
429 void performanceTests(
const CRYPT_DEVICE cryptDevice );
453 puts(
"\nPress a key to exit." );
471 int main(
int argc,
char **argv )
473 const char *zargPtr = NULL;
480 #ifdef CONFIG_SUITEB_TESTS
481 return( suiteBMain( argc, argv ) );
485 printf(
"testlib - cryptlib %d-bit self-test framework.\n",
486 (
int )
sizeof(
long ) * 8 );
487 puts(
"Copyright Peter Gutmann 1995 - 2011." );
492 status = processArgs( argc, argv, &flags, &zargPtr );
508 #if ( defined( __IBMC__ ) || defined( __IBMCPP__ ) ) && !defined( __VMCMS__ )
513 printf(
"Initialising cryptlib..." );
517 printf(
"\ncryptInit() failed with error code %d, line %d.\n",
528 #if defined( __MVS__ ) || defined( __VMCMS__ )
529 #pragma convlit( resume )
531 #pragma convlit( suspend )
557 testKludge( zargPtr );
591 sessionTestError =
TRUE;
596 loopbackTestError =
TRUE;
608 puts(
"cryptEnd() failed with error code CRYPT_ERROR_INCOMPLETE, "
609 "a code path in the\nself-test code resulted in an error "
610 "return without a full cleanup of objects.\nIf you were "
611 "running the multithreaded loopback tests this may be "
612 "because one\nor more threads lost sync with other threads "
613 "and exited without cleaning up\nits objects. This "
614 "happens occasionally due to network timing issues or\n"
615 "thread scheduling differences." );
619 printf(
"cryptEnd() failed with error code %d, line %d.\n",
625 puts(
"All tests concluded successfully." );
632 puts(
"\nThe test was aborted due to an error being detected. If you "
633 "want to report\nthis problem, please provide as much information "
634 "as possible to allow it to\nbe diagnosed, for example the call "
635 "stack, the location inside cryptlib where\nthe problem occurred, "
636 "and the values of any variables that might be\nrelevant." );
637 if( sessionTestError )
639 puts(
"\nThe error occurred during one of the network session tests, "
640 "if the error\nmessage indicates a network-level problem such "
641 "as ECONNREFUSED, ECONNRESET,\nor a timeout or read error then "
642 "this is either due to a transient\nnetworking problem or a "
643 "firewall interfering with network connections. This\nisn't a "
644 "cryptlib error, and doesn't need to be reported." );
646 #ifdef WINDOWS_THREADS
647 if( loopbackTestError )
649 puts(
"\nThe error occurred during one of the multi-threaded network "
650 "loopback\ntests, this was probably due to the different threads "
651 "losing synchronisation.\nFor the secure sessions this usually "
652 "results in read/write, timeout, or\nconnection-closed errors "
653 "when one thread is pre-empted for too long. For the\n"
654 "certificate-management sessions it usually results in an error "
655 "related to the\nserver being pre-empted for too long by database "
656 "updates. Since the self-\ntest exists only to exercise "
657 "cryptlib's capabilities, it doesn't bother with\ncomplex thread "
658 "synchronisation during the multi-threaded loopback tests.\nThis "
659 "type of error is non-fatal, and should disappear if the test is "
663 #if defined( __WINDOWS__ ) && !defined( NDEBUG )
666 puts(
"\nHit a key..." );
674 #ifdef __PALMSOURCE__
676 #include <CmnErrors.h>
677 #include <CmnLaunchCodes.h>
679 uint32_t PilotMain( uint16_t cmd,
void *cmdPBP, uint16_t launchFlags )
683 case sysAppLaunchCmdNormalLaunch:
695 GLDEF_C TInt E32Main(
void )
706 EXPORT_C TInt WinsMain(
void )
713 TInt E32Dll( TDllReason )
738 #if defined( __MVS__ ) || defined( __VMCMS__ )
739 #pragma convlit( resume )
741 #if defined( __ILEC400__ )
742 #pragma convert( 819 )
745 #include "../crypt.h"
749 #if defined( __MVS__ ) || defined( __VMCMS__ )
750 #pragma convlit( suspend )
752 #if defined( __ILEC400__ )
759 static time_t testTime(
const int year )
763 memset( &theTime, 0,
sizeof(
struct tm ) );
764 theTime.tm_isdst = -1;
765 theTime.tm_year = 100 + year;
768 theTime.tm_hour = 12;
771 return( mktime( &theTime ) );
790 bigEndian = ( *(
long * )
"\x80\x00\x00\x00\x00\x00\x00\x00" < 0 );
791 #ifdef DATA_LITTLEENDIAN
794 puts(
"The CPU endianness define is set wrong in crypt.h, this "
795 "machine appears to be\nbig-endian, not little-endian. Edit "
796 "the file and rebuild cryptlib." );
802 puts(
"The CPU endianness define is set wrong in crypt.h, this "
803 "machine appears to be\nlittle-endian, not big-endian. Edit "
804 "the file and rebuild cryptlib." );
816 puts(
"The compiler you are using treats enumerated types as "
817 "variable-length non-\ninteger values, making it impossible "
818 "to reliably pass the address of an\nenum as a function "
819 "parameter. To fix this you need to rebuild cryptlib\nwith "
820 "the appropriate compiler option or pragma to ensure that\n"
821 "sizeof( enum ) == sizeof( int )." );
833 puts(
"The compiler you are using treats enumerated types as "
834 "unsigned values,\nmaking it impossible to reliably use enums "
835 "in conjunction with standard\n(signed) integers. To fix this "
836 "you need to rebuild cryptlib with the\nappropriate compiler "
837 "option or pragma to ensure that enumerated types\nare signed "
838 "like standard data types." );
846 for( i = 10; i < 36; i ++ )
848 const time_t theTime = testTime( i );
852 printf(
"Warning: This system has a buggy mktime() that can't "
853 "handle dates beyond %d.\n Some certificate tests "
854 "will fail, and long-lived CA certificates\n won't "
855 "be correctly imported.\nPress a key...\n", 2000 + i );
865 #if defined( UNIX_THREADS ) && !defined( __SCO_VERSION__ )
870 pthread_attr_init( &attr );
871 pthread_attr_getstacksize( &attr, &stackSize );
872 pthread_attr_destroy( &attr );
873 #if ( defined( sun ) && OSVERSION > 4 )
877 if( stackSize < 32768 && stackSize != 0 )
879 if( stackSize < 32768 )
882 printf(
"The pthread stack size is defaulting to %ld bytes, which is "
883 "too small for\ncryptlib to run in. To fix this, edit the "
884 "thread-creation function macro in\ncryptos.h and recompile "
885 "cryptlib.\n", (
long ) stackSize );
897 const time_t theTime = time( NULL ) - 5;
910 puts(
"Couldn't create certificate object for time sanity-check "
911 "because certificate\n" "use has been disabled, skipping "
912 "time sanity check...\n" );
915 puts(
"Couldn't create certificate object for time sanity-check." );
919 &theTime,
sizeof( time_t ) );
923 printf(
"Warning: This compiler is using a %ld-bit time_t data type, "
924 "which appears to be\n different to the one that "
925 "was used when cryptlib was built. This\n situation "
926 "usually occurs when the compiler allows the use of both\n"
927 " 32- and 64-bit time_t data types and different "
928 "options were\n selected for building cryptlib and "
929 "the test app. To resolve this,\n ensure that both "
930 "cryptlib and the code that calls it use the same\n"
931 " time_t data type.\n",
932 (
long )
sizeof( time_t ) * 8 );