58 capabilityInfoPtr->algoName == NULL || \
68 capabilityInfoPtr->getInfoFunction == NULL )
72 if( capabilityInfoPtr->encryptOFBFunction == NULL || \
73 capabilityInfoPtr->decryptOFBFunction == NULL )
83 if( capabilityInfoPtr->decryptFunction == NULL && \
84 capabilityInfoPtr->signFunction == NULL )
93 if( ( capabilityInfoPtr->encryptFunction == NULL || \
94 capabilityInfoPtr->decryptFunction == NULL ) && \
95 ( capabilityInfoPtr->encryptCBCFunction == NULL || \
96 capabilityInfoPtr->decryptCBCFunction == NULL ) && \
97 ( capabilityInfoPtr->encryptCFBFunction == NULL || \
98 capabilityInfoPtr->decryptCFBFunction == NULL ) && \
99 ( capabilityInfoPtr->encryptOFBFunction == NULL || \
100 capabilityInfoPtr->decryptOFBFunction == NULL ) && \
101 ( capabilityInfoPtr->encryptGCMFunction == NULL || \
102 capabilityInfoPtr->decryptGCMFunction == NULL ) && \
103 ( capabilityInfoPtr->signFunction == NULL || \
104 capabilityInfoPtr->sigCheckFunction == NULL ) )
124 if( capabilityInfoPtr->initParamsFunction == NULL || \
125 capabilityInfoPtr->initKeyFunction == NULL )
130 if( ( capabilityInfoPtr->encryptCBCFunction != NULL && \
131 capabilityInfoPtr->decryptCBCFunction == NULL ) || \
132 ( capabilityInfoPtr->encryptCBCFunction == NULL && \
133 capabilityInfoPtr->decryptCBCFunction != NULL ) )
135 if( ( capabilityInfoPtr->encryptCFBFunction != NULL && \
136 capabilityInfoPtr->decryptCFBFunction == NULL ) || \
137 ( capabilityInfoPtr->encryptCFBFunction == NULL && \
138 capabilityInfoPtr->decryptCFBFunction != NULL ) )
140 if( ( capabilityInfoPtr->encryptOFBFunction != NULL && \
141 capabilityInfoPtr->decryptOFBFunction == NULL ) || \
142 ( capabilityInfoPtr->encryptOFBFunction == NULL && \
143 capabilityInfoPtr->decryptOFBFunction != NULL ) )
145 if( ( capabilityInfoPtr->encryptGCMFunction != NULL && \
146 capabilityInfoPtr->decryptGCMFunction == NULL ) || \
147 ( capabilityInfoPtr->encryptGCMFunction == NULL && \
148 capabilityInfoPtr->decryptGCMFunction != NULL ) )
156 if( capabilityInfoPtr->encryptCBCFunction != NULL || \
157 capabilityInfoPtr->decryptCBCFunction != NULL || \
158 capabilityInfoPtr->encryptCFBFunction != NULL || \
159 capabilityInfoPtr->decryptCFBFunction != NULL || \
160 capabilityInfoPtr->encryptOFBFunction != NULL || \
161 capabilityInfoPtr->decryptOFBFunction != NULL || \
162 capabilityInfoPtr->encryptGCMFunction != NULL || \
163 capabilityInfoPtr->decryptGCMFunction != NULL )
172 if( capabilityInfoPtr->
blockSize != 0 || \
173 ( capabilityInfoPtr->
minKeySize < minKeySize || \
176 if( capabilityInfoPtr->initKeyFunction == NULL || \
177 capabilityInfoPtr->generateKeyFunction == NULL )
187 capabilityInfoPtr->
keySize != 0 || \
202 if( capabilityInfoPtr->initKeyFunction == NULL )
209 if( capabilityInfoPtr->
blockSize != 0 || \
213 if( capabilityInfoPtr->encryptFunction != NULL || \
214 capabilityInfoPtr->decryptFunction != NULL )
216 if( capabilityInfoPtr->initKeyFunction == NULL )
235 memcpy( cryptQueryInfo->algoName, capabilityInfoPtr->algoName,
236 capabilityInfoPtr->algoNameLen );
237 cryptQueryInfo->algoName[ capabilityInfoPtr->algoNameLen ] =
'\0';
238 cryptQueryInfo->blockSize = capabilityInfoPtr->blockSize;
239 cryptQueryInfo->minKeySize = capabilityInfoPtr->minKeySize;
240 cryptQueryInfo->keySize = capabilityInfoPtr->keySize;
241 cryptQueryInfo->maxKeySize = capabilityInfoPtr->maxKeySize;
257 for( capabilityInfoListPtr = capabilityInfoList, iterationCount = 0;
259 capabilityInfoListPtr = capabilityInfoListPtr->
next, iterationCount++ )
262 return( capabilityInfoListPtr->
info );
264 ENSURES_N( iterationCount < FAILSAFE_ITERATIONS_MED );
286 assert( contextInfoPtr == NULL || \
288 assert( ( length == 0 &&
isWritePtr( data,
sizeof(
int ) ) ) || \
289 ( length > 0 &&
isWritePtr( data, length ) ) );
332 void clearTempBignums(
INOUT PKC_INFO *pkcInfo )
334 assert(
isWritePtr( pkcInfo,
sizeof( PKC_INFO ) ) );
339 #if defined( USE_ECDH ) || defined( USE_ECDSA )
352 int initContextBignums(
INOUT PKC_INFO *pkcInfo,
353 IN_RANGE( 0, 3 )
const int sideChannelProtectionLevel,
358 assert(
isWritePtr( pkcInfo,
sizeof( PKC_INFO ) ) );
360 REQUIRES( sideChannelProtectionLevel >= 0 && \
361 sideChannelProtectionLevel <= 3 );
377 if( sideChannelProtectionLevel > 0 )
385 #if defined( USE_ECDH ) || defined( USE_ECDSA )
388 pkcInfo->isECC =
TRUE;
394 if( pkcInfo->ecCTX == NULL || pkcInfo->ecPoint == NULL || \
395 pkcInfo->tmpPoint == NULL )
397 if( pkcInfo->tmpPoint != NULL )
399 if( pkcInfo->ecPoint != NULL )
401 if( pkcInfo->ecCTX != NULL )
408 pkcInfo->bnCTX = bnCTX;
417 void freeContextBignums(
INOUT PKC_INFO *pkcInfo,
420 assert(
isWritePtr( pkcInfo,
sizeof( PKC_INFO ) ) );
443 #if defined( USE_ECDH ) || defined( USE_ECDSA )
458 if( pkcInfo->publicKeyInfo != NULL )
459 clFree(
"contextMessageFunction", pkcInfo->publicKeyInfo );
465 int calculateBignumChecksum(
INOUT PKC_INFO *pkcInfo,
470 assert(
isWritePtr( pkcInfo,
sizeof( PKC_INFO ) ) );
475 #if defined( USE_ECDH ) || defined( USE_ECDSA )
488 BN_checksum( &pkcInfo->eccParam_mont_p.RR, &checksum );
489 BN_checksum( &pkcInfo->eccParam_mont_p.N, &checksum );
490 BN_checksum( &pkcInfo->eccParam_mont_p.Ni, &checksum );
491 BN_checksum( &pkcInfo->eccParam_mont_n.RR, &checksum );
492 BN_checksum( &pkcInfo->eccParam_mont_n.N, &checksum );
493 BN_checksum( &pkcInfo->eccParam_mont_n.Ni, &checksum );
504 BN_checksum( &pkcInfo->dlpParam_mont_p.RR, &checksum );
505 BN_checksum( &pkcInfo->dlpParam_mont_p.N, &checksum );
506 BN_checksum( &pkcInfo->dlpParam_mont_p.Ni, &checksum );
516 BN_checksum( &pkcInfo->rsaParam_exponent1, &checksum );
517 BN_checksum( &pkcInfo->rsaParam_exponent2, &checksum );
518 BN_checksum( &pkcInfo->rsaParam_mont_n.RR, &checksum );
519 BN_checksum( &pkcInfo->rsaParam_mont_n.N, &checksum );
520 BN_checksum( &pkcInfo->rsaParam_mont_n.Ni, &checksum );
521 BN_checksum( &pkcInfo->rsaParam_mont_p.RR, &checksum );
522 BN_checksum( &pkcInfo->rsaParam_mont_p.N, &checksum );
523 BN_checksum( &pkcInfo->rsaParam_mont_p.Ni, &checksum );
524 BN_checksum( &pkcInfo->rsaParam_mont_q.RR, &checksum );
525 BN_checksum( &pkcInfo->rsaParam_mont_q.N, &checksum );
526 BN_checksum( &pkcInfo->rsaParam_mont_q.Ni, &checksum );
530 if( pkcInfo->checksum == 0L )
532 pkcInfo->checksum = checksum;
554 REQUIRES( minLength > 0 && minLength <= maxLength && \
571 if( bnWord <
BN_MASK2 && bnWord <= 1 )
604 if( bignumLength < minLength || bignumLength > maxLength )
605 return( CRYPT_ERROR_BADDATA );
609 if( maxRange != NULL &&
BN_cmp( bignum, maxRange ) >= 0 )
610 return( CRYPT_ERROR_BADDATA );
632 REQUIRES( minLength > 0 && minLength <= maxLength && \
644 return( CRYPT_ERROR_BADDATA );
648 return( CRYPT_ERROR_BADDATA );
653 return( CRYPT_ERROR_BADDATA );
657 if(
BN_bin2bn( buffer, length, bignum ) == NULL )
661 return( checkBignum( bignum, minLength, maxLength, maxRange,
675 assert(
isWritePtr( dataLength,
sizeof(
int ) ) );
681 memset( data, 0,
min( 16, dataMaxLength ) );
696 #if defined( USE_ECDH ) || defined( USE_ECDSA )
708 IN_OPT const void *maxRangePtr,
723 REQUIRES( minLength > 0 && minLength <= maxLength && \
736 return( CRYPT_ERROR_BADDATA );
755 if( length != ( fieldSize * 2 ) + 1 )
756 return( CRYPT_ERROR_BADDATA );
757 if( eccPointData[ 0 ] != 0x04 )
758 return( CRYPT_ERROR_BADDATA );
759 status = importBignum( bignum1, eccPointData + 1, fieldSize,
760 minLength, maxLength, maxRange, checkType );
763 return( importBignum( bignum2, eccPointData + 1 + fieldSize,
764 fieldSize, minLength, maxLength, maxRange,
769 int exportECCPoint(
OUT_BUFFER_OPT( dataMaxLength, *dataLength )
void *data,
781 assert( data == NULL ||
isWritePtr( data, dataMaxLength ) );
782 assert(
isWritePtr( dataLength,
sizeof(
int ) ) );
786 REQUIRES( ( data == NULL && dataMaxLength == 0 ) || \
788 dataMaxLength >= 16 && \
795 memset( data, 0,
min( 16, dataMaxLength ) );
801 *dataLength = 1 + ( fieldSize * 2 );
813 if( dataMaxLength < 1 + ( fieldSize * 2 ) )
816 memset( bufPtr, 0, fieldSize * 2 );
818 ENSURES( length > 0 && length <= fieldSize );
819 result =
BN_bn2bin( bignum1, bufPtr + ( fieldSize - length ) );
823 ENSURES( length > 0 && length <= fieldSize );
824 result =
BN_bn2bin( bignum2, bufPtr + ( fieldSize - length ) );
826 *dataLength = 1 + ( fieldSize * 2 );
835 void clearTempBignums(
INOUT PKC_INFO *pkcInfo )
839 int initContextBignums(
INOUT PKC_INFO *pkcInfo,
840 IN_RANGE( 0, 3 )
const int sideChannelProtectionLevel )
844 void freeContextBignums(
INOUT PKC_INFO *pkcInfo,
872 assert(
isReadPtr( contextData, contextDataSize ) );
875 REQUIRES( contextDataSize >= 32 && \
879 memset( contextData, 0, contextDataSize );
880 contextInfoPtr->type =
type;
886 contextInfoPtr->ctxConv = (
CONV_INFO * ) contextData;
887 contextInfoPtr->ctxConv->key =
keyData;
891 contextInfoPtr->ctxHash = (
HASH_INFO * ) contextData;
892 contextInfoPtr->ctxHash->hashInfo =
keyData;
896 contextInfoPtr->ctxMAC = (
MAC_INFO * ) contextData;
897 contextInfoPtr->ctxMAC->macInfo =
keyData;
905 contextInfoPtr->ctxPKC = ( PKC_INFO * ) contextData;
906 status = initContextBignums( contextData, 0,
910 initKeyID( contextInfoPtr );
911 initKeyRead( contextInfoPtr );
912 initKeyWrite( contextInfoPtr );
931 freeContextBignums( contextInfoPtr->ctxPKC,
932 ( contextInfoPtr->capabilityInfo->cryptAlgo == \
962 memcpy( temp, plaintext, capabilityInfo->
blockSize );
964 status = staticInitContext( &contextInfo,
CONTEXT_CONV, capabilityInfo,
969 status = capabilityInfo->initKeyFunction( &contextInfo, key, keySize );
971 status = capabilityInfo->encryptFunction( &contextInfo, temp,
974 memcmp( ciphertext, temp, capabilityInfo->
blockSize ) )
977 status = capabilityInfo->decryptFunction( &contextInfo, temp,
979 staticDestroyContext( &contextInfo );
981 memcmp( plaintext, temp, capabilityInfo->
blockSize ) )
1002 assert( ( data == NULL && dataLength == 0 ) || \
1006 REQUIRES( ( data == NULL && dataLength == 0 ) || \
1010 status = staticInitContext( &contextInfo,
CONTEXT_HASH, capabilityInfo,
1020 status = capabilityInfo->encryptFunction( &contextInfo,
1026 status = capabilityInfo->encryptFunction( &contextInfo,
1029 memcmp( contextInfo.ctxHash->hash, hashValue,
1032 staticDestroyContext( &contextInfo );
1042 IN_BUFFER( dataLength )
const void *data,
1053 assert(
isReadPtr( data, dataLength ) );
1059 status = staticInitContext( &contextInfo,
CONTEXT_MAC, capabilityInfo,
1064 status = capabilityInfo->initKeyFunction( &contextInfo, key, keySize );
1067 status = capabilityInfo->encryptFunction( &contextInfo,
1073 status = capabilityInfo->encryptFunction( &contextInfo,
1076 memcmp( contextInfo.ctxMAC->mac, hashValue,
1079 staticDestroyContext( &contextInfo );
1101 const HASHFUNCTION_ATOMIC
function;
1114 #ifdef USE_RIPEMD160
1123 #if defined( CONFIG_SUITEB )
1140 assert( ( hashOutputSize == NULL ) || \
1141 isWritePtr( hashOutputSize,
sizeof(
int ) ) );
1149 if( hashFunctions[ i ].cryptAlgo != hashAlgorithm )
1154 if( hashParam != 0 && hashFunctions[ i ].
hashSize != hashParam )
1168 if( hashOutputSize != NULL )
1173 *hashFunction = hashFunctions[ i ].function;
1174 if( hashOutputSize != NULL )
1175 *hashOutputSize = hashFunctions[ i ].hashSize;
1188 #ifdef USE_RIPEMD160
1197 #if defined( CONFIG_SUITEB )
1213 assert(
isWritePtr( hashFunctionAtomic,
sizeof( HASHFUNCTION_ATOMIC ) ) );
1214 assert( ( hashOutputSize == NULL ) || \
1215 isWritePtr( hashOutputSize,
sizeof(
int ) ) );
1223 if( hashFunctions[ i ].cryptAlgo != hashAlgorithm )
1228 if( hashParam != 0 && hashFunctions[ i ].
hashSize != hashParam )
1242 if( hashOutputSize != NULL )
1247 *hashFunctionAtomic = hashFunctions[ i ].function;
1248 if( hashOutputSize != NULL )
1249 *hashOutputSize = hashFunctions[ i ].hashSize;