37 if( envelopeInfoPtr->buffer == NULL || \
38 envelopeInfoPtr->
bufPos < 0 || \
88 assert(
isWritePtr( length,
sizeof(
long ) ) );
89 assert( isIndefinite == NULL || \
97 if( isIndefinite != NULL )
98 *isIndefinite =
FALSE;
105 if( isIndefinite != NULL )
106 status = pgpReadPacketHeaderI( stream, &ctb, length, minPacketSize );
108 status = pgpReadPacketHeader( stream, &ctb, length, minPacketSize );
113 ENSURES( isIndefinite != NULL );
117 *isIndefinite =
TRUE;
120 if( version > envelopeInfoPtr->version )
121 envelopeInfoPtr->version =
version;
139 const BOOLEAN isContinuedSignature )
147 assert( ( stream == NULL && \
148 envelopeInfoPtr->actionList == NULL && \
149 envelopeInfoPtr->contentList == NULL ) || \
153 envelopeInfoPtr->actionList == NULL && \
154 envelopeInfoPtr->contentList == NULL ) || \
155 ( stream != NULL ) );
168 status = createContentListItem( &contentListItem,
169 envelopeInfoPtr->memPoolState,
174 encrInfo = &contentListItem->clEncrInfo;
179 status = appendContentListItem( envelopeInfoPtr, contentListItem );
182 clFree(
"addContentListItem", contentListItem );
192 status = queryPgpObject( stream, &queryInfo );
198 ENSURES( !isContinuedSignature );
202 status = sSkip( stream, (
int ) queryInfo.
size );
208 objectSize = ( int ) queryInfo.
size;
209 if( (
object =
clAlloc(
"addContentListItem", \
210 objectSize ) ) == NULL )
212 status = sread( stream,
object, objectSize );
215 clFree(
"addContentListItem",
object );
225 if( isContinuedSignature )
229 for( contentListItem = envelopeInfoPtr->contentList, \
231 contentListItem != NULL && \
234 contentListItem = contentListItem->
next, iterationCount++ );
236 ENSURES( contentListItem != NULL && \
237 contentListItem->object == NULL && \
242 if( contentListItem->clSigInfo.hashAlgo != queryInfo.
hashAlgo || \
244 memcmp( contentListItem->keyID, queryInfo.keyID,
247 clFree(
"addContentListItem",
object );
253 contentListItem->object = object;
260 status = createContentListItem( &contentListItem,
261 envelopeInfoPtr->memPoolState,
268 clFree(
"addContentListItem",
object );
295 sigInfo->extraData = \
296 (
BYTE * ) contentListItem->object + \
305 sigInfo->extraData2 = \
306 (
BYTE * ) contentListItem->object + \
313 memcpy( contentListItem->keyID, queryInfo.keyID,
320 contentListItem->issuerAndSerialNumber = \
338 memcpy( encrInfo->saltOrIV, queryInfo.salt,
351 contentListItem->payload = \
355 if( queryInfo.
version > envelopeInfoPtr->version )
356 envelopeInfoPtr->version = queryInfo.
version;
360 if( isContinuedSignature )
375 contentListItem->clSigInfo.hashAlgo );
381 deleteContentList( envelopeInfoPtr->memPoolState,
385 status = addAction( &envelopeInfoPtr->actionList,
392 deleteContentList( envelopeInfoPtr->memPoolState,
397 status = appendContentListItem( envelopeInfoPtr, contentListItem );
400 deleteContentList( envelopeInfoPtr->memPoolState,
422 const int streamPos = stell( stream );
432 REQUIRES( sanityCheck( envelopeInfoPtr ) );
438 status = getPacketInfo( stream, envelopeInfoPtr, &packetType,
439 &packetLength, &isIndefinite,
445 "Invalid PGP packet header" ) );
460 status = length = sgetc( stream );
462 status = sSkip( stream, length + 4 );
467 "Invalid PGP data packet start" ) );
477 packetLength - ( 1 + 1 + length + 4 );
490 #ifdef USE_COMPRESSION
491 value = sgetc( stream );
518 const long payloadSize = packetLength - 1;
548 sseek( stream, streamPos );
549 status = addContentListItem( envelopeInfoPtr, stream,
FALSE );
554 "Invalid PGP %s packet",
572 envelopeInfoPtr->actionList != NULL && \
573 envelopeInfoPtr->actionList->action ==
ACTION_HASH )
581 "PGP detached signature can't be a one-pass "
582 "signature packet" ) );
596 sseek( stream, streamPos );
597 status = addContentListItem( envelopeInfoPtr, stream,
FALSE );
602 "Invalid PGP %s signature packet",
611 envelopeInfoPtr->payloadSize = 0;
621 status = value = sgetc( stream );
631 if( packetLength <= 0 || packetLength > MAX_INTLENGTH )
638 "Invalid MDC packet header" ) );
655 return( sSkip( stream, packetLength ) );
661 "Unrecognised PGP packet type %d", packetType ) );
664 ENSURES( sanityCheck( envelopeInfoPtr ) );
722 REQUIRES( sanityCheck( envelopeInfoPtr ) );
723 REQUIRES( envelopeInfoPtr->oobDataLeft < 32 + 256 );
727 if( envelopeInfoPtr->oobEventCount <= 0 )
729 status = envelopeInfoPtr->copyFromEnvelopeFunction( envelopeInfoPtr,
730 buffer, envelopeInfoPtr->oobDataLeft,
742 envelopeInfoPtr->oobDataLeft = 0;
747 ENSURES( sanityCheck( envelopeInfoPtr ) );
759 if( envelopeInfoPtr->segmentSize > 0 )
761 envelopeInfoPtr->segmentSize -=
length;
762 ENSURES( envelopeInfoPtr->segmentSize >= 0 && \
763 envelopeInfoPtr->segmentSize < MAX_INTLENGTH );
769 if( envelopeInfoPtr->segmentSize <= envelopeInfoPtr->bufPos )
771 envelopeInfoPtr->dataLeft = envelopeInfoPtr->segmentSize;
772 envelopeInfoPtr->segmentSize = 0;
785 ENSURES( sanityCheck( envelopeInfoPtr ) );
808 status = envelopeInfoPtr->copyFromEnvelopeFunction( envelopeInfoPtr,
817 sMemConnect( &headerStream, buffer, length );
818 status = getPacketInfo( &headerStream, envelopeInfoPtr, &packetType,
819 &packetLength, NULL, 8 );
822 sMemDisconnect( &headerStream );
838 envelopeInfoPtr->segmentSize = stell( &headerStream ) + \
845 envelopeInfoPtr->payloadSize = envelopeInfoPtr->segmentSize;
859 DEBUG_DIAG((
"Found EOC for unknown-length compressed "
865 envelopeInfoPtr->segmentSize = envelopeInfoPtr->payloadSize;
872 if( envelopeInfoPtr->segmentSize <= envelopeInfoPtr->bufPos )
874 envelopeInfoPtr->dataLeft = envelopeInfoPtr->segmentSize;
875 envelopeInfoPtr->segmentSize = 0;
889 ( void ) sgetc( &headerStream );
890 status = extraLen = sgetc( &headerStream );
893 envelopeInfoPtr->oobDataLeft = stell( &headerStream ) + \
896 sMemDisconnect( &headerStream );
909 envelopeInfoPtr->oobEventCount--;
911 ENSURES( sanityCheck( envelopeInfoPtr ) );
916 sMemDisconnect( &headerStream );
919 status = mapValue( packetType, &value, typeMapTbl,
923 envelopeInfoPtr->contentType =
value;
932 envelopeInfoPtr->segmentSize <= envelopeInfoPtr->bufPos )
934 envelopeInfoPtr->dataLeft = envelopeInfoPtr->segmentSize;
935 envelopeInfoPtr->segmentSize = 0;
940 envelopeInfoPtr->oobEventCount = envelopeInfoPtr->oobDataLeft = 0;
943 ENSURES( sanityCheck( envelopeInfoPtr ) );
962 REQUIRES( sanityCheck( envelopeInfoPtr ) );
967 if( envelopeInfoPtr->actionList == NULL )
977 if( envelopeInfoPtr->contentList == NULL )
979 status = addContentListItem( envelopeInfoPtr, NULL,
FALSE );
987 ENSURES( envelopeInfoPtr->actionList != NULL && \
995 status = sread( stream, ivInfoBuffer, ivSize + 2 );
998 status = pgpProcessIV( envelopeInfoPtr->actionList->iCryptHandle,
999 ivInfoBuffer, ivSize + 2, ivSize,
FALSE,
1005 envelopeInfoPtr->iCryptContext = \
1006 envelopeInfoPtr->actionList->iCryptHandle;
1009 BYTE buffer[ 1024 ], *
srcPtr = sMemBufPtr( stream );
1011 memcpy( buffer, srcPtr - 14, 32 );
1020 offset = stell( stream );
1047 envelopeInfoPtr->payloadSize -=
offset;
1063 status = addAction( &envelopeInfoPtr->actionList,
1075 ENSURES( sanityCheck( envelopeInfoPtr ) );
1095 REQUIRES( sanityCheck( envelopeInfoPtr ) );
1099 if( envelopeInfoPtr->bufPos - \
1147 DEBUG_DIAG((
"Processing MDC data at end of packet" ));
1150 status = envelopeInfoPtr->copyFromEnvelopeFunction( envelopeInfoPtr,
1156 buffer[ 0 ] != 0xD0 || buffer[ 1 ] != 0x14 )
1161 status = envelopeInfoPtr->processExtraData( envelopeInfoPtr,
1165 status = envelopeInfoPtr->processExtraData( envelopeInfoPtr,
1171 ENSURES( sanityCheck( envelopeInfoPtr ) );
1201 int remainder, streamPos = 0, iterationCount, status =
CRYPT_OK;
1205 REQUIRES( sanityCheck( envelopeInfoPtr ) );
1212 sMemConnect( &stream, envelopeInfoPtr->buffer, envelopeInfoPtr->
bufPos );
1216 for( iterationCount = 0;
1223 status = processPacketHeader( envelopeInfoPtr, &stream, &state );
1228 streamPos = stell( &stream );
1235 status = processEncryptedPacket( envelopeInfoPtr, &stream, state );
1249 "Invalid PGP encrypted data packet header",
1256 streamPos = stell( &stream );
1263 const int originalDataFlags = envelopeInfoPtr->dataFlags;
1287 status = envelopeInfoPtr->syncDeenvelopeData( envelopeInfoPtr,
1289 envelopeInfoPtr->dataFlags = originalDataFlags;
1293 "Couldn't synchronise envelope state prior "
1294 "to data payload processing", 68 );
1305 envelopeInfoPtr->oobEventCount = 1;
1311 ENSURES( checkActions( envelopeInfoPtr ) );
1328 if( envelopeInfoPtr->oobEventCount <= 0 && \
1329 envelopeInfoPtr->oobDataLeft <= 0 )
1336 status = processPacketDataHeader( envelopeInfoPtr, &state );
1340 "Invalid PGP encapsulated content header",
1346 sMemDisconnect( &stream );
1347 if( iterationCount >= FAILSAFE_ITERATIONS_MED )
1353 envelopeInfoPtr->pgpDeenvState =
state;
1355 ENSURES( streamPos >= 0 && streamPos < MAX_INTLENGTH && \
1356 envelopeInfoPtr->bufPos - streamPos >= 0 );
1360 remainder = envelopeInfoPtr->bufPos - streamPos;
1361 REQUIRES( remainder >= 0 && remainder < MAX_INTLENGTH && \
1362 streamPos + remainder <= envelopeInfoPtr->
bufSize );
1363 if( remainder > 0 && streamPos > 0 )
1366 envelopeInfoPtr->bufSize ) );
1367 memmove( envelopeInfoPtr->buffer, envelopeInfoPtr->buffer + streamPos,
1370 envelopeInfoPtr->bufPos = remainder;
1371 ENSURES( sanityCheck( envelopeInfoPtr ) );
1390 int iterationCount, status =
CRYPT_OK;
1394 REQUIRES( sanityCheck( envelopeInfoPtr ) );
1397 if( envelopeInfoPtr->usage !=
ACTION_SIGN && !hasMDC )
1404 status = processMDC( envelopeInfoPtr );
1409 "Invalid MDC packet data" ) );
1419 for( contentListPtr = envelopeInfoPtr->contentList, iterationCount = 0;
1420 contentListPtr != NULL && \
1422 iterationCount < FAILSAFE_ITERATIONS_MED;
1423 contentListPtr = contentListPtr->
next, iterationCount++ );
1424 ENSURES( iterationCount < FAILSAFE_ITERATIONS_MED );
1425 ENSURES( contentListPtr != NULL );
1432 if( contentListPtr->object == NULL )
1441 if( envelopeInfoPtr->bufPos - \
1448 sMemConnect( &stream, envelopeInfoPtr->buffer + envelopeInfoPtr->dataLeft,
1449 envelopeInfoPtr->
bufPos - envelopeInfoPtr->dataLeft );
1450 status = getPacketInfo( &stream, envelopeInfoPtr, &packetType,
1451 &packetLength, NULL, 8 );
1456 sMemDisconnect( &stream );
1459 "Invalid PGP signature packet header" ) );
1461 sseek( &stream, 0 );
1462 status = addContentListItem( envelopeInfoPtr, &stream,
TRUE );
1463 sMemDisconnect( &stream );
1468 "Invalid PGP signature packet" ) );
1478 if( envelopeInfoPtr->dataLeft > 0 )
1480 status = envelopeInfoPtr->processExtraData( envelopeInfoPtr,
1481 envelopeInfoPtr->buffer, envelopeInfoPtr->dataLeft );
1487 ENSURES( sanityCheck( envelopeInfoPtr ) );
1506 envelopeInfoPtr->processPreambleFunction = processPreamble;
1507 envelopeInfoPtr->processPostambleFunction = processPostamble;