⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cryptkrn.h

📁 提供了很多种加密算法和CA认证及相关服务如CMP、OCSP等的开发
💻 H
📖 第 1 页 / 共 4 页
字号:
	   permission error when the kernel blocks the access.  Actual access
	   checking is still done at the kernel level to avoid the confused 
	   deputy problem */
	RESOURCE_MESSAGE_GETATTRIBUTE,		/* Get numeric object attribute */
	RESOURCE_MESSAGE_GETATTRIBUTE_S,	/* Get string object attribute */
	RESOURCE_MESSAGE_SETATTRIBUTE,		/* Set numeric object attribute */
	RESOURCE_MESSAGE_SETATTRIBUTE_S,	/* Set string object attribute */
	RESOURCE_MESSAGE_DELETEATTRIBUTE,	/* Delete object attribute */
	RESOURCE_MESSAGE_COMPARE,			/* Compare objs. or obj.properties */
	RESOURCE_MESSAGE_CLONE,				/* Clone the object */
	RESOURCE_MESSAGE_CHECK,				/* Check object info */
	RESOURCE_MESSAGE_LOCK,				/* Lock object for exclusive use */
	RESOURCE_MESSAGE_UNLOCK,			/* Unlock object */

	/* Messages sent from the kernel to object message handlers (these never
	   originate from outside the kernel) */
	RESOURCE_MESSAGE_CHANGENOTIFY,		/* Notification of obj.status chge.*/

	/* Object-type-specific messages */
	RESOURCE_MESSAGE_CTX_ENCRYPT,		/* Context: Action = encrypt */
	RESOURCE_MESSAGE_CTX_DECRYPT,		/* Context: Action = decrypt */
	RESOURCE_MESSAGE_CTX_SIGN,			/* Context: Action = sign */
	RESOURCE_MESSAGE_CTX_SIGCHECK,		/* Context: Action = sigcheck */
	RESOURCE_MESSAGE_CTX_HASH,			/* Context: Action = hash */
	RESOURCE_MESSAGE_CTX_GENKEY,		/* Context: Generate a key */
	RESOURCE_MESSAGE_CTX_GENIV,			/* Context: Generate an IV */
	RESOURCE_MESSAGE_CRT_SIGN,			/* Cert: Action = sign cert */
	RESOURCE_MESSAGE_CRT_SIGCHECK,		/* Cert: Action = check/verify cert */
	RESOURCE_MESSAGE_DEV_QUERYCAPABILITY,/* Device: Query capability */
	RESOURCE_MESSAGE_DEV_EXPORT,		/* Device: Action = export key */
	RESOURCE_MESSAGE_DEV_IMPORT,		/* Device: Action = import key */
	RESOURCE_MESSAGE_DEV_SIGN,			/* Device: Action = sign */
	RESOURCE_MESSAGE_DEV_SIGCHECK,		/* Device: Action = sig.check */
	RESOURCE_MESSAGE_DEV_DERIVE,		/* Device: Action = derive key */
	RESOURCE_MESSAGE_DEV_CREATEOBJECT,	/* Device: Create object */
	RESOURCE_MESSAGE_DEV_CREATEOBJECT_INDIRECT,	/* Device: Create obj.from data*/
	RESOURCE_MESSAGE_ENV_PUSHDATA,		/* Envelope: Push data */
	RESOURCE_MESSAGE_ENV_POPDATA,		/* Envelope: Pop data */
	RESOURCE_MESSAGE_KEY_GETKEY,		/* Keyset: Instantiate ctx/cert */
	RESOURCE_MESSAGE_KEY_SETKEY,		/* Keyset: Add ctx/cert */
	RESOURCE_MESSAGE_KEY_DELETEKEY,		/* Keyset: Delete key/cert */
	RESOURCE_MESSAGE_KEY_GETFIRSTCERT,	/* Keyset: Get first cert in sequence */
	RESOURCE_MESSAGE_KEY_GETNEXTCERT,	/* Keyset: Get next cert in sequence */
	RESOURCE_MESSAGE_KEY_CERTMGMT,		/* Keyset: Cert management */
	RESOURCE_MESSAGE_LAST,				/* Last valid message type */

	/* Messages to all (including internal) object types */
	RESOURCE_IMESSAGE_DESTROY = MKINTERNAL( RESOURCE_MESSAGE_DESTROY ),
	RESOURCE_IMESSAGE_INCREFCOUNT = MKINTERNAL( RESOURCE_MESSAGE_INCREFCOUNT ),
	RESOURCE_IMESSAGE_DECREFCOUNT = MKINTERNAL( RESOURCE_MESSAGE_DECREFCOUNT ),

	RESOURCE_IMESSAGE_GETATTRIBUTE = MKINTERNAL( RESOURCE_MESSAGE_GETATTRIBUTE ),
	RESOURCE_IMESSAGE_GETATTRIBUTE_S = MKINTERNAL( RESOURCE_MESSAGE_GETATTRIBUTE_S ),
	RESOURCE_IMESSAGE_SETATTRIBUTE = MKINTERNAL( RESOURCE_MESSAGE_SETATTRIBUTE ),
	RESOURCE_IMESSAGE_SETATTRIBUTE_S = MKINTERNAL( RESOURCE_MESSAGE_SETATTRIBUTE_S ),
	RESOURCE_IMESSAGE_DELETEATTRIBUTE = MKINTERNAL( RESOURCE_MESSAGE_DELETEATTRIBUTE ),
	RESOURCE_IMESSAGE_GETDEPENDENT = MKINTERNAL( RESOURCE_MESSAGE_GETDEPENDENT ),
	RESOURCE_IMESSAGE_SETDEPENDENT = MKINTERNAL( RESOURCE_MESSAGE_SETDEPENDENT ),
	RESOURCE_IMESSAGE_COMPARE = MKINTERNAL( RESOURCE_MESSAGE_COMPARE ),
	RESOURCE_IMESSAGE_CLONE = MKINTERNAL( RESOURCE_MESSAGE_CLONE ),
	RESOURCE_IMESSAGE_CHECK = MKINTERNAL( RESOURCE_MESSAGE_CHECK ),
	RESOURCE_IMESSAGE_LOCK = MKINTERNAL( RESOURCE_MESSAGE_LOCK ),
	RESOURCE_IMESSAGE_UNLOCK = MKINTERNAL( RESOURCE_MESSAGE_UNLOCK ),

	RESOURCE_IMESSAGE_CHANGENOTIFY = MKINTERNAL( RESOURCE_MESSAGE_CHANGENOTIFY ),

	RESOURCE_IMESSAGE_CTX_ENCRYPT = MKINTERNAL( RESOURCE_MESSAGE_CTX_ENCRYPT ),
	RESOURCE_IMESSAGE_CTX_DECRYPT = MKINTERNAL( RESOURCE_MESSAGE_CTX_DECRYPT ),
	RESOURCE_IMESSAGE_CTX_SIGN = MKINTERNAL( RESOURCE_MESSAGE_CTX_SIGN ),
	RESOURCE_IMESSAGE_CTX_SIGCHECK = MKINTERNAL( RESOURCE_MESSAGE_CTX_SIGCHECK ),
	RESOURCE_IMESSAGE_CTX_HASH = MKINTERNAL( RESOURCE_MESSAGE_CTX_HASH ),
	RESOURCE_IMESSAGE_CTX_GENKEY = MKINTERNAL( RESOURCE_MESSAGE_CTX_GENKEY ),
	RESOURCE_IMESSAGE_CTX_GENIV = MKINTERNAL( RESOURCE_MESSAGE_CTX_GENIV ),
	RESOURCE_IMESSAGE_CRT_SIGN = MKINTERNAL( RESOURCE_MESSAGE_CRT_SIGN ),
	RESOURCE_IMESSAGE_CRT_SIGCHECK = MKINTERNAL( RESOURCE_MESSAGE_CRT_SIGCHECK ),
	RESOURCE_IMESSAGE_DEV_QUERYCAPABILITY = MKINTERNAL( RESOURCE_MESSAGE_DEV_QUERYCAPABILITY ),
	RESOURCE_IMESSAGE_DEV_EXPORT = MKINTERNAL( RESOURCE_MESSAGE_DEV_EXPORT ),
	RESOURCE_IMESSAGE_DEV_IMPORT = MKINTERNAL( RESOURCE_MESSAGE_DEV_IMPORT ),
	RESOURCE_IMESSAGE_DEV_SIGN = MKINTERNAL( RESOURCE_MESSAGE_DEV_SIGN ),
	RESOURCE_IMESSAGE_DEV_SIGCHECK = MKINTERNAL( RESOURCE_MESSAGE_DEV_SIGCHECK ),
	RESOURCE_IMESSAGE_DEV_DERIVE = MKINTERNAL( RESOURCE_MESSAGE_DEV_DERIVE ),
	RESOURCE_IMESSAGE_DEV_CREATEOBJECT = MKINTERNAL( RESOURCE_MESSAGE_DEV_CREATEOBJECT ),
	RESOURCE_IMESSAGE_DEV_CREATEOBJECT_INDIRECT = MKINTERNAL( RESOURCE_MESSAGE_DEV_CREATEOBJECT_INDIRECT ),
	RESOURCE_IMESSAGE_ENV_PUSHDATA = MKINTERNAL( RESOURCE_MESSAGE_ENV_PUSHDATA ),
	RESOURCE_IMESSAGE_ENV_POPDATA = MKINTERNAL( RESOURCE_MESSAGE_ENV_POPDATA ),
	RESOURCE_IMESSAGE_KEY_GETKEY = MKINTERNAL( RESOURCE_MESSAGE_KEY_GETKEY ),
	RESOURCE_IMESSAGE_KEY_SETKEY = MKINTERNAL( RESOURCE_MESSAGE_KEY_SETKEY ),
	RESOURCE_IMESSAGE_KEY_DELETEKEY = MKINTERNAL( RESOURCE_MESSAGE_KEY_DELETEKEY ),
	RESOURCE_IMESSAGE_KEY_GETFIRSTCERT = MKINTERNAL( RESOURCE_MESSAGE_KEY_GETFIRSTCERT ),
	RESOURCE_IMESSAGE_KEY_GETNEXTCERT = MKINTERNAL( RESOURCE_MESSAGE_KEY_GETNEXTCERT ),
	RESOURCE_IMESSAGE_KEY_CERTMGMT = MKINTERNAL( RESOURCE_MESSAGE_KEY_CERTMGMT ),
	RESOURCE_IMESSAGE_LAST = MKINTERNAL( RESOURCE_MESSAGE_LAST )
	} RESOURCE_MESSAGE_TYPE;

/* The properties which RESOURCE_MESSAGE_COMPARE can compare */

typedef enum {
	RESOURCE_MESSAGE_COMPARE_NONE,		/* No comparison */
	RESOURCE_MESSAGE_COMPARE_HASH,		/* Compare string hash value */
	RESOURCE_MESSAGE_COMPARE_KEYID,		/* Compare object key IDs */
	RESOURCE_MESSAGE_COMPARE_SUBJECT,	/* Compare string subject */
	RESOURCE_MESSAGE_COMPARE_ISSUERANDSERIALNUMBER,	/* Compare string iAndS */
	RESOURCE_MESSAGE_COMPARE_FINGERPRINT,	/* Compare cert.obj.fingerprint */
	RESOURCE_MESSAGE_COMPARE_LAST		/* Last possible compare type */
	} RESOURCE_MESSAGE_COMPARE_TYPE;

/* The checks which RESOURCE_MESSAGE_CHECK performs */

typedef enum {
	RESOURCE_MESSAGE_CHECK_NONE,		/* No check */
	RESOURCE_MESSAGE_CHECK_PKC,			/* Public or private key context */
	RESOURCE_MESSAGE_CHECK_PKC_PRIVATE,	/* Private key context */
	RESOURCE_MESSAGE_CHECK_PKC_ENCRYPT,	/* Public encryption context */
	RESOURCE_MESSAGE_CHECK_PKC_DECRYPT,	/* Private decryption context */
	RESOURCE_MESSAGE_CHECK_PKC_SIGCHECK,/* Public signature check context */
	RESOURCE_MESSAGE_CHECK_PKC_SIGN,	/* Private signature context */
	RESOURCE_MESSAGE_CHECK_PKC_KA_EXPORT,/* Key agreement - export context */
	RESOURCE_MESSAGE_CHECK_PKC_KA_IMPORT,/* Key agreement - import context */
	RESOURCE_MESSAGE_CHECK_CRYPT,		/* Conventional encryption context */
	RESOURCE_MESSAGE_CHECK_HASH,		/* Hash context */
	RESOURCE_MESSAGE_CHECK_MAC,			/* MAC context */
	RESOURCE_MESSAGE_CHECK_KEYGEN,		/* Key generation capability */
	RESOURCE_MESSAGE_CHECK_CA,			/* Cert signing capability */
	RESOURCE_MESSAGE_CHECK_LAST			/* Last possible check type */
	} RESOURCE_MESSAGE_CHECK_TYPE;

/* Symbolic defines for the set dependent object message */

#define SETDEP_OPTION_INCREF	TRUE	/* Increment dep.objs reference count */
#define SETDEP_OPTION_NOINCREF	FALSE	/* Don't inc.dep.objs reference count */

/* When getting/setting data, the information may be a variable-length string
   rather than a simple integer value, which would require two calls (one to
   communicate the length and one for the data).  To avoid this, we pass a
   pointer to a data-and-length structure rather than a pointer to the data */

typedef struct {
	void *data;							/* Data */
	int length;							/* Length */
	} RESOURCE_DATA;

#define setResourceData( resDataPtr, dataPtr, dataLength ) \
	{ \
	memset( ( resDataPtr ), 0, sizeof( RESOURCE_DATA ) ); \
	( resDataPtr )->data = ( dataPtr ); \
	( resDataPtr )->length = ( dataLength ); \
	}

/* Some messages communicate standard data values which are used again and 
   again so we predefine values for these which can be used globally */

#define MESSAGE_VALUE_TRUE			( ( void * ) &messageValueTrue )
#define MESSAGE_VALUE_FALSE			( ( void * ) &messageValueFalse )
#define MESSAGE_VALUE_OK			( ( void * ) &messageValueCryptOK )
#define MESSAGE_VALUE_ERROR			( ( void * ) &messageValueCryptError )
#define MESSAGE_VALUE_SIGNALLED		( ( void * ) &messageValueCryptSignalled )
#define MESSAGE_VALUE_UNUSED		( ( void * ) &messageValueCryptUnused )
#define MESSAGE_VALUE_DEFAULT		( ( void * ) &messageValueCryptUseDefault )
#define MESSAGE_VALUE_CURSORFIRST	( ( void * ) &messageValueCursorFirst )
#define MESSAGE_VALUE_CURSORNEXT	( ( void * ) &messageValueCursorNext )
#define MESSAGE_VALUE_CURSORPREVIOUS ( ( void * ) &messageValueCursorPrevious )
#define MESSAGE_VALUE_CURSORLAST	( ( void * ) &messageValueCursorLast )

extern const int messageValueTrue, messageValueFalse;
extern const int messageValueCryptOK, messageValueCryptError;
extern const int messageValueCryptSignalled;
extern const int messageValueCryptUnused, messageValueCryptUseDefault;
extern const int messageValueCursorFirst, messageValueCursorNext;
extern const int messageValueCursorPrevious, messageValueCursorLast;

/* Test for membership within an attribute class */

#define isAttribute( attribute ) \
	( ( attribute ) > CRYPT_ATTRIBUTE_NONE && \
	  ( attribute ) < CRYPT_ATTRIBUTE_LAST )
#define isInternalAttribute( attribute ) \
	( ( attribute ) > CRYPT_IATTRIBUTE_FIRST && \
	  ( attribute ) < CRYPT_IATTRIBUTE_LAST )

/* Check whether a message is in a given message class */

#define isAttributeMessage( message ) \
	( ( message ) >= RESOURCE_MESSAGE_GETATTRIBUTE && \
	  ( message ) <= RESOURCE_MESSAGE_DELETEATTRIBUTE )
#define isActionMessage( message ) \
	( ( message ) >= RESOURCE_MESSAGE_CTX_ENCRYPT && \
	  ( message ) <= RESOURCE_MESSAGE_CTX_HASH )
#define isMechanismActionMessage( message ) \
	( ( message ) >= RESOURCE_MESSAGE_DEV_EXPORT && \
	  ( message ) <= RESOURCE_MESSAGE_DEV_DERIVE )

/* The following handles correspond to built-in fixed object types which are
   available throughout the architecture.  Currently there are two objects,
   an internal system object which encapsulates the built-in RNG and the 
   built-in mechanism types (if this ever becomes a bottleneck the two can be
   separated into different objects) and a default user object which is used
   when there are no explicit user objects being employed */

#define SYSTEM_OBJECT_HANDLE	0	/* Internal system object */
#define DEFAULTUSER_OBJECT_HANDLE 1	/* Default user object */

#define NO_SYSTEM_OBJECTS		2	/* Total number of system objects */

/* We limit the maximum number of objects to a sensible value to prevent 
   deliberate/accidental DoS attacks.  The following represents about 64MB
   of object data which should be a good indication that there are more
   objects present than there should be */

#define MAX_OBJECTS				16384

/* Prototype for an object's message-handling function */

typedef int ( *RESOURCE_MESSAGE_FUNCTION )( const int objectHandle,
							const RESOURCE_MESSAGE_TYPE message,
							void *messageDataPtr, const int messageValue );

/****************************************************************************
*																			*
*							Action Message Types							*
*																			*
****************************************************************************/

/* Action messages come in two types, direct action messages and mechanism-
   action messages.  Action messages apply directly to action objects (for
   example transform a block of data) while mechanism-action messages apply
   to device objects and involve extra formatting above and beyond the direct
   action (for example perform PKCS #1 padding and then transform a block of
   data) */

/* Action permissions.  Each object can can have a range of permission 
   settings which control how action messages sent to it are handled.  The
   most common case is that the action isn't available for this object,
   ACTION_PERM_NOTAVAIL.  This is an all-zero permission, so the default is
   deny-all unless the action is explicitly permitted.  The permissions are
   ACTION_PERM_NONE, which means the action is in theory available but has
   been turned off, ACTION_PERM_NONE_EXTERNAL, which means the action is only 
   valid if the message is coming from inside cryptlib, and ACTION_PERM_ALL, 
   which means the action is available for anyone.
   
   The kernel enforces a ratchet for these setting which only allows them to
   be set to a more restrictive value than their existing one.  If a setting
   starts out as not available on object creation, it can never be enabled. 
   If a setting starts as none-external, it can only be set to a straight 
   none, but never to all */

#define ACTION_PERM_NOTAVAIL		0x00
#define ACTION_PERM_NONE			0x01
#define ACTION_PERM_NONE_EXTERNAL	0x02
#define ACTION_PERM_ALL				0x03

#define ACTION_PERM_BASE	RESOURCE_MESSAGE_CTX_ENCRYPT
#define ACTION_PERM_MASK	0x03
#define ACTION_PERM_BITS	2
#define ACTION_PERM_COUNT	( RESOURCE_MESSAGE_CTX_GENKEY - \
							  RESOURCE_MESSAGE_CTX_ENCRYPT + 1 )
#define ACTION_PERM_LAST	\
		( 1 << ( ( ( ACTION_PERM_COUNT ) * ACTION_PERM_BITS ) + 1 ) )
#define ACTION_PERM_SHIFT( action ) \
		( ( ( action ) - ACTION_PERM_BASE ) * ACTION_PERM_BITS )
#define MK_ACTION_PERM( action, perm ) \
		( ( perm ) << ACTION_PERM_SHIFT( action ) )

/* The mechanism types.  The distinction between the PKCS #1 and raw PKCS #1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -