11 #if defined( INC_ALL )
34 const int delta = ( dataLength < 16 ) ? 1 : 0;
35 int bitCount[ 4 + 8 ] = { 0 }, noOnes, i;
43 const int value = data[ i ];
45 bitCount[ value & 3 ]++;
46 bitCount[ ( value >> 2 ) & 3 ]++;
47 bitCount[ ( value >> 4 ) & 3 ]++;
48 bitCount[ ( value >> 6 ) & 3 ]++;
53 noOnes = bitCount[ 1 ] + bitCount[ 2 ] + ( 2 * bitCount[ 3 ] );
54 if( noOnes < dataLength * 2 || noOnes > dataLength * 6 )
66 if( ( bitCount[ 0 ] + delta < dataLength / 2 ) || \
67 ( bitCount[ 1 ] + delta < dataLength / 2 ) || \
68 ( bitCount[ 2 ] + delta < dataLength / 2 ) || \
69 ( bitCount[ 3 ] + delta < dataLength / 2 ) )
92 assert( ( dest == NULL && destMaxLength == 0 ) || \
94 assert(
isWritePtr( destLength,
sizeof(
int ) ) );
95 assert( ( source == NULL && sourceLength == 0 ) || \
98 REQUIRES( ( dest == NULL && destMaxLength == 0 ) || \
100 destMaxLength > 0 && \
102 REQUIRES( ( source == NULL && sourceLength == 0 ) || \
103 ( source != NULL && \
104 sourceLength > 0 && \
110 if( sourceLength <= 0 )
114 assert(
isReadPtr( source, sourceLength ) );
116 if( sourceLength > destMaxLength || \
119 memcpy( dest, source, sourceLength );
132 assert( attributeLength == 0 || \
133 isReadPtr( attribute, attributeLength ) );
138 return( attributeCopyParams( msgData->data, msgData->length,
139 &msgData->length, attribute,
179 int algo1index, algo2index;
186 algoPrecedence[ algo1index ] != algorithm1 && \
198 algoPrecedence[ algo2index ] != algorithm2 && \
212 return( ( algo1index < algo2index ) ?
TRUE :
FALSE );
221 #define RANDOM_BUFFER_SIZE 8
224 int getRandomInteger(
void )
227 static int nonceIndex = 0;
233 if( nonceIndex <= 0 )
240 CRYPT_IATTRIBUTE_RANDOM_NONCE );
242 return( (
int )
getTime() & 0x7FFF );
246 returnValue = ( nonceData[ nonceIndex ] << 8 ) | \
247 nonceData[ nonceIndex + 1 ];
252 return( returnValue & 0x7FFF );
267 assert(
isWritePtr( destValue,
sizeof(
int ) ) );
271 REQUIRES( mapTblSize > 0 && mapTblSize < 100 );
278 for( i = 0; i < mapTblSize && mapTbl[ i ].source !=
CRYPT_ERROR && \
281 if( mapTbl[ i ].source == srcValue )
283 *destValue = mapTbl[ i ].destination;
314 int sum1 = 0, sum2 = 0, i;
323 sum1 += dataPtr[ i ];
327 return( sum2 & 0xFFFF );
346 assert( hashMaxLength >= 16 && \
352 if( hashFunctionAtomic == NULL )
366 if( data == NULL || dataLength <= 0 || dataLength >=
MAX_INTLENGTH || \
367 hashMaxLength < 16 || hashMaxLength > hashSize || \
370 memset( hash, 0, hashMaxLength );
379 memcpy( hash, hashBuffer, hashMaxLength );
401 for( i = 0; i <
length; i++ )
402 value |= srcPtr[ i ] ^ destPtr[ i ];
431 void *dataPtr = NULL;
432 int attrLength = 0,
status;
445 if( !sIsNullStream( stream ) )
452 status = sMemGetDataBlock( stream, &dataPtr, length );
458 status = sMemGetDataBlockRemaining( stream, &dataPtr,
468 &msgData, attributeType );
486 return( exportAttr( streamPtr, cryptHandle, attributeType, \
496 const int attributeDataLength )
501 REQUIRES( attributeType == CRYPT_IATTRIBUTE_RANDOM_NONCE );
502 REQUIRES( attributeDataLength >= 8 && attributeDataLength <= 1024 );
504 return( exportAttr( streamPtr, cryptHandle, attributeType,
505 attributeDataLength ) );
516 void *dataPtr = NULL;
527 if( !sIsNullStream( stream ) )
529 status = sMemGetDataBlockRemaining( stream, &dataPtr, &length );
537 &msgData, certFormatType );
544 int importCertFromStream(
INOUT void *streamPtr,
572 status = sMemGetDataBlock( stream, &dataPtr, certDataLength );
574 status = sSkip( stream, certDataLength );
580 certDataLength, certType );
607 const BOOLEAN hasAlgoParameters )
609 const long startPos = stell( stream );
625 readUniversal( stream );
626 status = readBitStringHole( stream, &keyLength,
634 return( sseek( stream, startPos ) );
639 if( hasAlgoParameters )
641 readSequence( stream, NULL );
648 readSequence( stream, NULL );
660 return( sseek( stream, startPos ) );
692 status = getStreamObjectLength( stream, &spkiLength );
694 status = sMemGetDataBlock( stream, &spkiPtr, spkiLength );
697 status = readGenericHole( stream, NULL,
703 status = readAlgoIDparam( stream, &cryptAlgo, &length,
715 status = checkKeyLength( stream, cryptAlgo,
724 readUniversal( stream );
725 status = readUniversal( stream );
738 &msgData, deferredLoad ? \
739 CRYPT_IATTRIBUTE_KEY_SPKI_PARTIAL : \
740 CRYPT_IATTRIBUTE_KEY_SPKI );
746 DEBUG_DIAG((
"Public-key load returned argError status" ));
783 #define MAX_LINE_LENGTH 4096
795 const int value1,
const int value2 )
802 format, value1, value2 ) );
806 int readTextLine( READCHARFUNCTION readCharFunction,
807 INOUT void *streamPtr,
815 int totalChars, bufPos = 0;
818 assert(
isWritePtr( lineBuffer, lineBufferMaxLen ) );
819 assert(
isWritePtr( lineBufferSize,
sizeof(
int ) ) );
820 assert( localError == NULL || \
823 REQUIRES( readCharFunction != NULL );
824 REQUIRES( lineBufferMaxLen >= 16 && \
828 memset( lineBuffer, 0,
min( 16, lineBufferMaxLen ) );
830 if( localError != NULL )
834 seenWhitespace =
TRUE;
843 ch = readCharFunction( streamPtr );
853 while( bufPos > 0 && lineBuffer[ bufPos - 1 ] ==
' ' )
862 if( seenContinuation )
864 seenContinuation =
FALSE;
879 if( bufPos > lineBufferMaxLen - 8 )
883 if( ch <= 0 || ch > 0x7F || !
isPrint( ch ) )
887 if( localError != NULL )
889 formatTextLineError( &errorInfo,
"Invalid character 0x%02X "
890 "at position %d", ch, totalChars );
902 if( ch ==
' ' || ch ==
'\t' )
913 if( ch <= 0 || ch > 0x7F || !
isPrint( ch ) )
917 if( localError != NULL )
919 formatTextLineError( &errorInfo,
"Invalid character 0x%02X at "
920 "position %d", ch, totalChars );
926 lineBuffer[ bufPos++ ] =
intToByte( ch );
927 ENSURES( bufPos > 0 && bufPos <= totalChars + 1 );
937 seenWhitespace = ( ch ==
' ' ) ?
TRUE :
FALSE;
938 seenContinuation = ( ch ==
';' || \
939 ( seenContinuation && seenWhitespace ) ) ? \
942 if( totalChars >= MAX_LINE_LENGTH )
946 if( localError != NULL )
948 formatTextLineError( &errorInfo,
"Text line too long", 0, 0 );
954 *lineBufferSize = bufPos;