109 #ifdef USE_CERTIFICATES
155 int nonceLength, iterationCount;
178 if( !systemInfo->nonceDataInitialised )
185 &systemInfo->hashFunctionAtomic,
186 &systemInfo->hashSize );
188 systemInfo->hashSize, 8 );
191 CRYPT_IATTRIBUTE_RANDOM );
195 CRYPT_IATTRIBUTE_RANDOM );
198 const time_t theTime =
getTime();
200 memcpy( systemInfo->nonceData + systemInfo->hashSize, &theTime,
203 systemInfo->nonceDataInitialised =
TRUE;
205 ENSURES( systemInfo->hashFunctionAtomic != NULL );
206 ENSURES( systemInfo->hashSize >= 16 && \
211 for( nonceLength = dataLength, iterationCount = 0;
215 const int bytesToCopy =
min( nonceLength, systemInfo->hashSize );
219 systemInfo->hashFunctionAtomic( systemInfo->nonceData,
221 systemInfo->nonceData,
222 systemInfo->hashSize + 8 );
223 memcpy( noncePtr, systemInfo->nonceData, bytesToCopy );
226 noncePtr += bytesToCopy;
227 nonceLength -= bytesToCopy;
229 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );
234 #ifndef CONFIG_NO_SELFTEST
239 static
int algorithmSelfTest(
INOUT \
247 assert(
isReadPtr( capabilityInfoListPtrPtr, \
251 for( capabilityInfoListPtr = *capabilityInfoListPtrPtr, iterationCount = 0;
253 capabilityInfoListPtr = capabilityInfoListPtr->
next, iterationCount++ )
267 status = localStatus;
269 capabilityInfoListPrevPtr,
270 capabilityInfoListPtr );
277 capabilityInfoPtr->algoName ));
284 capabilityInfoListPrevPtr = capabilityInfoListPtr;
287 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
303 #define MECHANISM_OUTPUT_SIZE 32
304 #define MECHANISM_INPUT_SIZE 32
305 #define MECHANISM_SALT_SIZE 16
307 #define MECHANISM_OUTPUT_SIZE_SSL 48
308 #define MECHANISM_INPUT_SIZE_SSL 48
309 #define MECHANISM_SALT_SIZE_SSL 64
313 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
314 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
315 0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5, 0x96, 0x87,
316 0x78, 0x69, 0x5A, 0x4B, 0x3C, 0x2D, 0x1E, 0x0F,
317 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
318 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
322 0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5, 0x96, 0x87,
323 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
324 0x78, 0x69, 0x5A, 0x4B, 0x3C, 0x2D, 0x1E, 0x0F,
325 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
326 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
327 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
328 0x80, 0x91, 0xA2, 0xB3, 0xC4, 0xD5, 0xE6, 0xF7,
329 0x08, 0x19, 0x2A, 0x3B, 0x4C, 0x5D, 0x6E, 0x7F
335 0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5, 0x96, 0x87,
336 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
342 {
"\x73\xF7\x8A\xBE\x3C\x9C\x65\x80\x97\x60\x56\xDE\x04\x2A\x0C\x97"
346 #if defined( USE_PGP ) || defined( USE_PGPKEYS )
348 {
"\x4A\x4B\x90\x09\x27\xF8\xD0\x93\x56\x16\xEA\xC1\x45\xCD\xEE\x05"
351 saltValue, 8, 10 } },
355 {
"\x87\x46\xDD\x7D\xAD\x5F\x48\xB6\xFC\x8D\x92\xC4\xDB\x38\x79\x9A"
356 "\x3D\xEA\x22\xFA\xCD\x7E\x86\xD5\x23\x6E\x10\x4C\xBD\x84\x89\xDF"
361 {
"\xD3\xD4\x2F\xD6\xE3\x7D\xC0\x3C\xA6\x9F\x92\xDF\x3E\x40\x0A\x64"
362 "\x49\xB4\x0E\xC4\x14\x04\x2F\xC8\xDD\x27\xD5\x1C\x62\xD2\x2C\x97"
369 {
"\x80\x0B\x95\x73\x74\x3B\xC1\x63\x6B\x28\x2B\x04\x47\xFD\xF0\x04"
370 "\x80\x40\x31\xB1", 20,
377 {
"\x8A\xAA\xE6\x29\x7B\x6C\xB0\x46\x42\xAB\x5B\x07\x78\x51\x28\x4E"
378 "\xB7\x12\x8F\x1A\x2A\x7F\xBC\xA3", 24,
380 "\x01\x0A\x58\xCF\x64\x53\x0D\x82\x3F", 1 + 8, 1 } },
384 {
"\xED\x20\x34\xE3\x63\x28\x83\x0F\xF0\x9D\xF1\xE1\xA0\x7D\xD3\x57"
385 "\x18\x5D\xAC\x0D\x4F\x9E\xB3\xD4", 24,
387 "\x01\x05\xDE\xC9\x59\xAC\xFF\x72\xF7", 1 + 8, 1000 } },
390 {
"\x8B\xFB\x1D\x77\xFE\x78\xFF\xE8\xE9\x69\x76\xE0\xC5\x0A\xB6\xD2"
399 static
int mechanismSelfTest(
void )
404 for( i = 0; mechanismTestInfo[ i ].mechanismType !=
MECHANISM_NONE && \
409 &mechanismTestInfo[ i ];
412 memcpy( &mechanismInfo, &mechanismTestInfoPtr->
mechanismInfo,
414 mechanismInfo.dataOut =
buffer;
420 if( memcmp( mechanismTestInfoPtr->
mechanismInfo.dataOut, buffer,
439 static
int initCapabilities(
void );
450 REQUIRES( name == NULL && nameLength == 0 );
453 status = initCapabilities();
458 status = initRandomInfo( &deviceInfo->randomInfo );
463 deviceInfo->label =
"cryptlib system device";
464 deviceInfo->labelLen = strlen( deviceInfo->label );
474 endRandomInfo( &deviceInfo->randomInfo );
477 #ifndef CONFIG_NO_SELFTEST
487 BYTE buffer[ 8 + 8 ];
499 status = deviceInfo->getRandomFunction( deviceInfo, buffer, 8, NULL );
503 status = getNonce( deviceInfo->deviceSystem, buffer, 8 );
509 status = algorithmSelfTest( capabilityInfoListPtrPtr );
517 status = krnlSuspendObject( deviceInfo->objectHandle, &refCount );
521 return( mechanismSelfTest() );
575 return( getRandomData( deviceInfo->randomInfo, buffer, length ) );
578 status = krnlSuspendObject( deviceInfo->objectHandle, &refCount );
581 status = getRandomData( deviceInfo->randomInfo, buffer, length );
582 if( messageExtInfo == NULL || refCount > 1 )
592 DEBUG_DIAG((
"Failed to re-lock system object" ));
594 if( messageExtInfo != NULL )
619 assert( data == NULL ||
isReadPtr( data, dataLength ) );
621 REQUIRES( type == CRYPT_IATTRIBUTE_ENTROPY || \
622 type == CRYPT_IATTRIBUTE_ENTROPY_QUALITY || \
623 type == CRYPT_IATTRIBUTE_RANDOM_POLL || \
624 type == CRYPT_IATTRIBUTE_RANDOM_NONCE || \
625 type == CRYPT_IATTRIBUTE_TIME );
626 REQUIRES( ( ( type == CRYPT_IATTRIBUTE_ENTROPY || \
627 type == CRYPT_IATTRIBUTE_RANDOM_NONCE ) && \
630 ( type == CRYPT_IATTRIBUTE_TIME && \
631 data != NULL && dataLength ==
sizeof( time_t ) ) || \
632 ( ( type == CRYPT_IATTRIBUTE_ENTROPY_QUALITY || \
633 type == CRYPT_IATTRIBUTE_RANDOM_POLL ) && \
640 if( type == CRYPT_IATTRIBUTE_ENTROPY )
642 status = krnlSuspendObject( deviceInfo->objectHandle, &refCount );
646 return( addEntropyData( deviceInfo->randomInfo, data, dataLength ) );
648 if( type == CRYPT_IATTRIBUTE_ENTROPY_QUALITY )
650 status = krnlSuspendObject( deviceInfo->objectHandle, &refCount );
654 return( addEntropyQuality( deviceInfo->randomInfo, dataLength ) );
656 if( type == CRYPT_IATTRIBUTE_RANDOM_POLL )
658 status = krnlSuspendObject( deviceInfo->objectHandle, &refCount );
664 if( dataLength ==
TRUE )
673 if( type == CRYPT_IATTRIBUTE_RANDOM_NONCE )
674 return( getNonce( deviceInfo->deviceSystem, data, dataLength ) );
677 if( type == CRYPT_IATTRIBUTE_TIME )
679 time_t *timePtr = ( time_t * ) data;
696 #define MAX_NO_CAPABILITIES 32
734 #ifdef USE_HMAC_RIPEMD160
767 #ifdef USE_VENDOR_ALGOS
768 #include "vendalgo.c"
780 static
int initCapabilities(
void )
785 memset( capabilityInfoList, 0,
788 getCapabilityTable[ i ] != NULL && \
794 REQUIRES( sanityCheckCapability( capabilityInfoPtr,
FALSE ) );
797 capabilityInfoList[ i ].next = NULL;
799 capabilityInfoList[ i - 1 ].next = &capabilityInfoList[ i ];
820 deviceInfo->initFunction = initFunction;
821 deviceInfo->shutdownFunction = shutdownFunction;
822 deviceInfo->controlFunction = controlFunction;
823 #ifndef CONFIG_NO_SELFTEST
824 deviceInfo->selftestFunction = selftestFunction;
826 deviceInfo->getRandomFunction = getRandomFunction;
827 deviceInfo->capabilityInfoList = capabilityInfoList;
828 deviceInfo->createObjectFunctions = createObjectFunctions;
829 deviceInfo->createObjectFunctionCount = \
831 deviceInfo->mechanismFunctions = mechanismFunctions;
832 deviceInfo->mechanismFunctionCount = \