24 #if defined( INC_ALL )
53 *param1 = *param2 = 0;
68 const ALGOID_INFO *algoIDinfoPtr = &algoIDinfoTbl[ i ];
72 algoIDinfoPtr->oid[ 6 ] == oidByte && \
73 !memcmp( algoIDinfoPtr->
oid, oid, oidLength ) )
76 *param1 = algoIDinfoPtr->
param1;
77 *param2 = algoIDinfoPtr->
param2;
94 #define ALGOTOOID_REQUIRE_VALID TRUE
95 #define ALGOTOOID_CHECK_VALID FALSE
103 const BYTE *oid = NULL;
107 REQUIRES_N( ( param1 == 0 && param2 == 0 ) || \
108 ( ( param1 > 0 && param1 <= 999 ) && param2 == 0 ) || \
109 ( ( param1 > 0 && param1 <= 999 ) && \
110 ( param2 > 0 && param2 <= 999 ) ) );
115 if( algoIDinfoTbl[ i ].
algorithm == cryptAlgo )
117 oid = algoIDinfoTbl[ i ].oid;
125 while( algoIDinfoTbl[ i ].
algorithm == cryptAlgo && \
128 if( algoIDinfoTbl[ i ].param1 == param1 )
130 oid = algoIDinfoTbl[ i ].oid;
140 while( algoIDinfoTbl[ i ].
algorithm == cryptAlgo && \
141 algoIDinfoTbl[ i ].param1 == param1 && \
144 if( algoIDinfoTbl[ i ].param2 == param2 )
146 oid = algoIDinfoTbl[ i ].oid;
181 assert( param1 == NULL ||
isWritePtr( param1,
sizeof(
int ) ) );
182 assert( param2 == NULL ||
isWritePtr( param2,
sizeof(
int ) ) );
183 assert( extraLength == NULL || \
186 REQUIRES_S( ( param1 == NULL && param2 == NULL ) || \
187 ( param1 != NULL && param2 != NULL ) );
194 *param1 = *param2 = 0;
195 if( extraLength != NULL )
201 readSequence( stream, &length );
203 readConstructed( stream, &length, tag );
204 status = readEncodedOID( stream, oidBuffer,
MAX_OID_SIZE, &oidLength,
209 if( oidLength !=
sizeofOID( oidBuffer ) || \
215 status = oidToAlgorithm( oidBuffer, oidLength, type, &localCryptAlgo,
216 &algoParam1, &algoParam2 );
219 *cryptAlgo = localCryptAlgo;
222 *param1 = algoParam1;
223 *param2 = algoParam2;
229 if( extraLength == NULL )
237 *extraLength = ( int ) length;
309 #define RC2_KEYSIZE_MAGIC 58
314 static
int readAuthEncParamData(
INOUT STREAM *stream,
319 const int paramStart = stell( stream );
323 assert(
isWritePtr( offset,
sizeof(
int ) ) );
324 assert(
isWritePtr( length,
sizeof(
int ) ) );
330 *offset = *length = 0;
333 status = readUniversal( stream );
336 paramLength = stell( stream ) - paramStart;
339 if( paramLength < 8 || paramLength > maxLength )
342 *offset = paramStart;
354 const int offset = stell( stream );
364 status = readAlgoIDheader( stream, &queryInfo->cryptAlgo, &mode, ¶m,
365 &length, tag, type );
368 queryInfo->cryptMode =
mode;
375 queryInfo->keySize =
param;
379 queryInfo->hashParam =
param;
389 if(
isPkcAlgo( queryInfo->cryptAlgo ) && \
401 isMacAlgo( queryInfo->cryptAlgo ) )
420 switch( queryInfo->cryptAlgo )
437 &queryInfo->ivLength,
441 readSequence( stream, NULL );
452 readSequence( stream, NULL );
457 &queryInfo->ivLength,
471 long val1, val2, val3;
473 readSequence( stream, NULL );
479 if( val1 != 16 || val2 != 12 || val3 != 64 )
489 &queryInfo->ivLength,
494 case CRYPT_IALGO_GENERIC_SECRET:
506 status = readSequence( stream, NULL );
510 status = readAuthEncParamData( stream,
511 &queryInfo->encParamStart,
512 &queryInfo->encParamLength,
518 status = readAuthEncParamData( stream,
519 &queryInfo->macParamStart,
520 &queryInfo->macParamLength,
521 maxLength - queryInfo->encParamLength );
529 queryInfo->encParamStart -=
offset;
530 queryInfo->macParamStart -=
offset;
533 length = stell( stream ) -
offset;
534 if( length <= 0 || length > 128 )
536 status = sseek( stream, offset );
538 status = sread( stream, queryInfo->authEncParamData,
541 queryInfo->authEncParamLength =
length;
551 CHECK_RETVAL_LENGTH \
562 sMemNullOpen( &nullStream );
563 status = writeCryptContextAlgoID( &nullStream, iCryptContext );
565 status = stell( &nullStream );
566 sMemClose( &nullStream );
579 int algoParam = 0, oidSize, ivSize = 0, sizeofIV = 0, paramSize,
status;
589 if(
cryptStatusOK( status ) && algorithm != CRYPT_IALGO_GENERIC_SECRET )
603 sizeofIV = ( int ) sizeofObject( ivSize );
615 DEBUG_DIAG((
"Couldn't extract information needed to write "
622 algorithm == CRYPT_IALGO_GENERIC_SECRET );
625 if( ( oid = algorithmToOID( algorithm, mode, algoParam, \
631 DEBUG_DIAG((
"Tried to write non-PKCS #7 algorithm ID" ));
655 writeSequence( stream, oidSize + paramSize );
656 swrite( stream, oid, oidSize );
661 return( writeOctetString( stream, iv, ivSize,
DEFAULT_TAG ) );
663 writeOctetString( stream, iv, ivSize,
DEFAULT_TAG );
664 return( writeShortInteger( stream, noBits,
DEFAULT_TAG ) );
671 writeSequence( stream, oidSize + \
672 (
int ) sizeofObject( paramSize ) );
673 swrite( stream, oid, oidSize );
674 writeSequence( stream, paramSize );
681 return( writeOctetString( stream, iv, ivSize,
DEFAULT_TAG ) );
686 writeSequence( stream, oidSize +
sizeofNull() );
687 swrite( stream, oid, oidSize );
694 sizeofShortInteger( 12 ) + \
695 sizeofShortInteger( 64 ) + \
697 writeSequence( stream, oidSize + \
698 (
int ) sizeofObject( paramSize ) );
699 swrite( stream, oid, oidSize );
700 writeSequence( stream, paramSize );
704 return( writeOctetString( stream, iv, ivSize,
DEFAULT_TAG ) );
707 case CRYPT_IALGO_GENERIC_SECRET:
712 int encAlgoDataSize, macAlgoDataSize;
719 &msgData, CRYPT_IATTRIBUTE_ENCPARAMS );
722 encAlgoDataSize = msgData.
length;
725 &msgData, CRYPT_IATTRIBUTE_MACPARAMS );
728 macAlgoDataSize = msgData.
length;
731 writeSequence( stream, oidSize + \
732 sizeofObject( encAlgoDataSize + macAlgoDataSize ) );
733 swrite( stream, oid, oidSize );
734 writeSequence( stream, encAlgoDataSize + macAlgoDataSize );
735 swrite( stream, encAlgoData, encAlgoDataSize );
736 return( swrite( stream, macAlgoData, macAlgoDataSize ) );
761 return( ( algorithmToOID( cryptAlgo, cryptMode, 0, \
770 CHECK_RETVAL_LENGTH \
775 const BYTE *oid = algorithmToOID( cryptAlgo, parameter, 0, \
779 REQUIRES( parameter >= 0 && parameter <= 999 );
783 return( (
int ) sizeofObject(
sizeofOID( oid ) + \
784 ( ( extraLength > 0 ) ? extraLength : \
788 CHECK_RETVAL_LENGTH \
806 const BYTE *oid = algorithmToOID( cryptAlgo, associatedAlgo, 0, \
820 writeSequence( stream,
sizeofOID( oid ) + \
821 ( ( extraLength > 0 ) ? extraLength :
sizeofNull() ) );
822 status = swrite( stream, oid,
sizeofOID( oid ) );
823 if( extraLength > 0 )
854 return( writeAlgoIDex( stream, cryptAlgo,
CRYPT_ALGO_NONE, paramLength) );
882 return( readAlgoIDheader( stream, cryptAlgo, NULL, NULL, NULL,
898 assert(
isWritePtr( parameter,
sizeof(
int ) ) );
906 status = readAlgoIDheader( stream, cryptAlgo, &altAlgo, parameter,
909 *altCryptAlgo = altAlgo;
921 assert(
isWritePtr( paramLength,
sizeof(
int ) ) );
925 return( readAlgoIDheader( stream, cryptAlgo, NULL, NULL, paramLength,
933 CHECK_RETVAL_LENGTH \
935 IN_RANGE( 0, 999 )
const int parameter )
940 REQUIRES( parameter >= 0 && parameter <= 999 );
973 return( writeAlgoIDex( stream, cryptAlgo, associatedAlgo, 0 ) );
990 assert( iCryptContext == NULL || \
992 assert( queryInfo == NULL || \
1000 if( iCryptContext != NULL )
1005 if( queryInfo == NULL )
1006 queryInfoPtr = &localQueryInfo;
1009 memset( queryInfoPtr, 0,
sizeof(
QUERY_INFO ) );
1013 status = readAlgoIDInfo( stream, queryInfoPtr, tag, type );
1083 assert(
isReadPtr( oid, oidLength ) && \
1091 status = readSequence( stream, &length );
1093 status = readFixedOID( stream, oid, oidLength );
1109 assert(
isReadPtr( oid, oidLength ) && \
1114 writeSequence( stream, oidLength );