C_RET cryptQueryObject( C_IN void C_PTR objectData, C_IN int objectDataLength, C_OUT CRYPT_OBJECT_INFO C_PTR cryptObjectInfo ) { QUERY_INFO queryInfo = DUMMY_INIT_STRUCT; /* If USE_PGP undef'd */ STREAM stream; int value, length = objectDataLength, status; /* Perform basic error checking and clear the return value */ if( objectDataLength <= MIN_CRYPT_OBJECTSIZE || \ objectDataLength >= MAX_INTLENGTH ) return( CRYPT_ERROR_PARAM2 ); if( !isReadPtr( objectData, objectDataLength ) ) return( CRYPT_ERROR_PARAM1 ); if( !isWritePtrConst( cryptObjectInfo, sizeof( CRYPT_OBJECT_INFO ) ) ) return( CRYPT_ERROR_PARAM3 ); memset( cryptObjectInfo, 0, sizeof( CRYPT_OBJECT_INFO ) ); /* Query the object. This is just a wrapper for the lower-level object- query functions. Note that we use sPeek() rather than peekTag() because we want to continue processing (or at least checking for) PGP data if it's no ASN.1 */ sMemConnect( &stream, ( void * ) objectData, length ); status = value = sPeek( &stream ); if( cryptStatusError( status ) ) { sMemDisconnect( &stream ); return( status ); } if( value == BER_SEQUENCE || value == MAKE_CTAG( CTAG_RI_PWRI ) ) status = queryAsn1Object( &stream, &queryInfo ); else { #ifdef USE_PGP status = queryPgpObject( &stream, &queryInfo ); #else status = CRYPT_ERROR_BADDATA; #endif /* USE_PGP */ } sMemDisconnect( &stream ); if( cryptStatusError( status ) ) return( status ); /* Copy the externally-visible fields across */ cryptObjectInfo->objectType = queryInfo.type; cryptObjectInfo->cryptAlgo = queryInfo.cryptAlgo; cryptObjectInfo->cryptMode = queryInfo.cryptMode; if( queryInfo.type == CRYPT_OBJECT_SIGNATURE ) cryptObjectInfo->hashAlgo = queryInfo.hashAlgo; if( queryInfo.type == CRYPT_OBJECT_ENCRYPTED_KEY && \ queryInfo.saltLength > 0 ) { memcpy( cryptObjectInfo->salt, queryInfo.salt, queryInfo.saltLength ); cryptObjectInfo->saltSize = queryInfo.saltLength; if( queryInfo.keySetupAlgo != CRYPT_ALGO_NONE ) cryptObjectInfo->hashAlgo = queryInfo.keySetupAlgo; } return( CRYPT_OK ); }
static int initMemoryStream( OUT STREAM *stream, const BOOLEAN isNullStream ) { /* We don't use a REQUIRES() predicate here for the reasons given in the comments above */ assert( isWritePtr( stream, sizeof( STREAM ) ) ); /* Check that the input parameters are in order */ if( !isWritePtrConst( stream, sizeof( STREAM ) ) ) retIntError(); /* Clear the stream data and initialise the stream structure. Further initialisation of stream buffer parameters will be done by the caller */ memset( stream, 0, sizeof( STREAM ) ); stream->type = ( isNullStream ) ? STREAM_TYPE_NULL : STREAM_TYPE_MEMORY; return( CRYPT_OK ); }
static int shutdownMemoryStream( INOUT STREAM *stream, const BOOLEAN clearStreamBuffer ) { assert( isWritePtr( stream, sizeof( STREAM ) ) ); /* Check that the input parameters are in order */ if( !isWritePtrConst( stream, sizeof( STREAM ) ) ) retIntError(); REQUIRES( stream->type == STREAM_TYPE_NULL || \ stream->type == STREAM_TYPE_MEMORY ); /* Clear the stream structure */ if( clearStreamBuffer && stream->buffer != NULL && stream->bufEnd > 0 ) zeroise( stream->buffer, stream->bufEnd ); zeroise( stream, sizeof( STREAM ) ); return( CRYPT_OK ); }