10 #define _CRYPT_DEFINED
27 #if defined( SYMANTEC_C ) && !defined( INC_ALL )
28 #error You need to predefine INC_ALL in your project file
34 #if ( defined( _MSC_VER ) && ( _MSC_VER >= 1000 ) ) || defined ( __MWERKS__ )
40 #if !defined( __STDC_WANT_LIB_EXT1__ )
41 #define __STDC_WANT_LIB_EXT1__ 1
48 #if ( defined( _WINDOWS ) || defined( WIN32 ) || defined( _WIN32 ) || \
49 defined( __WIN32__ ) ) && !defined( _SCCTK )
56 #define NODEFERWINDOWPOS
69 #if defined( _MSC_VER ) && ( _MSC_VER > 800 )
82 #define NOVIRTUALKEYCODES
107 #if ( defined( __PALMSOURCE__ ) && defined( _PACC_VER ) ) || \
108 ( defined( __QNX__ ) && ( OSVERSION <= 4 ) )
112 #define CRYPT_ALGO_LAST CRYPT_ALGO_LAST, CRYPT_ALGO_ENUM = -50000
113 #define CRYPT_MODE_LAST CRYPT_MODE_LAST, CRYPT_MODE_ENUM = -50000
114 #define CRYPT_KEYSET_LAST CRYPT_KEYSET_LAST, CRYPT_KEYSET_ENUM = -50000
115 #define CRYPT_DEVICE_LAST CRYPT_DEVICE_LAST, CRYPT_DEVICE_ENUM = -50000
116 #define CRYPT_CERTTYPE_LAST CRYPT_CERTTYPE_LAST, CRYPT_CERTTYPE_ENUM = -50000
117 #define CRYPT_FORMAT_LAST CRYPT_FORMAT_LAST, CRYPT_FORMAT_ENUM = -50000
118 #define CRYPT_SESSION_LAST CRYPT_SESSION_LAST, CRYPT_SESSION_ENUM = -50000
119 #define CRYPT_USER_LAST CRYPT_USER_LAST, CRYPT_USER_ENUM = -50000
120 #define CRYPT_IATTRIBUTE_LAST CRYPT_IATTRIBUTE_LAST, CRYPT_IATTRIBUTE_ENUM = -50000
121 #define CRYPT_CRLEXTREASON_LAST CRYPT_CRLEXTREASON_LAST, CRYPT_CRLEXTREASON_ENUM = -50000
122 #define CRYPT_CONTENT_LAST CRYPT_CONTENT_LAST, CRYPT_CONTENT_ENUM = -50000
123 #define CRYPT_SIGNATURELEVEL_LAST CRYPT_SIGNATURELEVEL_LAST, CRYPT_SIGNATURELEVEL_ENUM = -50000
124 #define CRYPT_CERTFORMAT_LAST CRYPT_CERTFORMAT_LAST
125 #define CRYPT_REQUESTTYPE_LAST CRYPT_REQUESTTYPE_LAST, CRYPT_REQUESTTYPE_ENUM = -50000
126 #define CRYPT_KEYID_LAST CRYPT_KEYID_LAST, CRYPT_KEYID_ENUM = -50000
127 #define CRYPT_OBJECT_LAST CRYPT_OBJECT_LAST, CRYPT_OBJECT_ENUM = -50000
128 #define CRYPT_ERRTYPE_LAST CRYPT_ERRTYPE_LAST, CRYPT_ERRTYPE_ENUM = -50000
129 #define CRYPT_CERTACTION_LAST CRYPT_CERTACTION_LAST, CRYPT_CERTACTION_ENUM = -50000
130 #define CRYPT_KEYOPT_LAST CRYPT_KEYOPT_LAST, CRYPT_KEYOPT_ENUM = -50000
132 #define KEYFORMAT_LAST KEYFORMAT_LAST, KEYFORMAT_ENUM = -50000
133 #define CERTFORMAT_LAST CERTFORMAT_LAST, CERTFORMAT_ENUM = -50000
134 #define MANAGEMENT_ACTION_LAST MANAGEMENT_ACTION_LAST, MANAGEMENT_ACTION_ENUM = -50000
135 #define HASH_LAST HASH_LAST, HASH_ENUM = -50000
136 #define ATTR_LAST ATTR_LAST, ATTR_ENUM = -50000
138 #define MESSAGE_COMPARE_LAST MESSAGE_COMPARE_LAST, MESSAGE_COMPARE_ENUM = -50000
139 #define MESSAGE_CHECK_LAST MESSAGE_CHECK_LAST, MESSAGE_CHECK_ENUM = -50000
140 #define MESSAGE_CHANGENOTIFY_LAST MESSAGE_CHANGENOTIFY_LAST, MESSAGE_CHANGENOTIFY_ENUM = -50000
141 #define MECHANISM_LAST MECHANISM_LAST, MECHANISM_ENUM = -50000
142 #define KEYMGMT_ITEM_LAST KEYMGMT_ITEM_LAST, KEYMGMT_ITEM_ENUM = -50000
143 #define SEMAPHORE_LAST SEMAPHORE_LAST, SEMAPHORE_ENUM = -50000
144 #define MUTEX_LAST MUTEX_LAST, MUTEX_ENUM = -50000
146 #define RTCSRESPONSE_TYPE_LAST RTCSRESPONSE_TYPE_LAST, RTCSRESPONSE_TYPE_ENUM = -50000
147 #define ATTRIBUTE_LAST ATTRIBUTE_LAST, ATTRIBUTE_ENUM = -50000
148 #define POLICY_LAST POLICY_LAST, POLICY_ENUM = -50000
149 #define SELECTION_OPTION_LAST SELECTION_OPTION_LAST, SELECTION_OPTION_ENUM = -50000
151 #define CONTEXT_LAST CONTEXT_LAST, CONTEXT_ENUM = -50000
153 #define CAPABILITY_INFO_LAST CAPABILITY_INFO_LAST, CAPABILITY_INFO_ENUM = -50000
155 #define BER_ID_LAST BER_ID_LAST, BER_ID_ENUM = -50000
157 #define ACTION_LAST ACTION_LAST, ACTION_ENUM = -50000
158 #define ACTION_RESULT_LAST ACTION_RESULT_LAST, ACTION_RESULT_ENUM = -50000
159 #define STATE_LAST STATE_LAST, STATE_ENUM = -50000
160 #define ENVSTATE_LAST ENVSTATE_LAST, ENVSTATE_ENUM = -50000
161 #define DEENVSTATE_LAST DEENVSTATE_LAST, DEENVSTATE_ENUM = -50000
162 #define PGP_DEENVSTATE_LAST PGP_DEENVSTATE_LAST, PGP_DEENVSTATE_ENUM = -50000
163 #define SEGHDRSTATE_LAST SEGHDRSTATE_LAST, SEGHDRSTATE_ENUM = -50000
165 #define RANGEVAL_LAST RANGEVAL_LAST, RANGEVAL_ENUM = -50000
166 #define ATTRIBUTE_VALUE_LAST ATTRIBUTE_VALUE_LAST, ATTRIBUTE_VALUE_ENUM = -50000
167 #define PARAM_VALUE_LAST PARAM_VALUE_LAST, PARAM_VALUE_ENUM = -50000
169 #define SEMAPHORE_STATE_LAST SEMAPHORE_STATE_LAST, SEMAPHORE_STATE_ENUM = -50000
171 #define CERTADD_LAST CERTADD_LAST, CERTADD_ENUM = -50000
173 #define KEYSET_SUBTYPE_LAST KEYSET_SUBTYPE_LAST, KEYSET_SUBTYPE_ENUM = -50000
174 #define DBMS_QUERY_LAST DBMS_QUERY_LAST, DBMS_QUERY_ENUM = -50000
175 #define DBMS_UPDATE_LAST DBMS_UPDATE_LAST, DBMS_UPDATE_ENUM = -50000
176 #define DBMS_CACHEDQUERY_LAST DBMS_CACHEDQUERY_LAST, DBMS_CACHEDQUERY_ENUM = -50000
178 #define PKCS15_SUBTYPE_LAST PKCS15_SUBTYPE_LAST, PKCS15_SUBTYPE_ENUM = -50000
180 #define PKCS15_KEYID_LAST PKCS15_KEYID_LAST, PKCS15_KEYID_ENUM = -50000
182 #define PGP_ALGOCLASS_LAST PGP_ALGOCLASS_LAST, PGP_ALGOCLASS_ENUM = -50000
184 #define COMMAND_LAST COMMAND_LAST, COMMAND_ENUM = -50000
185 #define DBX_COMMAND_LAST DBX_COMMAND_LAST, DBX_COMMAND_ENUM = -50000
187 #define STREAM_TYPE_LAST STREAM_TYPE_LAST, STREAM_TYPE_ENUM = -50000
188 #define BUILDPATH_LAST BUILDPATH_LAST, BUILDPATH_ENUM = -50000
189 #define STREAM_IOCTL_LAST STREAM_IOCTL_LAST, STREAM_IOCTL_ENUM = -50000
190 #define STREAM_PROTOCOL_LAST STREAM_PROTOCOL_LAST, STREAM_PROTOCOL_ENUM = -50000
191 #define URL_TYPE_LAST URL_TYPE_LAST, URL_TYPE_ENUM = -50000
192 #define NET_OPTION_LAST NET_OPTION_LAST, NET_OPTION_ENUM = -50000
194 #define CMPBODY_LAST CMPBODY_LAST, CMPBODY_ENUM = -50000
196 #define READINFO_LAST READINFO_LAST, READINFO_ENUM = -50000
198 #define CHANNEL_LAST CHANNEL_LAST, CHANNEL_ENUM = -50000
199 #define MAC_LAST MAC_LAST, MAC_ENUM = -50000
200 #define SSH_ATRIBUTE_LAST SSH_ATRIBUTE_LAST, SSH_ATRIBUTE_ENUM = -50000
202 #define SSL_LAST SSL_LAST, SSL_ENUM = -50000
203 #define TLS_EXT_LAST TLS_EXT_LAST, TLS_EXT_ENUM = -50000
213 #ifndef _CRYPTLIB_DEFINED
221 #undef CRYPT_ALGO_LAST
222 #undef CRYPT_MODE_LAST
223 #undef CRYPT_KEYSET_LAST
224 #undef CRYPT_DEVICE_LAST
225 #undef CRYPT_CERTTYPE_LAST
226 #undef CRYPT_FORMAT_LAST
227 #undef CRYPT_SESSION_LAST
228 #undef CRYPT_USER_LAST
229 #undef CRYPT_IATTRIBUTE_LAST
230 #undef CRYPT_CRLEXTREASON_LAST
231 #undef CRYPT_CONTENT_LAST
232 #undef CRYPT_SIGNATURELEVEL_LAST
233 #undef CRYPT_CERTFORMAT_LAST
234 #undef CRYPT_REQUESTTYPE_LAST
235 #undef CRYPT_KEYID_LAST
236 #undef CRYPT_OBJECT_LAST
237 #undef CRYPT_ERRTYPE_LAST
238 #undef CRYPT_CERTACTION_LAST
239 #undef CRYPT_KEYOPT_LAST
250 #if defined( INC_ALL )
258 #if defined( INC_ALL )
275 #if defined( INC_ALL )
311 #if defined( USE_CMP_TRANSPORT ) || defined( USE_SSH1 )
313 #define mgetWord( memPtr ) \
314 ( ( ( unsigned int ) memPtr[ 0 ] << 8 ) | \
315 ( unsigned int ) memPtr[ 1 ] ); \
318 #define mputWord( memPtr, data ) \
319 memPtr[ 0 ] = ( BYTE ) ( ( ( data ) >> 8 ) & 0xFF ); \
320 memPtr[ 1 ] = ( BYTE ) ( ( data ) & 0xFF ); \
325 #define mgetLong( memPtr ) \
326 ( ( ( unsigned long ) memPtr[ 0 ] << 24 ) | \
327 ( ( unsigned long ) memPtr[ 1 ] << 16 ) | \
328 ( ( unsigned long ) memPtr[ 2 ] << 8 ) | \
329 ( unsigned long ) memPtr[ 3 ] ); \
332 #define mputLong( memPtr, data ) \
333 memPtr[ 0 ] = ( BYTE ) ( ( ( data ) >> 24 ) & 0xFF ); \
334 memPtr[ 1 ] = ( BYTE ) ( ( ( data ) >> 16 ) & 0xFF ); \
335 memPtr[ 2 ] = ( BYTE ) ( ( ( data ) >> 8 ) & 0xFF ); \
336 memPtr[ 3 ] = ( BYTE ) ( ( data ) & 0xFF ); \
347 #if defined( INC_ALL )
398 BUFFER( 128, authEncParamLength )
\
399 BYTE authEncParamData[ 128 + 8 ];
425 const
BYTE *inParam1;
427 const
BYTE *inParam2;
434 #define setDLPParams( dlpDataPtr, dataIn, dataInLen, dataOut, dataOutLen ) \
436 memset( ( dlpDataPtr ), 0, sizeof( DLP_PARAMS ) ); \
437 ( dlpDataPtr )->formatType = CRYPT_FORMAT_CRYPTLIB; \
438 ( dlpDataPtr )->inParam1 = ( dataIn ); \
439 ( dlpDataPtr )->inLen1 = ( dataInLen ); \
440 ( dlpDataPtr )->outParam = ( dataOut ); \
441 ( dlpDataPtr )->outLen = ( dataOutLen ); \
477 #define UNUSED_ARG( arg ) ( ( arg ) = ( arg ) )
488 #define min( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
489 #define max( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
496 #define bitsToBytes( bits ) ( ( ( bits ) + 7 ) >> 3 )
497 #define bytesToBits( bytes ) ( ( bytes ) << 3 )
504 #define MKDATA( x ) ( ( unsigned char * ) ( x ) )
509 #define roundUp( size, roundSize ) \
510 ( ( ( size ) + ( ( roundSize ) - 1 ) ) & ~( ( roundSize ) - 1 ) )
518 #if defined( _MSC_VER ) && VC_GE_2005( _MSC_VER )
524 #define zeroise( memory, size ) SecureZeroMemory( memory, size )
526 #define zeroise( memory, size ) memset( memory, 0, size )
535 #define isHandleRangeValid( handle ) \
536 ( ( handle ) > NO_SYSTEM_OBJECTS - 1 && ( handle ) < MAX_OBJECTS )
540 #define needsIV( mode ) ( ( mode ) == CRYPT_MODE_CBC || \
541 ( mode ) == CRYPT_MODE_CFB || \
542 ( mode ) == CRYPT_MODE_OFB || \
543 ( mode ) == CRYPT_MODE_GCM )
549 #define isStreamCipher( algorithm ) ( ( algorithm ) == CRYPT_ALGO_RC4 )
560 #define isWeakCryptAlgo( algorithm ) ( ( algorithm ) == CRYPT_ALGO_DES || \
561 ( algorithm ) == CRYPT_ALGO_RC2 || \
562 ( algorithm ) == CRYPT_ALGO_RC4 )
563 #define isWeakHashAlgo( algorithm ) ( ( algorithm ) == CRYPT_ALGO_MD5 )
564 #define isWeakMacAlgo( algorithm ) ( ( algorithm ) == CRYPT_ALGO_HMAC_MD5 )
570 #define isConvAlgo( algorithm ) \
571 ( ( algorithm ) >= CRYPT_ALGO_FIRST_CONVENTIONAL && \
572 ( algorithm ) <= CRYPT_ALGO_LAST_CONVENTIONAL )
573 #define isPkcAlgo( algorithm ) \
574 ( ( algorithm ) >= CRYPT_ALGO_FIRST_PKC && \
575 ( algorithm ) <= CRYPT_ALGO_LAST_PKC )
576 #define isHashAlgo( algorithm ) \
577 ( ( algorithm ) >= CRYPT_ALGO_FIRST_HASH && \
578 ( algorithm ) <= CRYPT_ALGO_LAST_HASH )
579 #define isMacAlgo( algorithm ) \
580 ( ( algorithm ) >= CRYPT_ALGO_FIRST_MAC && \
581 ( algorithm ) <= CRYPT_ALGO_LAST_MAC )
582 #define isSpecialAlgo( algorithm ) \
583 ( ( algorithm ) == CRYPT_IALGO_GENERIC_SECRET )
594 #define isSigAlgo( algorithm ) \
595 ( ( algorithm ) == CRYPT_ALGO_RSA || ( algorithm ) == CRYPT_ALGO_DSA || \
596 ( algorithm ) == CRYPT_ALGO_ECDSA )
597 #define isCryptAlgo( algorithm ) \
598 ( ( algorithm ) == CRYPT_ALGO_RSA || ( algorithm ) == CRYPT_ALGO_ELGAMAL )
599 #define isKeyxAlgo( algorithm ) \
600 ( ( algorithm ) == CRYPT_ALGO_DH || ( algorithm ) == CRYPT_ALGO_ECDH )
601 #define isDlpAlgo( algorithm ) \
602 ( ( algorithm ) == CRYPT_ALGO_DSA || ( algorithm ) == CRYPT_ALGO_ELGAMAL || \
603 ( algorithm ) == CRYPT_ALGO_DH )
604 #define isEccAlgo( algorithm ) \
605 ( ( algorithm ) == CRYPT_ALGO_ECDSA || ( algorithm ) == CRYPT_ALGO_ECDH )
610 #define isParameterisedConvAlgo( algorithm ) \
611 ( ( algorithm ) == CRYPT_ALGO_AES )
612 #define isParameterisedHashAlgo( algorithm ) \
613 ( ( algorithm ) == CRYPT_ALGO_SHA2 || ( algorithm ) == CRYPT_ALGO_SHAng )
614 #define isParameterisedMacAlgo( algorithm ) \
615 ( ( algorithm ) == CRYPT_ALGO_HMAC_SHA2 || \
616 ( algorithm ) == CRYPT_ALGO_HMAC_SHAng )
629 #define isDataError( status ) \
630 ( ( ( status ) >= CRYPT_ERROR_OVERFLOW && \
631 ( status ) <= CRYPT_ERROR_SIGNATURE ) ) || \
632 ( ( status ) == CRYPT_ERROR_NOTAVAIL || \
633 ( status ) == CRYPT_ERROR_INCOMPLETE || \
634 ( status ) == CRYPT_ERROR_COMPLETE || \
635 ( status ) == CRYPT_ERROR_INVALID )
643 #define isShortPKCKey( keySize ) \
644 ( ( keySize ) >= MIN_PKCSIZE_THRESHOLD && \
645 ( keySize ) < MIN_PKCSIZE )
646 #define isShortECCKey( keySize ) \
647 ( ( keySize ) >= MIN_PKCSIZE_ECC_THRESHOLD && \
648 ( keySize ) < MIN_PKCSIZE_ECC )
658 #define rangeCheck( start, length, totalLength ) \
659 ( ( start ) <= 0 || ( length ) < 1 || \
660 ( start ) + ( length ) > ( totalLength ) ) ? FALSE : TRUE
661 #define rangeCheckZ( start, length, totalLength ) \
662 ( ( start ) < 0 || ( length ) < 1 || \
663 ( start ) + ( length ) > ( totalLength ) ) ? FALSE : TRUE
741 #if defined( __WIN32__ ) || defined( __WINCE__ )
742 #define isReadPtr( ptr, size ) ( ( ptr ) != NULL && ( size ) > 0 && \
743 !IsBadReadPtr( ( ptr ), ( size ) ) )
744 #define isWritePtr( ptr, size ) ( ( ptr ) != NULL && ( size ) > 0 && \
745 !IsBadWritePtr( ( ptr ), ( size ) ) )
746 #define isReadPtrConst( ptr, size ) \
747 ( ( ptr ) != NULL && \
748 !IsBadReadPtr( ( ptr ), ( size ) ) )
749 #define isWritePtrConst( ptr, size ) \
750 ( ( ptr ) != NULL && \
751 !IsBadWritePtr( ( ptr ), ( size ) ) )
752 #elif defined( __UNIX__ ) && 0
755 #define isReadPtr( ptr, size ) ( ( ptr ) != NULL && \
756 ( void * ) ( ptr ) > ( void * ) &_etext && \
758 #define isWritePtr( ptr, size ) ( ( ptr ) != NULL && \
759 ( void * ) ( ptr ) > ( void * ) &_etext && \
761 #define isReadPtrConst( ptr, size ) \
762 ( ( ptr ) != NULL && \
763 ( void * ) ( ptr ) > ( void * ) &_etext )
764 #define isWritePtrConst( ptr, size ) \
765 ( ( ptr ) != NULL && \
766 ( void * ) ( ptr ) > ( void * ) &_etext )
768 #define isReadPtr( ptr, size ) ( ( ptr ) != NULL && ( size ) > 0 )
769 #define isWritePtr( ptr, size ) ( ( ptr ) != NULL && ( size ) > 0 )
770 #define isReadPtrConst( ptr, type ) \
772 #define isWritePtrConst( ptr, type ) \
782 #define byteToInt( x ) ( ( unsigned char ) ( x ) )
783 #define intToLong( x ) ( ( unsigned int ) ( x ) )
785 #define sizeToInt( x ) ( ( unsigned int ) ( x ) )
786 #define intToByte( x ) ( ( unsigned char ) ( x ) )
790 #define clearErrorInfo( objectInfoPtr ) \
792 ( objectInfoPtr )->errorLocus = CRYPT_ATTRIBUTE_NONE; \
793 ( objectInfoPtr )->errorType = CRYPT_OK; \
796 #define setErrorInfo( objectInfoPtr, locus, type ) \
798 ( objectInfoPtr )->errorLocus = locus; \
799 ( objectInfoPtr )->errorType = type; \
810 #if defined( INC_ALL )
824 #if defined( INC_ALL )