Go to the documentation of this file.
8 #ifndef _CRYPTKRN_DEFINED
10 #define _CRYPTKRN_DEFINED
26 #define ORIGINAL_VALUE( x ) orig_##x
27 #define ORIGINAL_INT( x ) const int orig_##x = ( int ) x
28 #define ORIGINAL_PTR( x ) const BYTE *orig_##x = ( const BYTE * ) x
40 #define ORIGINAL_INT_VAR( x, y ) const int orig_##x = ( y )
41 #define DECLARE_ORIGINAL_INT( x ) int orig_##x
42 #define STORE_ORIGINAL_INT( x, y ) orig_##x = ( y )
47 #if !defined( NDEBUG )
56 #define FORALL( iter, start, end, condition ) \
60 for( iter = ( start ); iter < ( end ); iter++ ) \
61 assert( condition ); \
64 #define EXISTS( iter, start, end, condition ) \
68 for( iter = ( start ); iter < ( end ); iter++ ) \
73 assert( iter < ( end ) ); \
81 #define FORALL( a, b, c, d )
82 #define EXISTS( a, b, c, d )
149 #define SUBTYPE_CLASS_MASK 0x70000000L
150 #define SUBTYPE_CLASS_A 0x10000000L
151 #define SUBTYPE_CLASS_B 0x20000000L
152 #define SUBTYPE_CLASS_C 0x40000000L
154 #define MK_SUBTYPE_A( value ) ( SUBTYPE_CLASS_A | ( 1L << ( value - 1 ) ) )
155 #define MK_SUBTYPE_B( value ) ( SUBTYPE_CLASS_B | ( 1L << ( value - 1 ) ) )
156 #define MK_SUBTYPE_C( value ) ( SUBTYPE_CLASS_C | ( 1L << ( value - 1 ) ) )
158 #define SUBTYPE_NONE 0x00000000L
160 #define SUBTYPE_CTX_CONV MK_SUBTYPE_A( 1 )
161 #define SUBTYPE_CTX_PKC MK_SUBTYPE_A( 2 )
162 #define SUBTYPE_CTX_HASH MK_SUBTYPE_A( 3 )
163 #define SUBTYPE_CTX_MAC MK_SUBTYPE_A( 4 )
164 #define SUBTYPE_CTX_GENERIC MK_SUBTYPE_A( 5 )
166 #define SUBTYPE_CERT_CERT MK_SUBTYPE_A( 6 )
167 #define SUBTYPE_CERT_CERTREQ MK_SUBTYPE_A( 7 )
168 #define SUBTYPE_CERT_REQ_CERT MK_SUBTYPE_A( 8 )
169 #define SUBTYPE_CERT_REQ_REV MK_SUBTYPE_A( 9 )
170 #define SUBTYPE_CERT_CERTCHAIN MK_SUBTYPE_A( 10 )
171 #define SUBTYPE_CERT_ATTRCERT MK_SUBTYPE_A( 11 )
172 #define SUBTYPE_CERT_CRL MK_SUBTYPE_A( 12 )
173 #define SUBTYPE_CERT_CMSATTR MK_SUBTYPE_A( 13 )
174 #define SUBTYPE_CERT_RTCS_REQ MK_SUBTYPE_A( 14 )
175 #define SUBTYPE_CERT_RTCS_RESP MK_SUBTYPE_A( 15 )
176 #define SUBTYPE_CERT_OCSP_REQ MK_SUBTYPE_A( 16 )
177 #define SUBTYPE_CERT_OCSP_RESP MK_SUBTYPE_A( 17 )
178 #define SUBTYPE_CERT_PKIUSER MK_SUBTYPE_A( 18 )
180 #define SUBTYPE_ENV_ENV MK_SUBTYPE_B( 1 )
181 #define SUBTYPE_ENV_ENV_PGP MK_SUBTYPE_B( 2 )
182 #define SUBTYPE_ENV_DEENV MK_SUBTYPE_B( 3 )
184 #define SUBTYPE_KEYSET_FILE MK_SUBTYPE_B( 4 )
185 #define SUBTYPE_KEYSET_FILE_PARTIAL MK_SUBTYPE_B( 5 )
186 #define SUBTYPE_KEYSET_FILE_READONLY MK_SUBTYPE_B( 6 )
187 #define SUBTYPE_KEYSET_DBMS MK_SUBTYPE_B( 7 )
188 #define SUBTYPE_KEYSET_DBMS_STORE MK_SUBTYPE_B( 8 )
189 #define SUBTYPE_KEYSET_HTTP MK_SUBTYPE_B( 9 )
190 #define SUBTYPE_KEYSET_LDAP MK_SUBTYPE_B( 10 )
192 #define SUBTYPE_DEV_SYSTEM MK_SUBTYPE_B( 11 )
193 #define SUBTYPE_DEV_PKCS11 MK_SUBTYPE_B( 12 )
194 #define SUBTYPE_DEV_CRYPTOAPI MK_SUBTYPE_B( 13 )
195 #define SUBTYPE_DEV_HARDWARE MK_SUBTYPE_B( 14 )
197 #define SUBTYPE_SESSION_SSH MK_SUBTYPE_C( 1 )
198 #define SUBTYPE_SESSION_SSH_SVR MK_SUBTYPE_C( 2 )
199 #define SUBTYPE_SESSION_SSL MK_SUBTYPE_C( 3 )
200 #define SUBTYPE_SESSION_SSL_SVR MK_SUBTYPE_C( 4 )
201 #define SUBTYPE_SESSION_RTCS MK_SUBTYPE_C( 5 )
202 #define SUBTYPE_SESSION_RTCS_SVR MK_SUBTYPE_C( 6 )
203 #define SUBTYPE_SESSION_OCSP MK_SUBTYPE_C( 7 )
204 #define SUBTYPE_SESSION_OCSP_SVR MK_SUBTYPE_C( 8 )
205 #define SUBTYPE_SESSION_TSP MK_SUBTYPE_C( 9 )
206 #define SUBTYPE_SESSION_TSP_SVR MK_SUBTYPE_C( 10 )
207 #define SUBTYPE_SESSION_CMP MK_SUBTYPE_C( 11 )
208 #define SUBTYPE_SESSION_CMP_SVR MK_SUBTYPE_C( 12 )
209 #define SUBTYPE_SESSION_SCEP MK_SUBTYPE_C( 13 )
210 #define SUBTYPE_SESSION_SCEP_SVR MK_SUBTYPE_C( 14 )
211 #define SUBTYPE_SESSION_CERT_SVR MK_SUBTYPE_C( 15 )
213 #define SUBTYPE_USER_SO MK_SUBTYPE_C( 16 )
214 #define SUBTYPE_USER_NORMAL MK_SUBTYPE_C( 17 )
215 #define SUBTYPE_USER_CA MK_SUBTYPE_C( 18 )
231 #define MESSAGE_FLAG_INTERNAL 0x100
232 #define MKINTERNAL( message ) ( message | MESSAGE_FLAG_INTERNAL )
236 #define MESSAGE_MASK 0xFF
540 #define setMessageData( msgDataPtr, dataPtr, dataLength ) \
542 ( msgDataPtr )->data = ( dataPtr ); \
543 ( msgDataPtr )->length = ( dataLength ); \
555 #define MESSAGE_VALUE_TRUE ( ( MESSAGE_CAST ) &messageValueTrue )
556 #define MESSAGE_VALUE_FALSE ( ( MESSAGE_CAST ) &messageValueFalse )
557 #define MESSAGE_VALUE_OK ( ( MESSAGE_CAST ) &messageValueCryptOK )
558 #define MESSAGE_VALUE_ERROR ( ( MESSAGE_CAST ) &messageValueCryptError )
559 #define MESSAGE_VALUE_UNUSED ( ( MESSAGE_CAST ) &messageValueCryptUnused )
560 #define MESSAGE_VALUE_DEFAULT ( ( MESSAGE_CAST ) &messageValueCryptUseDefault )
561 #define MESSAGE_VALUE_CURSORFIRST ( ( MESSAGE_CAST ) &messageValueCursorFirst )
562 #define MESSAGE_VALUE_CURSORNEXT ( ( MESSAGE_CAST ) &messageValueCursorNext )
563 #define MESSAGE_VALUE_CURSORPREVIOUS ( ( MESSAGE_CAST ) &messageValueCursorPrevious )
564 #define MESSAGE_VALUE_CURSORLAST ( ( MESSAGE_CAST ) &messageValueCursorLast )
574 #define isAttribute( attribute ) \
575 ( ( attribute ) > CRYPT_ATTRIBUTE_NONE && \
576 ( attribute ) < CRYPT_ATTRIBUTE_LAST )
577 #define isInternalAttribute( attribute ) \
578 ( ( attribute ) > CRYPT_IATTRIBUTE_FIRST && \
579 ( attribute ) < CRYPT_IATTRIBUTE_LAST )
584 #define isAttributeMessage( message ) \
585 ( ( message ) >= MESSAGE_GETATTRIBUTE && \
586 ( message ) <= MESSAGE_DELETEATTRIBUTE )
587 #define isActionMessage( message ) \
588 ( ( message ) >= MESSAGE_CTX_ENCRYPT && \
589 ( message ) <= MESSAGE_CTX_HASH )
590 #define isMechanismActionMessage( message ) \
591 ( ( message ) >= MESSAGE_DEV_EXPORT && \
592 ( message ) <= MESSAGE_DEV_KDF )
601 #define SYSTEM_OBJECT_HANDLE 0
602 #define DEFAULTUSER_OBJECT_HANDLE 1
604 #define NO_SYSTEM_OBJECTS 2
611 #define MAX_OBJECTS 16384
660 #define ACTION_PERM_NOTAVAIL 0x00
661 #define ACTION_PERM_NONE 0x01
662 #define ACTION_PERM_NONE_EXTERNAL 0x02
663 #define ACTION_PERM_ALL 0x03
665 #define ACTION_PERM_NONE_ALL 0x000
666 #define ACTION_PERM_NONE_EXTERNAL_ALL 0xAAA
667 #define ACTION_PERM_ALL_MAX 0xFFF
669 #define ACTION_PERM_BASE MESSAGE_CTX_ENCRYPT
670 #define ACTION_PERM_MASK 0x03
671 #define ACTION_PERM_BITS 2
672 #define ACTION_PERM_COUNT ( MESSAGE_CTX_GENKEY - \
673 MESSAGE_CTX_ENCRYPT + 1 )
674 #define ACTION_PERM_LAST \
675 ( 1 << ( ( ( ACTION_PERM_COUNT ) * ACTION_PERM_BITS ) + 1 ) )
676 #define ACTION_PERM_SHIFT( action ) \
677 ( ( ( action ) - ACTION_PERM_BASE ) * ACTION_PERM_BITS )
678 #define MK_ACTION_PERM( action, perm ) \
679 ( ( perm ) << ACTION_PERM_SHIFT( action ) )
680 #define MK_ACTION_PERM_NONE_EXTERNAL( action ) \
681 ( ( action ) & ACTION_PERM_NONE_EXTERNAL_ALL )
686 #define ACTION_PERM_FLAG_NONE 0x000
687 #define ACTION_PERM_FLAG_MAX 0xFFF
843 #define clearMechanismInfo( mechanismInfo ) \
844 memset( mechanismInfo, 0, sizeof( *mechanismInfo ) )
846 #define setMechanismWrapInfo( mechanismInfo, wrapped, wrappedLen, key, keyLen, keyCtx, wrapCtx ) \
848 memset( mechanismInfo, 0, sizeof( MECHANISM_WRAP_INFO ) ); \
849 ( mechanismInfo )->wrappedData = ( wrapped ); \
850 ( mechanismInfo )->wrappedDataLength = ( wrappedLen ); \
851 ( mechanismInfo )->keyData = ( key ); \
852 ( mechanismInfo )->keyDataLength = ( keyLen ); \
853 ( mechanismInfo )->keyContext = ( keyCtx ); \
854 ( mechanismInfo )->wrapContext = ( wrapCtx ); \
855 ( mechanismInfo )->auxContext = \
856 ( mechanismInfo )->auxInfo = CRYPT_UNUSED; \
859 #define setMechanismWrapInfoEx( mechanismInfo, wrapped, wrappedLen, key, keyLen, keyCtx, wrapCtx, auxCtx, auxInf ) \
861 memset( mechanismInfo, 0, sizeof( MECHANISM_WRAP_INFO ) ); \
862 ( mechanismInfo )->wrappedData = ( wrapped ); \
863 ( mechanismInfo )->wrappedDataLength = ( wrappedLen ); \
864 ( mechanismInfo )->keyData = ( key ); \
865 ( mechanismInfo )->keyDataLength = ( keyLen ); \
866 ( mechanismInfo )->keyContext = ( keyCtx ); \
867 ( mechanismInfo )->wrapContext = ( wrapCtx ); \
868 ( mechanismInfo )->auxContext = ( auxCtx ); \
869 ( mechanismInfo )->auxInfo = ( auxInf ); \
872 #define setMechanismSignInfo( mechanismInfo, sig, sigLen, hashCtx, hashCtx2, signCtx ) \
874 memset( mechanismInfo, 0, sizeof( MECHANISM_SIGN_INFO ) ); \
875 ( mechanismInfo )->signature = ( sig ); \
876 ( mechanismInfo )->signatureLength = ( sigLen ); \
877 ( mechanismInfo )->hashContext = ( hashCtx ); \
878 ( mechanismInfo )->hashContext2 = ( hashCtx2 ); \
879 ( mechanismInfo )->signContext = ( signCtx ); \
882 #define setMechanismDeriveInfo( mechanismInfo, out, outLen, in, inLen, hAlgo, slt, sltLen, iters ) \
884 memset( mechanismInfo, 0, sizeof( MECHANISM_DERIVE_INFO ) ); \
885 ( mechanismInfo )->dataOut = ( out ); \
886 ( mechanismInfo )->dataOutLength = ( outLen ); \
887 ( mechanismInfo )->dataIn = ( in ); \
888 ( mechanismInfo )->dataInLength = ( inLen ); \
889 ( mechanismInfo )->hashAlgo = ( hAlgo ); \
890 ( mechanismInfo )->salt = ( slt ); \
891 ( mechanismInfo )->saltLength = ( sltLen ); \
892 ( mechanismInfo )->iterations = ( iters ); \
895 #define setMechanismKDFInfo( mechanismInfo, keyCtx, masterKeyCtx, hAlgo, slt, sltLen ) \
897 memset( mechanismInfo, 0, sizeof( MECHANISM_KDF_INFO ) ); \
898 ( mechanismInfo )->keyContext = ( keyCtx ); \
899 ( mechanismInfo )->masterKeyContext = ( masterKeyCtx ); \
900 ( mechanismInfo )->hashAlgo = ( hAlgo ); \
901 ( mechanismInfo )->salt = ( slt ); \
902 ( mechanismInfo )->saltLength = ( sltLen ); \
934 #define setMessageCreateObjectInfo( createObjectInfo, a1 ) \
936 memset( createObjectInfo, 0, sizeof( MESSAGE_CREATEOBJECT_INFO ) ); \
937 ( createObjectInfo )->cryptHandle = CRYPT_ERROR; \
938 ( createObjectInfo )->cryptOwner = CRYPT_ERROR; \
939 ( createObjectInfo )->arg1 = ( a1 ); \
942 #define setMessageCreateObjectIndirectInfo( createObjectInfo, data, dataLen, type ) \
944 memset( createObjectInfo, 0, sizeof( MESSAGE_CREATEOBJECT_INFO ) ); \
945 ( createObjectInfo )->cryptHandle = CRYPT_ERROR; \
946 ( createObjectInfo )->cryptOwner = CRYPT_ERROR; \
947 ( createObjectInfo )->strArg1 = ( data ); \
948 ( createObjectInfo )->strArgLen1 = ( dataLen ); \
949 ( createObjectInfo )->arg1 = ( type ); \
1005 #define KEYMGMT_FLAG_NONE 0x0000
1006 #define KEYMGMT_FLAG_CHECK_ONLY 0x0001
1007 #define KEYMGMT_FLAG_LABEL_ONLY 0x0002
1008 #define KEYMGMT_FLAG_UPDATE 0x0004
1009 #define KEYMGMT_FLAG_DATAONLY_CERT 0x0008
1010 #define KEYMGMT_FLAG_USAGE_CRYPT 0x0010
1011 #define KEYMGMT_FLAG_USAGE_SIGN 0x0020
1012 #define KEYMGMT_FLAG_GETISSUER 0x0040
1013 #define KEYMGMT_FLAG_INITIALOP 0x0080
1014 #define KEYMGMT_FLAG_MAX 0x00FF
1016 #define KEYMGMT_MASK_USAGEOPTIONS ( KEYMGMT_FLAG_USAGE_CRYPT | \
1017 KEYMGMT_FLAG_USAGE_SIGN )
1018 #define KEYMGMT_MASK_CERTOPTIONS ( KEYMGMT_FLAG_DATAONLY_CERT | \
1019 KEYMGMT_FLAG_USAGE_CRYPT | \
1020 KEYMGMT_FLAG_USAGE_SIGN )
1033 #define setMessageKeymgmtInfo( keymgmtInfo, idType, id, idLength, aux, auxLen, keyFlags ) \
1035 ( keymgmtInfo )->cryptHandle = CRYPT_ERROR; \
1036 ( keymgmtInfo )->keyIDtype = ( idType ); \
1037 ( keymgmtInfo )->keyID = ( id ); \
1038 ( keymgmtInfo )->keyIDlength = ( idLength ); \
1039 ( keymgmtInfo )->auxInfo = ( aux ); \
1040 ( keymgmtInfo )->auxInfoLength = ( auxLen ); \
1041 ( keymgmtInfo )->flags = ( keyFlags ); \
1054 #define setMessageCertMgmtInfo( certMgmtInfo, mgmtCaKey, mgmtRequest ) \
1056 ( certMgmtInfo )->cryptCert = CRYPT_ERROR; \
1057 ( certMgmtInfo )->caKey = ( mgmtCaKey ); \
1058 ( certMgmtInfo )->request = ( mgmtRequest ); \
1071 #if defined( __PALMOS__ ) || defined( __WIN32__ ) || defined( __WINCE__ )
1072 void preInit(
void );
1073 void postShutdown(
void );
1094 #define initMessageExtInfo( messageExtInfo, objectInfo ) \
1096 memset( messageExtInfo, 0, sizeof( MESSAGE_FUNCTION_EXTINFO ) ); \
1097 ( messageExtInfo )->objectInfoPtr = objectInfo; \
1099 #define setMessageObjectLocked( messageExtInfo ) \
1100 ( messageExtInfo )->isUnlocked = FALSE
1101 #define setMessageObjectUnlocked( messageExtInfo ) \
1102 ( messageExtInfo )->isUnlocked = TRUE
1103 #define isMessageObjectUnlocked( messageExtInfo ) \
1104 ( ( messageExtInfo )->isUnlocked )
1113 #define CREATEOBJECT_FLAG_NONE 0x00
1114 #define CREATEOBJECT_FLAG_SECUREMALLOC \
1116 #define CREATEOBJECT_FLAG_DUMMY 0x02
1117 #define CREATEOBJECT_FLAG_PERSISTENT 0x04
1118 #define CREATEOBJECT_FLAG_MAX 0x0F
1126 IN_FLAGS( CREATEOBJECT )
const int createObjectFlags,
1128 IN_FLAGS( ACTION )
const int actionFlags,
1137 #define krnlSendNotifier( handle, message ) \
1138 krnlSendMessage( handle, message, NULL, 0 )
1150 int krnlAcquireObject(
IN_HANDLE const int objectHandle,
1166 int krnlSuspendObject(
IN_HANDLE const int objectHandle,
1247 int krnlMemfree(
INOUT_PTR void **pointer );
1250 #undef OBJECT_TYPE_LAST
1251 #undef MESSAGE_COMPARE_LAST
1252 #undef MESSAGE_CHECK_LAST
1253 #undef MESSAGE_CHANGENOTIFY_LAST
1254 #undef MECHANISM_LAST
1255 #undef KEYMGMT_ITEM_LAST
1256 #undef SEMAPHORE_LAST