20 #define PKCS5_SALT_SIZE 8
34 static const MAP_TABLE attributeMapTbl[] = {
54 status = mapValue( attribute, &value, attributeMapTbl,
78 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
91 contextInfoPtr->capabilityInfo;
100 contextInfoPtr->encryptFunction = \
101 capabilityInfoPtr->encryptFunction;
102 contextInfoPtr->decryptFunction = \
103 capabilityInfoPtr->decryptFunction;
106 contextInfoPtr->encryptFunction = \
107 capabilityInfoPtr->encryptCBCFunction;
108 contextInfoPtr->decryptFunction = \
109 capabilityInfoPtr->decryptCBCFunction;
112 contextInfoPtr->encryptFunction = \
113 capabilityInfoPtr->encryptCFBFunction;
114 contextInfoPtr->decryptFunction = \
115 capabilityInfoPtr->decryptCFBFunction;
118 contextInfoPtr->encryptFunction = \
119 capabilityInfoPtr->encryptOFBFunction;
120 contextInfoPtr->decryptFunction = \
121 capabilityInfoPtr->decryptOFBFunction;
124 contextInfoPtr->encryptFunction = \
125 capabilityInfoPtr->encryptGCMFunction;
126 contextInfoPtr->decryptFunction = \
127 capabilityInfoPtr->decryptGCMFunction;
132 ENSURES( ( contextInfoPtr->encryptFunction == NULL && \
133 contextInfoPtr->decryptFunction == NULL ) || \
134 ( contextInfoPtr->encryptFunction != NULL && \
135 contextInfoPtr->decryptFunction != NULL ) );
136 if( contextInfoPtr->encryptFunction == NULL || \
137 contextInfoPtr->decryptFunction == NULL )
155 memcpy( convInfo->iv, data, dataLength );
158 memcpy( convInfo->currentIV, convInfo->iv, dataLength );
202 if( eccKey->
pLen <= 0 || eccKey->
aLen <= 0 || eccKey->
bLen <= 0 || \
203 eccKey->
gxLen <= 0 || eccKey->
gyLen <= 0 || eccKey->
nLen <= 0 || \
210 if( eccKey->
pLen != 0 || eccKey->
aLen != 0 || eccKey->
bLen != 0 || \
211 eccKey->
gxLen != 0 || eccKey->
gyLen != 0 || eccKey->
nLen != 0 || \
212 eccKey->
hLen != 0 || eccKey->
qxLen <= 0 || eccKey->
qyLen <= 0 || \
241 eccKey->
hLen < 1 || \
275 if( dlpKey->
pLen <= 0 || dlpKey->
qLen <= 0 || dlpKey->
gLen <= 0 || \
276 dlpKey->
yLen < 0 || dlpKey->
xLen < 0 )
316 if( rsaKey->
nLen <= 0 || rsaKey->
eLen <= 0 || \
317 rsaKey->
dLen < 0 || rsaKey->
pLen < 0 || rsaKey->
qLen < 0 || \
362 if( rsaKey->
dLen <= 0 && rsaKey->
e1Len <= 0 )
367 if( rsaKey->
dLen > 0 && \
371 if( rsaKey->
e1Len > 0 && \
377 if( rsaKey->
uLen > 0 && \
407 if( !
needsIV( contextInfoPtr->ctxConv->mode ) || \
412 return( capabilityInfoPtr->initKeyFunction( contextInfoPtr, key,
425 assert( ( key == NULL ) ||
isReadPtr( key, keyLength ) );
428 REQUIRES( ( key == NULL && keyLength == 0 ) || \
440 status = checkPKCparams( capabilityInfoPtr->
cryptAlgo, key );
443 contextInfoPtr->flags |= 0x08;
448 status = capabilityInfoPtr->initKeyFunction( contextInfoPtr, key,
451 clearTempBignums( contextInfoPtr->ctxPKC );
466 return( contextInfoPtr->capabilityInfo->initKeyFunction( contextInfoPtr,
482 return( contextInfoPtr->capabilityInfo->initKeyFunction( contextInfoPtr,
520 static const int actionFlags = \
524 static const int actionFlagsPGP = \
527 const CAPABILITY_INFO *capabilityInfoPtr = contextInfoPtr->capabilityInfo;
533 assert(
isReadPtr( keyData, keyDataLen ) );
538 REQUIRES( keyType == CRYPT_IATTRIBUTE_KEY_SPKI || \
539 keyType == CRYPT_IATTRIBUTE_KEY_PGP || \
540 keyType == CRYPT_IATTRIBUTE_KEY_SSH || \
541 keyType == CRYPT_IATTRIBUTE_KEY_SSH1 || \
542 keyType == CRYPT_IATTRIBUTE_KEY_SSL || \
543 keyType == CRYPT_IATTRIBUTE_KEY_SPKI_PARTIAL || \
544 keyType == CRYPT_IATTRIBUTE_KEY_PGP_PARTIAL );
556 REQUIRES( keyType == CRYPT_IATTRIBUTE_KEY_SPKI || \
557 keyType == CRYPT_IATTRIBUTE_KEY_SPKI_PARTIAL );
559 if( ( contextInfoPtr->ctxPKC->publicKeyInfo = \
560 clAlloc(
"setEncodedKey", keyDataLen ) ) == NULL )
562 memcpy( contextInfoPtr->ctxPKC->publicKeyInfo, keyData, keyDataLen );
563 contextInfoPtr->ctxPKC->publicKeyInfoSize =
keyDataLen;
564 return( contextInfoPtr->ctxPKC->calculateKeyIDFunction( contextInfoPtr ) );
572 sMemConnect( &stream, keyData, keyDataLen );
573 status = contextInfoPtr->ctxPKC->readPublicKeyFunction( &stream,
574 contextInfoPtr, formatType );
575 sMemDisconnect( &stream );
582 if( keyType == CRYPT_IATTRIBUTE_KEY_SPKI_PARTIAL || \
583 keyType == CRYPT_IATTRIBUTE_KEY_PGP_PARTIAL )
584 return( contextInfoPtr->ctxPKC->calculateKeyIDFunction( contextInfoPtr ) );
589 status = contextInfoPtr->loadKeyFunction( contextInfoPtr, NULL, 0 );
606 ( keyType == CRYPT_IATTRIBUTE_KEY_PGP ) ? \
611 CRYPT_IATTRIBUTE_ACTIONPERMS );
614 return( contextInfoPtr->ctxPKC->calculateKeyIDFunction( contextInfoPtr ) );
626 static const int actionFlags = \
629 const CAPABILITY_INFO *capabilityInfoPtr = contextInfoPtr->capabilityInfo;
634 assert(
isReadPtr( keyData, keyDataLen ) );
650 isDlpAlgo( capabilityInfoPtr->
cryptAlgo ) ? \
653 if( !isPublicKey && contextInfoPtr->labelSize <= 0 )
660 contextInfoPtr->labelSize <= 0 )
664 status = contextInfoPtr->loadKeyFunction( contextInfoPtr, keyData,
679 CRYPT_IATTRIBUTE_ACTIONPERMS );
684 return( contextInfoPtr->ctxPKC->calculateKeyIDFunction( contextInfoPtr ) );
699 const CAPABILITY_INFO *capabilityInfoPtr = contextInfoPtr->capabilityInfo;
701 int keyLength = contextInfoPtr->ctxConv->userKeyLength,
status;
709 keyLength = capabilityInfoPtr->
keySize;
717 if( capabilityInfoPtr->generateKeyFunction != NULL )
719 return( capabilityInfoPtr->generateKeyFunction( contextInfoPtr,
726 setMessageData( &msgData, contextInfoPtr->ctxConv->userKey, keyLength );
728 &msgData, CRYPT_IATTRIBUTE_RANDOM );
731 return( contextInfoPtr->loadKeyFunction( contextInfoPtr,
732 contextInfoPtr->ctxConv->userKey, keyLength ) );
738 const CAPABILITY_INFO *capabilityInfoPtr = contextInfoPtr->capabilityInfo;
739 int keyLength =
bitsToBytes( contextInfoPtr->ctxPKC->keySizeBits );
751 keyLength = capabilityInfoPtr->
keySize;
754 status = capabilityInfoPtr->generateKeyFunction( contextInfoPtr,
757 clearTempBignums( contextInfoPtr->ctxPKC );
760 return( contextInfoPtr->ctxPKC->calculateKeyIDFunction( contextInfoPtr ) );
766 const CAPABILITY_INFO *capabilityInfoPtr = contextInfoPtr->capabilityInfo;
768 int keyLength = contextInfoPtr->ctxMAC->userKeyLength,
status;
776 keyLength = capabilityInfoPtr->
keySize;
784 if( capabilityInfoPtr->generateKeyFunction != NULL )
786 return( capabilityInfoPtr->generateKeyFunction( contextInfoPtr,
793 setMessageData( &msgData, contextInfoPtr->ctxMAC->userKey, keyLength );
795 &msgData, CRYPT_IATTRIBUTE_RANDOM );
798 return( contextInfoPtr->loadKeyFunction( contextInfoPtr,
799 contextInfoPtr->ctxMAC->userKey, keyLength ) );
805 const CAPABILITY_INFO *capabilityInfoPtr = contextInfoPtr->capabilityInfo;
807 int keyLength = contextInfoPtr->ctxGeneric->genericSecretLength,
status;
815 keyLength = capabilityInfoPtr->
keySize;
823 if( capabilityInfoPtr->generateKeyFunction != NULL )
825 return( capabilityInfoPtr->generateKeyFunction( contextInfoPtr,
832 setMessageData( &msgData, contextInfoPtr->ctxGeneric->genericSecret, keyLength );
834 &msgData, CRYPT_IATTRIBUTE_RANDOM );
837 return( contextInfoPtr->loadKeyFunction( contextInfoPtr,
838 contextInfoPtr->ctxGeneric->genericSecret, keyLength ) );
862 int hmacAlgo = ( contextInfoPtr->type ==
CONTEXT_CONV ) ? \
863 contextInfoPtr->ctxConv->keySetupAlgorithm : \
864 contextInfoPtr->ctxMAC->keySetupAlgorithm;
868 assert(
isReadPtr( keyValue, keyValueLen ) );
878 contextInfoPtr->labelSize <= 0 )
888 status = mapValue( hmacAlgo, &
value, mapTbl,
896 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
901 contextInfoPtr->capabilityInfo->keySize;
909 CRYPT_IATTRIBUTE_RANDOM_NONCE );
916 keyValue, keyValueLen,
933 MAC_INFO *macInfo = contextInfoPtr->ctxMAC;
938 contextInfoPtr->capabilityInfo->keySize;
946 CRYPT_IATTRIBUTE_RANDOM_NONCE );
951 contextInfoPtr->ctxConv->keySetupAlgorithm = hmacAlgo;
953 keyValue, keyValueLen,
974 status = contextInfoPtr->loadKeyFunction( contextInfoPtr,
975 mechanismInfo.dataOut,
996 switch( contextInfoPtr->type )
999 contextInfoPtr->loadKeyFunction = loadKeyConvFunction;
1000 contextInfoPtr->generateKeyFunction = generateKeyConvFunction;
1004 contextInfoPtr->loadKeyFunction = loadKeyPKCFunction;
1005 contextInfoPtr->generateKeyFunction = generateKeyPKCFunction;
1009 contextInfoPtr->loadKeyFunction = loadKeyMacFunction;
1010 contextInfoPtr->generateKeyFunction = generateKeyMacFunction;
1014 contextInfoPtr->loadKeyFunction = loadKeyGenericFunction;
1015 contextInfoPtr->generateKeyFunction = generateKeyGenericFunction;