58 (
void ** ) &deviceInfo,
62 *iCryptDevice = iLocalDevice;
63 *hwInfoPtrPtr = deviceInfo->deviceHardware;
80 assert(
isWritePtr( keyHandle,
sizeof(
int ) ) );
86 &msgData, CRYPT_IATTRIBUTE_DEVICESTORAGEID );
101 DEBUG_PRINT((
"Object held in PKCS #15 object store doesn't "
102 "correspond to anything known to the crypto "
117 char storageFilePath[ MAX_PATH_LENGTH + 8 ];
118 int storageFilePathLen,
status;
130 status = fileBuildCryptlibPath( storageFilePath, MAX_PATH_LENGTH,
131 &storageFilePathLen,
"CLKEYS", 6,
138 createInfo.strArg1 = storageFilePath;
169 CRYPT_IATTRIBUTE_HWSTORAGE );
188 #define MAX_DEVICE_CAPABILITIES 32
199 int noCapabilities, i,
status;
211 ENSURES( noCapabilities > 0 && \
212 noCapabilities < MAX_DEVICE_CAPABILITIES );
215 memset( capabilityInfoList, 0,
217 for( i = 0; i < noCapabilities && \
220 REQUIRES( sanityCheckCapability( &capabilityInfo[ i ],
FALSE ) );
222 capabilityInfoList[ i ].
info = &capabilityInfo[ i ];
223 capabilityInfoList[ i ].
next = NULL;
225 capabilityInfoList[ i - 1 ].
next = &capabilityInfoList[ i ];
278 memcpy( hardwareInfo->label,
"Cryptographic hardware device", 29 );
280 deviceInfo->label = hardwareInfo->label;
304 static int controlFunction(
DEVICE_INFO *deviceInfo,
363 shutdownFunction( deviceInfo );
373 char storageFilePath[ MAX_PATH_LENGTH + 1 + 8 ];
374 int storageFilePathLen;
377 status = fileBuildCryptlibPath( storageFilePath, MAX_PATH_LENGTH,
378 &storageFilePathLen,
"CLKEYS", 6,
382 storageFilePath[ storageFilePathLen ] =
'\0';
383 fileErase( storageFilePath );
403 if( type == CRYPT_IATTRIBUTE_TIME )
405 time_t *timePtr = ( time_t * ) data;
465 int keyHandle, p15status,
status;
474 assert(
isReadPtr( keyID, keyIDlength ) );
480 keyIDtype == CRYPT_IKEYID_KEYID || \
481 keyIDtype == CRYPT_IKEYID_PGPKEYID || \
482 keyIDtype == CRYPT_IKEYID_ISSUERANDSERIALNUMBER );
483 REQUIRES( auxInfo == NULL && *auxInfoLength == 0 );
506 *iCryptContext = iLocalContext;
513 status = getHardwareReference( iLocalContext, &keyHandle );
520 &keyHandle, CRYPT_IATTRIBUTE_DEVICEOBJECT );
525 CRYPT_IATTRIBUTE_INITIALISED );
541 NULL, 0, flags | extraFlags );
568 status = hwLookupItemInfo( keyIDtype, keyID, keyIDlength, &keyHandle,
596 status = setPublicComponents( createInfo.
cryptHandle,
598 &keyInfo.publicKeyInfo );
604 *iCryptContext = iLocalContext;
613 if( capabilityInfoPtr == NULL )
615 status = createContextFromCapability( &iLocalContext, cryptDevice,
631 CRYPT_IATTRIBUTE_DEVICEOBJECT );
649 if( keyInfo.labelLength <= 0 )
653 keyInfo.labelLength = 22;
657 &msgData, CRYPT_IATTRIBUTE_EXISTINGLABEL );
659 status = setPublicComponents( iLocalContext, keyInfo.cryptAlgo,
660 &keyInfo.publicKeyInfo );
664 CRYPT_IATTRIBUTE_INITIALISED );
682 *iCryptContext = iLocalContext;
716 const void *keyID,
const int keyIDlength )
723 assert(
isReadPtr( keyID, keyIDlength ) );
756 status = getHardwareReference( getkeyInfo.
cryptHandle, &keyHandle );
776 const void *keyID,
const int keyIDlength,
785 assert(
isReadPtr( keyID, keyIDlength ) );
786 assert(
isWritePtr( stateInfo,
sizeof(
int ) ) );
788 REQUIRES( keyIDtype == CRYPT_IKEYID_KEYID );
798 stateInfo,
sizeof(
int ), options );
806 int *stateInfo,
const int options )
813 assert(
isWritePtr( stateInfo,
sizeof(
int ) ) );
830 stateInfo,
sizeof(
int ), options );
854 void *storageID,
const int storageIDlength )
864 assert(
isWritePtr( storageID, storageIDlength ) );
866 REQUIRES( keyHandle >= 0 && keyHandle < INT_MAX );
876 CRYPT_IATTRIBUTE_DEVICESTORAGEID );
882 CRYPT_IATTRIBUTE_DEVICEOBJECT );
888 memcpy( storageID, buffer, storageIDlength );
908 status = getContextDeviceInfo( contextInfoPtr->
objectHandle,
909 &iCryptDevice, &hardwareInfo );
941 static int generateKeyComponents(
CONTEXT_INFO *staticContextInfo,
942 PKC_INFO *contextData,
944 const int keySizeBits )
949 assert(
isWritePtr( contextData,
sizeof( PKC_INFO ) ) );
956 status = staticInitContext( staticContextInfo,
CONTEXT_PKC,
957 capabilityInfoPtr, contextData,
958 sizeof( PKC_INFO ), NULL );
963 status = capabilityInfoPtr->generateKeyFunction( staticContextInfo,
967 staticDestroyContext( staticContextInfo );
975 const int keySizeBits )
978 PKC_INFO contextData, *pkcInfo = &contextData;
990 status = generateKeyComponents( &staticContextInfo, &contextData,
996 BN_bn2bin( &pkcInfo->rsaParam_n, rsaKeyInfo->
n );
998 BN_bn2bin( &pkcInfo->rsaParam_e, rsaKeyInfo->
e );
1000 BN_bn2bin( &pkcInfo->rsaParam_p, rsaKeyInfo->
p );
1002 BN_bn2bin( &pkcInfo->rsaParam_q, rsaKeyInfo->
q );
1004 BN_bn2bin( &pkcInfo->rsaParam_exponent1, rsaKeyInfo->
e1 );
1006 BN_bn2bin( &pkcInfo->rsaParam_exponent2, rsaKeyInfo->
e2 );
1008 BN_bn2bin( &pkcInfo->rsaParam_u, rsaKeyInfo->
u );
1010 staticDestroyContext( &staticContextInfo );
1015 #if defined( USE_DH ) || defined( USE_DSA ) || defined( USE_ELGAMAL )
1018 const int keySizeBits,
1022 PKC_INFO contextData, *pkcInfo = &contextData;
1041 status = generateKeyComponents( &staticContextInfo, &contextData,
1048 status = generateKeyComponents( &staticContextInfo, &contextData,
1055 status = generateKeyComponents( &staticContextInfo, &contextData,
1067 BN_bn2bin( &pkcInfo->dlpParam_p, dlpKeyInfo->
p );
1069 BN_bn2bin( &pkcInfo->dlpParam_g, dlpKeyInfo->
g );
1071 BN_bn2bin( &pkcInfo->dlpParam_q, dlpKeyInfo->
q );
1073 BN_bn2bin( &pkcInfo->dlpParam_y, dlpKeyInfo->
y );
1075 BN_bn2bin( &pkcInfo->dlpParam_x, dlpKeyInfo->
x );
1077 staticDestroyContext( &staticContextInfo );
1084 void *keyInfo,
const int keySizeBits )
1087 contextInfoPtr->capabilityInfo->cryptAlgo;
1103 status = rsaGenerateComponents( keyInfo, keySizeBits );
1106 #if defined( USE_DH ) || defined( USE_DSA ) || defined( USE_ELGAMAL )
1110 status = dlpGenerateComponents( keyInfo, keySizeBits, cryptAlgo );
1122 return(
setPKCinfo( contextInfoPtr, cryptAlgo, keyInfo ) );
1163 status = writeFlatPublicKey( keyDataBuffer,
1185 status = writeFlatPublicKey( keyDataBuffer,
1187 &keyDataSize, cryptAlgo,
1207 CRYPT_IATTRIBUTE_KEY_SPKI_PARTIAL ) );
1220 CRYPT_IATTRIBUTE_KEYSIZE ) );
1296 deviceInfo->initFunction = initFunction;
1297 deviceInfo->shutdownFunction = shutdownFunction;
1298 deviceInfo->controlFunction = controlFunction;
1304 deviceInfo->getRandomFunction = getRandomFunction;
1307 deviceInfo->mechanismFunctionCount = \