📄 cryptkrn.h
字号:
MESSAGE_ENV_POPDATA, /* Envelope: Pop data */
MESSAGE_KEY_GETKEY, /* Keyset: Instantiate ctx/cert */
MESSAGE_KEY_SETKEY, /* Keyset: Add ctx/cert */
MESSAGE_KEY_DELETEKEY, /* Keyset: Delete key/cert */
MESSAGE_KEY_GETFIRSTCERT, /* Keyset: Get first cert in sequence */
MESSAGE_KEY_GETNEXTCERT, /* Keyset: Get next cert in sequence */
MESSAGE_KEY_CERTMGMT, /* Keyset: Cert management */
MESSAGE_LAST, /* Last valid message type */
/* Internal object versions of the above messages */
IMESSAGE_DESTROY = MKINTERNAL( MESSAGE_DESTROY ),
IMESSAGE_INCREFCOUNT = MKINTERNAL( MESSAGE_INCREFCOUNT ),
IMESSAGE_DECREFCOUNT = MKINTERNAL( MESSAGE_DECREFCOUNT ),
IMESSAGE_GETDEPENDENT = MKINTERNAL( MESSAGE_GETDEPENDENT ),
IMESSAGE_SETDEPENDENT = MKINTERNAL( MESSAGE_SETDEPENDENT ),
IMESSAGE_CLONE = MKINTERNAL( MESSAGE_CLONE ),
IMESSAGE_GETATTRIBUTE = MKINTERNAL( MESSAGE_GETATTRIBUTE ),
IMESSAGE_GETATTRIBUTE_S = MKINTERNAL( MESSAGE_GETATTRIBUTE_S ),
IMESSAGE_SETATTRIBUTE = MKINTERNAL( MESSAGE_SETATTRIBUTE ),
IMESSAGE_SETATTRIBUTE_S = MKINTERNAL( MESSAGE_SETATTRIBUTE_S ),
IMESSAGE_DELETEATTRIBUTE = MKINTERNAL( MESSAGE_DELETEATTRIBUTE ),
IMESSAGE_COMPARE = MKINTERNAL( MESSAGE_COMPARE ),
IMESSAGE_CHECK = MKINTERNAL( MESSAGE_CHECK ),
IMESSAGE_CHANGENOTIFY = MKINTERNAL( MESSAGE_CHANGENOTIFY ),
IMESSAGE_CTX_ENCRYPT = MKINTERNAL( MESSAGE_CTX_ENCRYPT ),
IMESSAGE_CTX_DECRYPT = MKINTERNAL( MESSAGE_CTX_DECRYPT ),
IMESSAGE_CTX_SIGN = MKINTERNAL( MESSAGE_CTX_SIGN ),
IMESSAGE_CTX_SIGCHECK = MKINTERNAL( MESSAGE_CTX_SIGCHECK ),
IMESSAGE_CTX_HASH = MKINTERNAL( MESSAGE_CTX_HASH ),
IMESSAGE_CTX_GENKEY = MKINTERNAL( MESSAGE_CTX_GENKEY ),
IMESSAGE_CTX_GENIV = MKINTERNAL( MESSAGE_CTX_GENIV ),
IMESSAGE_CRT_SIGN = MKINTERNAL( MESSAGE_CRT_SIGN ),
IMESSAGE_CRT_SIGCHECK = MKINTERNAL( MESSAGE_CRT_SIGCHECK ),
IMESSAGE_CRT_EXPORT = MKINTERNAL( MESSAGE_CRT_EXPORT ),
IMESSAGE_DEV_QUERYCAPABILITY = MKINTERNAL( MESSAGE_DEV_QUERYCAPABILITY ),
IMESSAGE_DEV_EXPORT = MKINTERNAL( MESSAGE_DEV_EXPORT ),
IMESSAGE_DEV_IMPORT = MKINTERNAL( MESSAGE_DEV_IMPORT ),
IMESSAGE_DEV_SIGN = MKINTERNAL( MESSAGE_DEV_SIGN ),
IMESSAGE_DEV_SIGCHECK = MKINTERNAL( MESSAGE_DEV_SIGCHECK ),
IMESSAGE_DEV_DERIVE = MKINTERNAL( MESSAGE_DEV_DERIVE ),
IMESSAGE_DEV_CREATEOBJECT = MKINTERNAL( MESSAGE_DEV_CREATEOBJECT ),
IMESSAGE_DEV_CREATEOBJECT_INDIRECT = MKINTERNAL( MESSAGE_DEV_CREATEOBJECT_INDIRECT ),
IMESSAGE_ENV_PUSHDATA = MKINTERNAL( MESSAGE_ENV_PUSHDATA ),
IMESSAGE_ENV_POPDATA = MKINTERNAL( MESSAGE_ENV_POPDATA ),
IMESSAGE_KEY_GETKEY = MKINTERNAL( MESSAGE_KEY_GETKEY ),
IMESSAGE_KEY_SETKEY = MKINTERNAL( MESSAGE_KEY_SETKEY ),
IMESSAGE_KEY_DELETEKEY = MKINTERNAL( MESSAGE_KEY_DELETEKEY ),
IMESSAGE_KEY_GETFIRSTCERT = MKINTERNAL( MESSAGE_KEY_GETFIRSTCERT ),
IMESSAGE_KEY_GETNEXTCERT = MKINTERNAL( MESSAGE_KEY_GETNEXTCERT ),
IMESSAGE_KEY_CERTMGMT = MKINTERNAL( MESSAGE_KEY_CERTMGMT ),
IMESSAGE_LAST = MKINTERNAL( MESSAGE_LAST )
} MESSAGE_TYPE;
/* The properties that MESSAGE_COMPARE can compare */
typedef enum {
MESSAGE_COMPARE_NONE, /* No comparison */
MESSAGE_COMPARE_HASH, /* Compare hash value */
MESSAGE_COMPARE_KEYID, /* Compare key IDs */
MESSAGE_COMPARE_KEYID_PGP, /* Compare PGP key IDs */
MESSAGE_COMPARE_KEYID_OPENPGP, /* Compare OpenPGP key IDs */
MESSAGE_COMPARE_SUBJECT, /* Compare subject */
MESSAGE_COMPARE_ISSUERANDSERIALNUMBER, /* Compare iAndS */
MESSAGE_COMPARE_FINGERPRINT, /* Compare cert.fingerprint */
MESSAGE_COMPARE_CERTOBJ, /* Compare cert objects */
MESSAGE_COMPARE_LAST /* Last possible compare type */
} MESSAGE_COMPARE_TYPE;
/* The checks that MESSAGE_CHECK performs */
typedef enum {
MESSAGE_CHECK_NONE, /* No check */
MESSAGE_CHECK_PKC, /* Public or private key context */
MESSAGE_CHECK_PKC_PRIVATE, /* Private key context */
MESSAGE_CHECK_PKC_ENCRYPT, /* Public encryption context */
MESSAGE_CHECK_PKC_DECRYPT, /* Private decryption context */
MESSAGE_CHECK_PKC_SIGCHECK, /* Public signature check context */
MESSAGE_CHECK_PKC_SIGN, /* Private signature context */
MESSAGE_CHECK_PKC_KA_EXPORT, /* Key agreement - export context */
MESSAGE_CHECK_PKC_KA_IMPORT, /* Key agreement - import context */
MESSAGE_CHECK_CRYPT, /* Conventional encryption context */
MESSAGE_CHECK_HASH, /* Hash context */
MESSAGE_CHECK_MAC, /* MAC context */
MESSAGE_CHECK_KEYGEN, /* Key generation capability */
MESSAGE_CHECK_CA, /* Cert signing capability */
MESSAGE_CHECK_LAST /* Last possible check type */
} 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 string data which consists of (value, length) pairs,
we pass a pointer to a value-and-length structure rather than a pointer to
the data itself */
typedef struct {
void *data; /* Data */
int length; /* Length */
} RESOURCE_DATA;
#define setMessageData( msgDataPtr, dataPtr, dataLength ) \
{ \
( msgDataPtr )->data = ( dataPtr ); \
( msgDataPtr )->length = ( dataLength ); \
}
/* Some messages communicate standard data values that 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_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 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, used in object
message handlers */
#define isAttributeMessage( message ) \
( ( message ) >= MESSAGE_GETATTRIBUTE && \
( message ) <= MESSAGE_DELETEATTRIBUTE )
#define isActionMessage( message ) \
( ( message ) >= MESSAGE_CTX_ENCRYPT && \
( message ) <= MESSAGE_CTX_HASH )
#define isMechanismActionMessage( message ) \
( ( message ) >= MESSAGE_DEV_EXPORT && \
( message ) <= MESSAGE_DEV_DERIVE )
/* The following handles correspond to built-in fixed object types that are
available throughout the architecture. Currently there are two objects,
an internal system object that 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 32MB
of object data which should be a good indication that there are more
objects present than there should be */
#define MAX_OBJECTS 16384
/****************************************************************************
* *
* 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).
Each object that processes direct action messages can can have a range of
permission settings that 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
other permissions are ACTION_PERM_NONE, which means that the action is in
theory available but has been turned off, ACTION_PERM_NONE_EXTERNAL,
which means that the action is only valid if the message is coming from
inside cryptlib, and ACTION_PERM_ALL, which means that the action is
available for anyone. In order to set all permissions to a certain value
(e.g. NONE_EXTERNAL), we define overall values xxx_ALL which (in
combination with the kernel-enforced ratchet) can be used to set all
settings to (at most) the given value.
The order of the action bits is:
hash sign encr
| | |
xx xx xx xx xx xx
| | |
kgen sigch decr
x.. .0 .. .0 .. .0 Hex digits
Common settings are 0xCFF (new PKC, all operations), 0x0F (key-loaded
conv., all operations), and 0xAA (key-loaded PKC, internal-only
operations).
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_NONE_ALL 0x000
#define ACTION_PERM_NONE_EXTERNAL_ALL 0xAAA
#define ACTION_PERM_BASE MESSAGE_CTX_ENCRYPT
#define ACTION_PERM_MASK 0x03
#define ACTION_PERM_BITS 2
#define ACTION_PERM_COUNT ( MESSAGE_CTX_GENKEY - \
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 ) )
#define MK_ACTION_PERM_NONE_EXTERNAL( action ) \
( ( action ) & ACTION_PERM_NONE_EXTERNAL_ALL )
/* The mechanism types. The distinction between the PKCS #1 and raw PKCS #1
mechanisms is somewhat artificial in that they do the same thing, however
it's easier for the kernel to perform security checks on parameters if
the two are distinct */
typedef enum {
MECHANISM_NONE, /* No mechanism */
MECHANISM_PKCS1, /* PKCS #1 sign/encrypt */
MECHANISM_PKCS1_PGP, /* PKCS #1 using PGP formatting */
MECHANISM_PKCS1_RAW, /* PKCS #1 returning uninterpreted data */
MECHANISM_PKCS5, /* PKCS #5 derive */
MECHANISM_PKCS12, /* PKCS #12 derive */
MECHANISM_CMS, /* CMS key wrap */
MECHANISM_KEA, /* KEA key agreement */
MECHANISM_SSL, /* SSL derive */
MECHANISM_TLS, /* TLS derive */
MECHANISM_CMP, /* CMP/Entrust derive */
MECHANISM_PGP, /* OpenPGP S2K derive */
MECHANISM_PRIVATEKEYWRAP, /* Private key wrap */
MECHANISM_PRIVATEKEYWRAP_PKCS8, /* PKCS #8 private key wrap */
MECHANISM_PRIVATEKEYWRAP_PGP, /* PGP private key wrap */
MECHANISM_PRIVATEKEYWRAP_OPENPGP,/* OpenPGP private key wrap */
MECHANISM_LAST /* Last valid mechanism type */
} MECHANISM_TYPE;
/* A structure to hold information needed by the key export/import mechanism.
The key can be passed as raw key data or as a context if tied to hardware
that doesn't allow keying material outside the hardware's security
perimeter:
PKCS #1 wrappedData = wrapped key
PKCS #1 PGP keyData = -
keyContext = context containing key
wrapContext = wrap/unwrap PKC context
auxContext = CRYPT_UNUSED
PKCS #1 raw wrappedData = wrapped raw data
keyData = uninterpreted raw data
keyContext = CRYPT_UNUSED
wrapContext = wrap/unwrap PKC context
auxContext = CRYPT_UNUSED
CMS wrappedData = wrapped key
keyData = raw key - or -
keyContext = context containing key
wrapContext = wrap/unwrap conventional context
auxContext = CRYPT_UNUSED
KEA wrappedData = len + TEK( MEK ), len + UKM
keyData = NULL
keyContext = MEK
wrapContext = recipient KEA public key
auxContext = originator KEA private key
ssh wrappedData = double-wrapped key
keyData = raw key
keyContext = CRYPT_UNUSED
wrapContext = server PKC key
auxContext = host PKC key
Private wrappedData = Padded encrypted private key components
key wrap keyData = -
keyContext = context containing private key
wrapContext = wrap/unwrap conventional context
auxContext = CRYPT_UNUSED */
typedef struct {
void *wrappedData; /* Wrapped key */
int wrappedDataLength;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -