53 return( exitError( contextInfoPtr, errorLocus,
66 return( exitError( contextInfoPtr, errorLocus,
79 return( exitError( contextInfoPtr, errorLocus,
101 assert(
isWritePtr( valuePtr,
sizeof(
int ) ) );
112 *valuePtr = contextInfoPtr->errorType;
116 *valuePtr = contextInfoPtr->errorLocus;
120 *valuePtr = ( contextInfoPtr->flags & \
121 CONTEXT_FLAG_SIDECHANNELPROTECTION ) ? 1 : 0;
128 *valuePtr = capabilityInfoPtr->
cryptAlgo;
134 *valuePtr = contextInfoPtr->ctxConv->mode;
138 switch( contextType )
141 value = contextInfoPtr->ctxConv->userKeyLength;
145 value =
bitsToBytes( contextInfoPtr->ctxPKC->keySizeBits );
149 value = contextInfoPtr->ctxMAC->userKeyLength;
153 value = contextInfoPtr->ctxGeneric->genericSecretLength;
163 value = capabilityInfoPtr->
keySize;
174 *valuePtr = capabilityInfoPtr->
blockSize;
180 if( !
needsIV( contextInfoPtr->ctxConv->mode ) || \
183 *valuePtr = capabilityInfoPtr->
blockSize;
188 switch( contextType )
191 value = contextInfoPtr->ctxConv->keySetupAlgorithm;
195 value = contextInfoPtr->ctxMAC->keySetupAlgorithm;
202 return( exitErrorNotInited( contextInfoPtr,
209 switch( contextType )
212 value = contextInfoPtr->ctxConv->keySetupIterations;
216 value = contextInfoPtr->ctxMAC->keySetupIterations;
223 return( exitErrorNotInited( contextInfoPtr,
233 case CRYPT_IATTRIBUTE_KEYFEATURES:
236 *valuePtr = ( contextInfoPtr->flags & CONTEXT_FLAG_PBO ) ? 1 : 0;
242 case CRYPT_IATTRIBUTE_DEVICEOBJECT:
246 *valuePtr = contextInfoPtr->deviceObject;
276 return( attributeCopy( msgData, capabilityInfoPtr->algoName,
282 switch( contextInfoPtr->ctxConv->mode )
285 return( attributeCopy( msgData,
"ECB", 3 ) );
287 return( attributeCopy( msgData,
"CBC", 3 ) );
289 return( attributeCopy( msgData,
"CFB", 3 ) );
291 return( attributeCopy( msgData,
"OFB", 3 ) );
301 if( contextInfoPtr->ctxConv->saltLength <= 0 )
302 return( exitErrorInited( contextInfoPtr,
304 return( attributeCopy( msgData, contextInfoPtr->ctxConv->salt,
305 contextInfoPtr->ctxConv->saltLength ) );
307 if( contextInfoPtr->ctxMAC->saltLength <= 0 )
308 return( exitErrorInited( contextInfoPtr,
310 return( attributeCopy( msgData, contextInfoPtr->ctxMAC->salt,
311 contextInfoPtr->ctxMAC->saltLength ) );
316 if( !
needsIV( contextInfoPtr->ctxConv->mode ) || \
321 return( attributeCopy( msgData, contextInfoPtr->ctxConv->iv,
322 contextInfoPtr->ctxConv->ivLength ) );
332 return( attributeCopy( msgData, ( contextType ==
CONTEXT_HASH ) ? \
333 contextInfoPtr->ctxHash->hash : \
334 contextInfoPtr->ctxMAC->mac,
338 if( contextInfoPtr->labelSize <= 0 )
339 return( exitErrorNotInited( contextInfoPtr,
341 return( attributeCopy( msgData, contextInfoPtr->label,
342 contextInfoPtr->labelSize ) );
344 case CRYPT_IATTRIBUTE_KEYID:
346 REQUIRES( memcmp( contextInfoPtr->ctxPKC->keyID,
347 "\x00\x00\x00\x00\x00\x00\x00\x00", 8 ) );
349 return( attributeCopy( msgData, contextInfoPtr->ctxPKC->keyID,
352 case CRYPT_IATTRIBUTE_KEYID_PGP2:
357 return( attributeCopy( msgData, contextInfoPtr->ctxPKC->pgp2KeyID,
360 case CRYPT_IATTRIBUTE_KEYID_OPENPGP:
365 return( attributeCopy( msgData, contextInfoPtr->ctxPKC->openPgpKeyID,
368 case CRYPT_IATTRIBUTE_KEY_SPKI:
369 case CRYPT_IATTRIBUTE_KEY_SPKI_PARTIAL:
379 if( contextInfoPtr->ctxPKC->publicKeyInfo != NULL )
383 return( attributeCopy( msgData, contextInfoPtr->ctxPKC->publicKeyInfo,
384 contextInfoPtr->ctxPKC->publicKeyInfoSize ) );
386 ENSURES( attribute == CRYPT_IATTRIBUTE_KEY_SPKI );
389 case CRYPT_IATTRIBUTE_KEY_PGP:
390 case CRYPT_IATTRIBUTE_KEY_SSH:
391 case CRYPT_IATTRIBUTE_KEY_SSH1:
392 case CRYPT_IATTRIBUTE_KEY_SSL:
404 sMemOpenOpt( &stream, msgData->data, msgData->length );
405 status = contextInfoPtr->ctxPKC->writePublicKeyFunction( &stream,
406 contextInfoPtr, formatType,
409 msgData->length = stell( &stream );
410 sMemDisconnect( &stream );
414 case CRYPT_IATTRIBUTE_PGPVALIDITY:
417 *( ( time_t * ) msgData->data ) = \
418 contextInfoPtr->ctxPKC->pgpCreationTime;
421 case CRYPT_IATTRIBUTE_DEVICESTORAGEID:
423 if( contextInfoPtr->deviceStorageIDset )
424 return( attributeCopy( msgData, contextInfoPtr->deviceStorageID,
429 case CRYPT_IATTRIBUTE_ENCPARAMS:
432 if( contextInfoPtr->ctxGeneric->encAlgoParamSize <= 0 )
434 return( attributeCopy( msgData,
435 contextInfoPtr->ctxGeneric->encAlgoParams,
436 contextInfoPtr->ctxGeneric->encAlgoParamSize ) );
438 case CRYPT_IATTRIBUTE_MACPARAMS:
441 if( contextInfoPtr->ctxGeneric->macAlgoParamSize <= 0 )
443 return( attributeCopy( msgData,
444 contextInfoPtr->ctxGeneric->macAlgoParams,
445 contextInfoPtr->ctxGeneric->macAlgoParamSize ) );
447 case CRYPT_IATTRIBUTE_ICV:
453 contextInfoPtr, msgData->data,
473 const CAPABILITY_INFO *capabilityInfoPtr = contextInfoPtr->capabilityInfo;
508 return( exitErrorInited( contextInfoPtr,
516 return( exitErrorInited( contextInfoPtr,
519 if( capabilityInfoPtr->encryptCBCFunction != NULL )
522 return( exitErrorInited( contextInfoPtr,
530 return( exitErrorInited( contextInfoPtr,
537 return( capabilityInfoPtr->initParamsFunction( contextInfoPtr,
548 switch( contextType )
551 valuePtr = &contextInfoPtr->ctxConv->userKeyLength;
555 valuePtr = &contextInfoPtr->ctxPKC->keySizeBits;
559 valuePtr = &contextInfoPtr->ctxMAC->userKeyLength;
563 valuePtr = &contextInfoPtr->ctxGeneric->genericSecretLength;
570 return( exitErrorInited( contextInfoPtr,
607 if( capabilityInfoPtr->initParamsFunction == NULL )
609 return( capabilityInfoPtr->initParamsFunction( contextInfoPtr,
625 return( exitError( contextInfoPtr, attribute,
631 &contextInfoPtr->ctxConv->keySetupAlgorithm : \
632 &contextInfoPtr->ctxMAC->keySetupAlgorithm;
634 return( exitErrorInited( contextInfoPtr, attribute ) );
635 *algoValuePtr =
value;
645 &contextInfoPtr->ctxConv->keySetupIterations : \
646 &contextInfoPtr->ctxMAC->keySetupIterations;
648 return( exitErrorInited( contextInfoPtr,
676 if( ( value != 0 ) && \
687 case CRYPT_IATTRIBUTE_KEYSIZE:
692 contextInfoPtr->labelSize <= 0 )
699 switch( contextType )
702 contextInfoPtr->ctxConv->userKeyLength =
value;
706 contextInfoPtr->ctxPKC->keySizeBits =
bytesToBits( value );
710 contextInfoPtr->ctxMAC->userKeyLength =
value;
714 contextInfoPtr->ctxGeneric->genericSecretLength =
value;
722 case CRYPT_IATTRIBUTE_DEVICEOBJECT:
730 contextInfoPtr->ctxConv->userKeyLength > 0 ) || \
732 contextInfoPtr->ctxPKC->keySizeBits > 0 && \
733 contextInfoPtr->ctxPKC->publicKeyInfo != NULL ) || \
735 contextInfoPtr->ctxMAC->userKeyLength > 0 ) || \
737 contextInfoPtr->ctxGeneric->genericSecretLength > 0 ) || \
742 contextInfoPtr->deviceObject =
value;
759 const CAPABILITY_INFO *capabilityInfoPtr = contextInfoPtr->capabilityInfo;
779 if( contextInfoPtr->ctxConv->saltLength > 0 )
780 return( exitErrorInited( contextInfoPtr,
782 memcpy( contextInfoPtr->ctxConv->salt, data, dataLength );
783 contextInfoPtr->ctxConv->saltLength =
dataLength;
786 if( contextInfoPtr->ctxMAC->saltLength > 0 )
787 return( exitErrorInited( contextInfoPtr,
789 memcpy( contextInfoPtr->ctxMAC->salt, data, dataLength );
790 contextInfoPtr->ctxMAC->saltLength =
dataLength;
794 return( deriveKey( contextInfoPtr, data, dataLength ) );
805 contextInfoPtr->labelSize <= 0 )
806 return( exitErrorNotInited( contextInfoPtr,
812 if( dataLength < capabilityInfoPtr->
minKeySize || \
817 status = contextInfoPtr->loadKeyFunction( contextInfoPtr,
825 return( setKeyComponents( contextInfoPtr, data, dataLength ) );
833 if( !
needsIV( contextInfoPtr->ctxConv->mode ) || \
842 if( dataLength < 8 || \
843 dataLength > capabilityInfoPtr->
blockSize )
848 if( dataLength != capabilityInfoPtr->
blockSize )
853 return( capabilityInfoPtr->initParamsFunction( contextInfoPtr,
860 if( contextInfoPtr->labelSize > 0 )
861 return( exitErrorInited( contextInfoPtr,
894 data, dataLength, NULL, 0,
918 case CRYPT_IATTRIBUTE_EXISTINGLABEL:
927 if( contextInfoPtr->labelSize > 0 )
928 return( exitErrorInited( contextInfoPtr,
932 memcpy( contextInfoPtr->label, data, dataLength );
936 case CRYPT_IATTRIBUTE_KEYID_OPENPGP:
943 memcpy( contextInfoPtr->ctxPKC->openPgpKeyID, data, dataLength );
953 memcpy( contextInfoPtr->ctxPKC->pgp2KeyID,
959 case CRYPT_IATTRIBUTE_KEY_SPKI:
960 case CRYPT_IATTRIBUTE_KEY_PGP:
961 case CRYPT_IATTRIBUTE_KEY_SSH:
962 case CRYPT_IATTRIBUTE_KEY_SSH1:
963 case CRYPT_IATTRIBUTE_KEY_SSL:
964 case CRYPT_IATTRIBUTE_KEY_SPKI_PARTIAL:
965 case CRYPT_IATTRIBUTE_KEY_PGP_PARTIAL:
968 return( setEncodedKey( contextInfoPtr, attribute, data,
971 case CRYPT_IATTRIBUTE_PGPVALIDITY:
974 contextInfoPtr->ctxPKC->pgpCreationTime = *( ( time_t * ) data );
977 case CRYPT_IATTRIBUTE_DEVICESTORAGEID:
980 memset( contextInfoPtr->deviceStorageID, 0,
KEYID_SIZE );
981 memcpy( contextInfoPtr->deviceStorageID, data, dataLength );
982 contextInfoPtr->deviceStorageIDset =
TRUE;
986 case CRYPT_IATTRIBUTE_ENCPARAMS:
989 memcpy( contextInfoPtr->ctxGeneric->encAlgoParams, data,
991 contextInfoPtr->ctxGeneric->encAlgoParamSize =
dataLength;
995 case CRYPT_IATTRIBUTE_MACPARAMS:
998 memcpy( contextInfoPtr->ctxGeneric->macAlgoParams, data,
1000 contextInfoPtr->ctxGeneric->macAlgoParamSize =
dataLength;
1004 case CRYPT_IATTRIBUTE_AAD:
1011 return( capabilityInfoPtr->initParamsFunction( contextInfoPtr,
1046 return( exitErrorNotFound( contextInfoPtr,
1052 return( exitErrorNotFound( contextInfoPtr,
1063 if( contextInfoPtr->ctxConv->keySetupIterations == 0 )
1064 return( exitErrorNotFound( contextInfoPtr,
1066 contextInfoPtr->ctxConv->keySetupIterations = 0;
1069 if( contextInfoPtr->ctxMAC->keySetupIterations == 0 )
1070 return( exitErrorNotFound( contextInfoPtr,
1072 contextInfoPtr->ctxMAC->keySetupIterations = 0;
1081 if( contextInfoPtr->ctxConv->saltLength == 0 )
1082 return( exitErrorNotFound( contextInfoPtr,
1085 contextInfoPtr->ctxConv->saltLength = 0;
1088 if( contextInfoPtr->ctxMAC->saltLength == 0 )
1089 return( exitErrorNotFound( contextInfoPtr,
1092 contextInfoPtr->ctxMAC->saltLength = 0;
1098 if( !
needsIV( contextInfoPtr->ctxConv->mode ) || \
1100 return( exitErrorNotFound( contextInfoPtr,
1102 contextInfoPtr->ctxConv->ivLength = \
1103 contextInfoPtr->ctxConv->ivCount = 0;
1108 if( contextInfoPtr->labelSize <= 0 )
1109 return( exitErrorNotFound( contextInfoPtr,
1111 zeroise( contextInfoPtr->label, contextInfoPtr->labelSize );
1112 contextInfoPtr->labelSize = 0;
1116 switch( contextType )
1130 CONTEXT_FLAG_HASH_DONE );