18 #if defined( CONFIG_CONSERVE_MEMORY )
19 #define DEFAULT_BUFFER_SIZE 8192
20 #elif INT_MAX <= 32767
21 #define DEFAULT_BUFFER_SIZE 16384
23 #define DEFAULT_BUFFER_SIZE 32768
30 #define isRecoverableError( status ) \
31 ( ( status ) == CRYPT_ERROR_OVERFLOW || \
32 ( status ) == CRYPT_ERROR_UNDERFLOW )
53 assert( ( buffer == NULL && length == 0 ) || \
55 assert(
isWritePtr( bytesCopied,
sizeof(
int ) ) );
57 REQUIRES( ( buffer == NULL && length == 0 ) || \
69 status = envelopeInfoPtr->checkMissingInfo( envelopeInfoPtr );
74 if( envelopeInfoPtr->buffer == NULL )
76 if( ( envelopeInfoPtr->buffer = \
78 envelopeInfoPtr->bufSize + 8 ) ) == NULL )
80 memset( envelopeInfoPtr->buffer, 0, envelopeInfoPtr->bufSize );
84 status = envelopeInfoPtr->processPreambleFunction( envelopeInfoPtr );
88 envelopeInfoPtr->errorState =
status;
96 CRYPT_IATTRIBUTE_INITIALISED );
99 envelopeInfoPtr->errorState =
status;
114 status = envelopeInfoPtr->copyToEnvelopeFunction( envelopeInfoPtr,
119 envelopeInfoPtr->errorState =
status;
124 return( ( *bytesCopied < length ) ? \
136 status = envelopeInfoPtr->processPostambleFunction( envelopeInfoPtr,
141 envelopeInfoPtr->errorState =
status;
159 assert( ( buffer == NULL && length == 0 ) || \
161 assert(
isWritePtr( bytesCopied,
sizeof(
int ) ) );
163 REQUIRES( ( buffer == NULL && length == 0 ) || \
164 ( buffer != NULL && length > 0 && length <
MAX_INTLENGTH ) );
176 if( envelopeInfoPtr->buffer == NULL )
179 if( ( envelopeInfoPtr->buffer = \
181 envelopeInfoPtr->bufSize + 8 ) ) == NULL )
183 memset( envelopeInfoPtr->buffer, 0, envelopeInfoPtr->bufSize );
189 if( length > 0 && ( bufPtr[ 0 ] & 0x80 ) )
204 const int bytesToCopy =
min( envelopeInfoPtr->bufSize - \
205 envelopeInfoPtr->bufPos, bytesIn );
207 ENSURES( bytesToCopy >= 0 && bytesToCopy <= length && \
208 envelopeInfoPtr->bufPos + \
209 bytesToCopy <= envelopeInfoPtr->
bufSize );
210 if( bytesToCopy > 0 )
212 memcpy( envelopeInfoPtr->buffer + envelopeInfoPtr->bufPos,
213 bufPtr, bytesToCopy );
214 envelopeInfoPtr->bufPos += bytesToCopy;
215 bytesIn -= bytesToCopy;
216 *bytesCopied = bytesToCopy;
217 bufPtr += bytesToCopy;
223 status = envelopeInfoPtr->processPreambleFunction( envelopeInfoPtr );
240 envelopeInfoPtr->errorState =
status;
249 CRYPT_IATTRIBUTE_INITIALISED );
260 envelopeInfoPtr->errorState =
status;
282 const int byteCount = \
283 envelopeInfoPtr->copyToEnvelopeFunction( envelopeInfoPtr,
288 envelopeInfoPtr->errorState = byteCount;
291 *bytesCopied += byteCount;
292 bytesIn -= byteCount;
302 envelopeInfoPtr->segmentSize <= 0 ) )
335 const int bytesToCopy =
min( envelopeInfoPtr->bufSize - \
336 envelopeInfoPtr->bufPos, bytesIn );
338 ENSURES( bytesToCopy >= 0 && bytesToCopy <= bytesIn && \
339 envelopeInfoPtr->bufPos + \
340 bytesToCopy <= envelopeInfoPtr->
bufSize );
341 if( bytesToCopy > 0 )
343 memcpy( envelopeInfoPtr->buffer + envelopeInfoPtr->bufPos,
344 bufPtr, bytesToCopy );
345 envelopeInfoPtr->bufPos += bytesToCopy;
346 *bytesCopied += bytesToCopy;
355 status = envelopeInfoPtr->processPostambleFunction( envelopeInfoPtr,
361 envelopeInfoPtr->errorState =
status;
396 envelopeInfoPtr->state = \
435 status = envelopeInfoPtr->processExtraData( envelopeInfoPtr,
436 ( buffer == NULL ) ?
"" : buffer, length );
452 OUT_BUFFER( length, *bytesCopied )
void *buffer,
460 assert(
isWritePtr( bytesCopied,
sizeof(
int ) ) );
468 status = envelopeInfoPtr->copyFromEnvelopeFunction( envelopeInfoPtr,
473 envelopeInfoPtr->errorState =
status;
479 OUT_BUFFER( length, *bytesCopied )
void *buffer,
487 assert(
isWritePtr( bytesCopied,
sizeof(
int ) ) );
503 status = deenvelopePush( envelopeInfoPtr, NULL, 0, &dummy );
513 status = envelopeInfoPtr->copyFromEnvelopeFunction( envelopeInfoPtr,
518 envelopeInfoPtr->errorState =
status;
564 const BOOLEAN isAuthEnvelope = \
592 envelopeInfoPtr->dataLeft > 0 && \
593 !( isAuthEnvelope && \
606 if( envelopeInfoPtr->
bufPos > 0 )
624 #ifdef USE_COMPRESSION
652 if( envelopeInfoPtr->buffer != NULL )
655 clFree(
"envelopeMessageFunction", envelopeInfoPtr->buffer );
657 if( envelopeInfoPtr->auxBuffer != NULL )
660 clFree(
"envelopeMessageFunction", envelopeInfoPtr->auxBuffer );
678 return( getEnvelopeAttribute( envelopeInfoPtr,
679 (
int * ) messageDataPtr,
682 return( getEnvelopeAttributeS( envelopeInfoPtr,
690 if( messageValue == CRYPT_IATTRIBUTE_INITIALISED )
693 return( setEnvelopeAttribute( envelopeInfoPtr,
694 *( (
int * ) messageDataPtr ),
701 return( setEnvelopeAttributeS( envelopeInfoPtr, msgData->data,
702 msgData->
length, messageValue ) );
712 const int length = msgData->
length;
715 assert( ( msgData->data == NULL && msgData->
length == 0 ) || \
719 ( msgData->data != NULL && \
777 status = deenvelopePush( envelopeInfoPtr, msgData->data,
778 length, &bytesCopied );
780 status = envelopePush( envelopeInfoPtr, msgData->data,
781 length, &bytesCopied );
801 const int length = msgData->
length;
817 status = deenvelopePop( envelopeInfoPtr, msgData->data,
818 length, &bytesCopied );
820 status = envelopePop( envelopeInfoPtr, msgData->data,
821 length, &bytesCopied );
843 const int subType = \
856 formatType < CRYPT_FORMAT_LAST_EXTERNAL );
860 *envelopeInfoPtrPtr = NULL;
869 status = krnlCreateObject( iCryptEnvelope, (
void ** ) &envelopeInfoPtr,
877 *envelopeInfoPtrPtr = envelopeInfoPtr;
885 envelopeInfoPtr->storageSize = storageSize;
887 envelopeInfoPtr->storage, storageSize );
905 initDeenvelopeStreaming( envelopeInfoPtr );
906 initDenvResourceHandling( envelopeInfoPtr );
914 initEnvelopeStreaming( envelopeInfoPtr );
915 initEnvResourceHandling( envelopeInfoPtr );
932 REQUIRES( auxDataPtr == NULL && auxValue == 0 );
934 createInfo->arg1 < CRYPT_FORMAT_LAST_EXTERNAL );
937 initStatus = initEnvelope( &iCryptEnvelope, createInfo->cryptOwner,
938 createInfo->arg1, &envelopeInfoPtr );
942 if( envelopeInfoPtr == NULL )
943 return( initStatus );
956 createInfo->cryptHandle = iCryptEnvelope;