static int getMPIsize( INOUT STREAM *stream, IN_LENGTH_PKC const int minMpiSize, IN_LENGTH_PKC const int maxMpiSize, OUT_LENGTH_SHORT_Z int *length ) { const int position = stell( stream ); int dummy, status; assert( isWritePtr( stream, sizeof( STREAM ) ) ); assert( isWritePtr( length, sizeof( int ) ) ); REQUIRES( minMpiSize > 0 && maxMpiSize > 0 && \ minMpiSize <= maxMpiSize && maxMpiSize <= CRYPT_MAX_PKCSIZE ); REQUIRES( !cryptStatusError( position ) ); /* Clear return value */ *length = 0; status = readInteger16Ubits( stream, NULL, &dummy, minMpiSize, maxMpiSize ); if( cryptStatusError( status ) ) return( status ); *length = stell( stream ) - position; return( CRYPT_OK ); }
static int pgpReadDecryptMPI( INOUT STREAM *stream, IN_HANDLE const CRYPT_CONTEXT iCryptContext, IN_LENGTH_PKC const int minLength, IN_LENGTH_PKC const int maxLength ) { void *mpiDataPtr = DUMMY_INIT_PTR; const long mpiDataStartPos = stell( stream ) + UINT16_SIZE; int mpiLength, dummy, status; assert( isWritePtr( stream, sizeof( STREAM ) ) ); REQUIRES( isHandleRangeValid( iCryptContext ) ); REQUIRES( minLength >= bitsToBytes( 155 ) && \ minLength <= maxLength && \ maxLength <= CRYPT_MAX_PKCSIZE ); /* Get the MPI length and decrypt the payload data. We have to be careful how we handle this because readInteger16Ubits() returns the canonicalised form of the values (with leading zeroes truncated) so the returned length value doesn't necessarily represent the amount of data that we need to decrypt: startPos dataStart stell() | | | v v <-- length -->v +---+-----------+---------------+ | | |///////////////| Stream +---+-----------+---------------+ */ status = readInteger16Ubits( stream, NULL, &dummy, minLength, maxLength ); if( cryptStatusError( status ) ) return( status ); mpiLength = stell( stream ) - mpiDataStartPos; status = sMemGetDataBlockAbs( stream, mpiDataStartPos, &mpiDataPtr, mpiLength ); if( cryptStatusOK( status ) ) status = krnlSendMessage( iCryptContext, IMESSAGE_CTX_DECRYPT, mpiDataPtr, mpiLength ); return( status ); }