39 if( envelopeInfoPtr->buffer == NULL || \
40 envelopeInfoPtr->
bufPos < 0 || \
48 if( envelopeInfoPtr->auxBuffer != NULL || \
64 cryptAlgo < CRYPT_ALGO_LAST_EXTERNAL );
130 &msgData, CRYPT_IATTRIBUTE_KEYID_OPENPGP );
134 status = cryptlibToPgpAlgo( hashAlgo, &pgpHashAlgo );
136 status = cryptlibToPgpAlgo( signAlgo, &pgpCryptAlgo );
147 sputc( stream, pgpHashAlgo );
148 sputc( stream, pgpCryptAlgo );
150 return( sputc( stream, 1 ) );
177 status = initEnvelopeEncryption( envelopeInfoPtr,
178 envelopeInfoPtr->actionList->iCryptHandle,
186 envelopeInfoPtr->lastAction = \
187 findAction( envelopeInfoPtr->preActionList,
189 if( envelopeInfoPtr->lastAction == NULL )
193 envelopeInfoPtr->lastAction = envelopeInfoPtr->actionList;
197 ENSURES( envelopeInfoPtr->lastAction != NULL );
206 sMemOpen( &stream, envelopeInfoPtr->buffer, envelopeInfoPtr->
bufSize );
207 switch( envelopeInfoPtr->usage )
212 status = writeSignatureInfoPacket( &stream,
213 envelopeInfoPtr->postActionList->iCryptHandle,
214 envelopeInfoPtr->actionList->iCryptHandle );
229 envelopeInfoPtr->payloadSize + \
255 envelopeInfoPtr->bufPos = stell( &stream );
256 sMemDisconnect( &stream );
267 envelopeInfoPtr->blockSizeMask = -1;
268 envelopeInfoPtr->lastAction = NULL;
290 int iterationCount, status =
CRYPT_OK;
296 for( lastActionPtr = envelopeInfoPtr->lastAction, iterationCount = 0;
298 lastActionPtr = lastActionPtr->
next, iterationCount++ )
300 void *bufPtr = envelopeInfoPtr->buffer + envelopeInfoPtr->bufPos;
301 const int dataLeft =
min( envelopeInfoPtr->bufSize - \
302 envelopeInfoPtr->bufPos,
317 status = iCryptExportKey( bufPtr, dataLeft, &keyexSize,
319 envelopeInfoPtr->iCryptContext,
324 status = iCryptExportKey( bufPtr, dataLeft, &keyexSize,
326 envelopeInfoPtr->iCryptContext );
330 envelopeInfoPtr->bufPos += keyexSize;
343 const int dataLeft =
min( envelopeInfoPtr->bufSize - \
344 envelopeInfoPtr->bufPos,
361 status = pgpProcessIV( envelopeInfoPtr->iCryptContext,
362 ivInfoBuffer, ivSize + 2, ivSize,
TRUE,
TRUE );
367 sMemOpen( &stream, envelopeInfoPtr->buffer + envelopeInfoPtr->
bufPos,
370 ( ivSize + 2 ) + 1 + \
372 envelopeInfoPtr->payloadSize ) + \
374 envelopeInfoPtr->payloadSize );
375 status = swrite( &stream, ivInfoBuffer, ivSize + 2 );
377 envelopeInfoPtr->bufPos += stell( &stream );
378 sMemDisconnect( &stream );
437 status = addAction( &envelopeInfoPtr->actionList,
439 iSessionKeyContext );
454 int iterationCount,
status;
463 if( envelopeInfoPtr->actionList == NULL )
465 status = createSessionKey( envelopeInfoPtr );
487 &envelopeInfoPtr->actionList->iCryptHandle,
495 for( actionListPtr =
findAction( envelopeInfoPtr->preActionList,
498 actionListPtr != NULL && \
501 actionListPtr = actionListPtr->
next, iterationCount++ )
524 status = iCryptExportKey( NULL, 0, &actionListPtr->
encodedSize,
526 envelopeInfoPtr->actionList->iCryptHandle,
537 static
int preEnvelopeSign(
const ENVELOPE_INFO *envelopeInfoPtr )
547 if( actionListPtr == NULL )
557 return( iCryptCreateSignature( NULL, 0, &actionListPtr->
encodedSize,
578 REQUIRES( sanityCheck( envelopeInfoPtr ) );
596 envelopeInfoPtr->segmentSize = envelopeInfoPtr->payloadSize;
605 status = preEnvelopeEncrypt( envelopeInfoPtr );
609 status = preEnvelopeSign( envelopeInfoPtr );
615 "Couldn't perform final %s initialisation prior to "
618 "signing" :
"encryption" ) );
624 status = deleteUnusedActions( envelopeInfoPtr );
631 ENSURES( checkActions( envelopeInfoPtr ) );
641 status = writeHeaderPacket( envelopeInfoPtr );
646 "Couldn't create envelope header" ) );
653 status = writeKeyex( envelopeInfoPtr );
658 "Couldn't emit key exchange actions to envelope "
670 status = writeEncryptedContentHeader( envelopeInfoPtr );
675 "Couldn't emit encrypted content header to envelope "
690 BYTE headerBuffer[ 64 + 8 ];
700 sMemOpen( &stream, headerBuffer, 64 );
710 envelopeInfoPtr->segmentSize += stell( &stream );
713 status = envelopeInfoPtr->copyToEnvelopeFunction( envelopeInfoPtr,
714 headerBuffer, stell( &stream ) );
715 sMemClose( &stream );
720 "Couldn't emit data header into envelope header" ) );
733 ENSURES( sanityCheck( envelopeInfoPtr ) );
745 int sigBufSize, sigSize,
status;
749 REQUIRES( sanityCheck( envelopeInfoPtr ) );
755 status = envelopeInfoPtr->copyToEnvelopeFunction( envelopeInfoPtr,
761 "Couldn't flush remaining data into envelope "
775 ENSURES( sanityCheck( envelopeInfoPtr ) );
784 sigBufSize =
min( envelopeInfoPtr->bufSize - envelopeInfoPtr->bufPos,
786 if( envelopeInfoPtr->postActionList->encodedSize + 64 > sigBufSize )
792 status = iCryptCreateSignature( envelopeInfoPtr->buffer + \
793 envelopeInfoPtr->bufPos, sigBufSize, &sigSize,
795 envelopeInfoPtr->postActionList->iCryptHandle,
796 envelopeInfoPtr->actionList->iCryptHandle, &sigParams );
801 "Couldn't emit signature to envelope trailer" ) );
803 envelopeInfoPtr->bufPos += sigSize;
808 envelopeInfoPtr->segmentDataEnd = envelopeInfoPtr->bufPos;
811 ENSURES( sanityCheck( envelopeInfoPtr ) );
832 envelopeInfoPtr->processPreambleFunction = emitPreamble;
833 envelopeInfoPtr->processPostambleFunction = emitPostamble;
850 envelopeInfoPtr->defaultHash =
algorithm;
858 envelopeInfoPtr->defaultAlgo =
algorithm;