34 #ifdef CONFIG_CONSERVE_MEMORY
35 #define MAX_PGP_OBJECTS 4
37 #define MAX_PGP_OBJECTS 16
56 sizeof(
PGP_INFO ) * noPgpObjects ) );
62 if( pgpInfo[ i ].
keyData == NULL )
66 if( i >= noPgpObjects )
69 return( (
PGP_INFO * ) &pgpInfo[ i ] );
79 if( pgpInfo->keyData != NULL )
81 zeroise( pgpInfo->keyData, pgpInfo->keyDataLen );
82 clFree(
"pgpFreeEntry", pgpInfo->keyData );
83 pgpInfo->keyData = NULL;
84 pgpInfo->keyDataLen = 0;
107 assert(
isReadPtr( password, passwordLength ) );
123 status = pgpPasswordToKey( iLocalContext,
127 password, passwordLength,
130 keyInfo->salt : NULL, keyInfo->
saltSize,
156 *iSessionKey = iLocalContext;
186 assert(
isReadPtr( requiredID, requiredIDlength ) );
207 if( !memcmp( requiredID, keyInfo->openPGPkeyID,
PGP_KEYID_SIZE ) )
223 DEBUG_DIAG((
"Couldn't create PKC context to generate key ID" ));
231 &msgData, CRYPT_IATTRIBUTE_KEYID_OPENPGP );
237 &msgData, CRYPT_IATTRIBUTE_KEY_PGP );
243 &msgData, CRYPT_IATTRIBUTE_KEYID );
248 DEBUG_DIAG((
"Couldn't initialise PKC context to generate key ID" ));
254 return( !memcmp( requiredID, keyID, requiredIDlength ) ?
TRUE :
FALSE );
278 if( keyMatchInfo->
keyIDtype == CRYPT_IKEYID_KEYID || \
279 keyMatchInfo->
keyIDtype == CRYPT_IKEYID_PGPKEYID )
281 return(
matchKeyID( keyInfo, keyMatchInfo->keyID,
283 ( keyMatchInfo->
keyIDtype == CRYPT_IKEYID_PGPKEYID ) ? \
302 if(
strFindStr( pgpInfo->userID[ i ], pgpInfo->userIDlen[ i ],
303 (
char * ) keyMatchInfo->keyID,
322 IN_FLAGS_Z( KEYMGMT )
const int requestedUsage,
326 keyIDtype, keyID, keyIDlength, requestedUsage );
330 keyMatchInfo.keyID = keyID; \
332 keyMatchInfo.
flags = requestedUsage );
335 assert(
isReadPtr( keyID, keyIDlength ) );
336 assert( keyInfo == NULL || \
342 keyIDtype == CRYPT_IKEYID_KEYID || \
343 keyIDtype == CRYPT_IKEYID_PGPKEYID );
349 KEYMGMT_MASK_USAGEOPTIONS );
352 if( keyInfo != NULL )
357 if( pgpCheckKeyMatch( &pgpInfo[ i ], &pgpInfo[ i ].
key,
360 if( keyInfo != NULL )
362 return( (
PGP_INFO * ) &pgpInfo[ i ] );
364 if( pgpCheckKeyMatch( &pgpInfo[ i ], &pgpInfo[ i ].subKey,
367 if( keyInfo != NULL )
369 return( (
PGP_INFO * ) &pgpInfo[ i ] );
372 ENSURES_N( i < FAILSAFE_ITERATIONS_MED );
391 IN_BUFFER( keyIDlength )
const void *keyID,
403 const int auxInfoMaxLength = *auxInfoLength;
408 assert(
isReadPtr( keyID, keyIDlength ) );
409 assert( ( auxInfo == NULL && auxInfoMaxLength == 0 ) || \
410 isReadPtr( auxInfo, auxInfoMaxLength ) );
419 keyIDtype == CRYPT_IKEYID_KEYID || \
420 keyIDtype == CRYPT_IKEYID_PGPKEYID );
423 REQUIRES( ( auxInfo == NULL && *auxInfoLength == 0 ) || \
424 ( auxInfo != NULL && \
425 *auxInfoLength > 0 && \
439 pgpInfo = findEntry( keysetInfoPtr->keyData, MAX_PGP_OBJECTS,
440 keyIDtype, keyID, keyIDlength, flags,
442 if( pgpInfo == NULL )
448 keyIDtype, keyID, keyIDlength, flags );
451 keyMatchInfo.keyID = keyID; \
453 keyMatchInfo.
flags = flags );
456 sseek( &keysetInfoPtr->keysetFile->stream, 0 );
457 status = pgpReadKeyring( &keysetInfoPtr->keysetFile->stream,
458 pgpInfo, 1, &keyMatchInfo, &keyInfo,
469 const int userIDsize =
min( pgpInfo->userIDlen[ 0 ],
472 REQUIRES( pgpInfo->userIDlen[ 0 ] > 0 && \
475 *auxInfoLength = userIDsize;
476 if( auxInfo != NULL )
477 memcpy( auxInfo, pgpInfo->userID[ 0 ], userIDsize );
488 if( auxInfo == NULL )
492 "Need a password to decrypt the private key" ) );
502 status = createDecryptionContext( &iDecryptionKey, keyInfo,
503 auxInfo, auxInfoMaxLength );
508 "Couldn't create decryption context for private key "
509 "from user password" ) );
527 REQUIRES( pgpInfo->userIDlen[ 0 ] > 0 && \
531 min( pgpInfo->userIDlen[ 0 ],
540 &msgData, CRYPT_IATTRIBUTE_KEYID_OPENPGP );
545 keyInfo->pubKeyDataLen );
549 CRYPT_IATTRIBUTE_KEY_PGP_PARTIAL : \
550 CRYPT_IATTRIBUTE_KEY_PGP );
557 "Couldn't recreate key from stored %s key data",
559 "private" :
"public" ) );
565 *iCryptHandle = iLocalContext;
572 keyInfo->privKeyDataLen, NULL, 0, iLocalContext,
576 ( keyInfo->hashedChecksum ?
587 "Couldn't unwrap private key" ) );
589 *iCryptHandle = iLocalContext;
609 IN_FLAGS( KEYMGMT )
const int flags )
620 password == NULL && passwordLength == 0 ) || \
622 isReadPtr( password, passwordLength ) ) );
630 REQUIRES( ( password == NULL && passwordLength == 0 ) || \
631 ( password != NULL && \
635 password == NULL && passwordLength == 0 ) || \
637 password != NULL && passwordLength != 0 ) );
660 &msgData, CRYPT_IATTRIBUTE_KEYID );
683 if( password != NULL )
692 "Item being added doesn't contain a private "
695 if( password == NULL )
707 pgpInfoPtr = findEntry( keysetInfoPtr->keyData, MAX_PGP_OBJECTS,
708 CRYPT_IKEYID_KEYID, iD, iDsize,
710 if( pgpInfoPtr != NULL )
714 "Item is already present in keyset" ) );
726 if( findEntry( keysetInfoPtr->keyData, MAX_PGP_OBJECTS,
732 "Item with this label is already present" ) );
737 pgpInfoPtr = findFreeEntry( pgpInfo, MAX_PGP_OBJECTS );
738 if( pgpInfoPtr == NULL )
742 "No more room in keyset to add this item" ) );
769 if( pgpInfo == NULL )
777 for( i = 0; i < MAX_PGP_OBJECTS; i++ )
778 pgpFreeEntry( &pgpInfo[ i ] );
781 pgpFreeEntry( pgpInfo );
782 clFree(
"shutdownFunction", pgpInfo );
783 keysetInfoPtr->keyData = NULL;
784 keysetInfoPtr->keyDataSize = 0;
805 REQUIRES( name == NULL && nameLength == 0 );
809 if( ( pgpInfo =
clAlloc(
"initPublicFunction", \
812 memset( pgpInfo, 0,
sizeof(
PGP_INFO ) );
813 if( ( pgpInfo->keyData =
clAlloc(
"initPublicFunction", \
816 clFree(
"initPublicFunction", pgpInfo );
820 keysetInfoPtr->keyData = pgpInfo;
821 keysetInfoPtr->keyDataSize =
sizeof(
PGP_INFO );
844 REQUIRES( name == NULL && nameLength == 0 );
848 if( ( pgpInfo =
clAlloc(
"initPrivateFunction", \
849 sizeof(
PGP_INFO ) * MAX_PGP_OBJECTS ) ) == NULL )
851 memset( pgpInfo, 0,
sizeof(
PGP_INFO ) * MAX_PGP_OBJECTS );
852 keysetInfoPtr->keyData = pgpInfo;
853 keysetInfoPtr->keyDataSize =
sizeof(
PGP_INFO ) * MAX_PGP_OBJECTS;
860 status = pgpReadKeyring( &keysetInfoPtr->keysetFile->stream, pgpInfo,
871 keysetInfoPtr->shutdownFunction( keysetInfoPtr );
891 keysetInfoPtr->initFunction = initPublicFunction;
892 keysetInfoPtr->shutdownFunction = shutdownFunction;
893 keysetInfoPtr->getItemFunction = getItemFunction;
894 keysetInfoPtr->setItemFunction = setItemFunction;
909 keysetInfoPtr->initFunction = initPrivateFunction;
910 keysetInfoPtr->shutdownFunction = shutdownFunction;
911 keysetInfoPtr->getItemFunction = getItemFunction;
912 keysetInfoPtr->setItemFunction = setItemFunction;