pkcs11.h文件:
- #include "pkcs11t.h"
- #define __PASTE(x,y) x##y
- /* ==============================================================
- * Define the "extern" form of all the entry points.
- * ==============================================================
- */
- #define CK_NEED_ARG_LIST 1
- #define CK_PKCS11_FUNCTION_INFO(name) \
- extern CK_DECLARE_FUNCTION(CK_RV, name)
- /* pkcs11f.h has all the information about the Cryptoki
- * function prototypes. */
- #include "pkcs11f.h"
- #undef CK_NEED_ARG_LIST
- #undef CK_PKCS11_FUNCTION_INFO
- /* ==============================================================
- * Define the typedef form of all the entry points. That is, for
- * each Cryptoki function C_XXX, define a type CK_C_XXX which is
- * a pointer to that kind of function.
- * ==============================================================
- */
- #define CK_NEED_ARG_LIST 1
- #define CK_PKCS11_FUNCTION_INFO(name) \
- typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
- /* pkcs11f.h has all the information about the Cryptoki
- * function prototypes. */
- #include "pkcs11f.h"
- #undef CK_NEED_ARG_LIST
- #undef CK_PKCS11_FUNCTION_INFO
- /* ==============================================================
- * Define structed vector of entry points. A CK_FUNCTION_LIST
- * contains a CK_VERSION indicating a library's Cryptoki version
- * and then a whole slew of function pointers to the routines in
- * the library. This type was declared, but not defined, in
- * pkcs11t.h.
- * ==============================================================
- */
- #define CK_PKCS11_FUNCTION_INFO(name) \
- __PASTE(CK_,name) name;
-
- struct CK_FUNCTION_LIST {
- CK_VERSION version; /* Cryptoki version */
- /* Pile all the function pointers into the CK_FUNCTION_LIST. */
- /* pkcs11f.h has all the information about the Cryptoki
- * function prototypes. */
- #include "pkcs11f.h"
- };
- #undef CK_PKCS11_FUNCTION_INFO
- #undef __PASTE
- #ifdef __cplusplus
- }
- #endif
- #endif
pkcs11f.h文件:
- /* C_Initialize initializes the Cryptoki library. */
- CK_PKCS11_FUNCTION_INFO(C_Initialize)
- #ifdef CK_NEED_ARG_LIST
- (
- CK_VOID_PTR pInitArgs /* if this is not NULL_PTR, it gets
- * cast to CK_C_INITIALIZE_ARGS_PTR
- * and dereferenced */
- );
- #endif
- /* C_Finalize indicates that an application is done with the
- * Cryptoki library. */
- CK_PKCS11_FUNCTION_INFO(C_Finalize)
- #ifdef CK_NEED_ARG_LIST
- (
- CK_VOID_PTR pReserved /* reserved. Should be NULL_PTR */
- );
- #endif
- /* C_GetInfo returns general information about Cryptoki. */
- CK_PKCS11_FUNCTION_INFO(C_GetInfo)
- #ifdef CK_NEED_ARG_LIST
- (
- CK_INFO_PTR pInfo /* location that receives information */
- );
- #endif
- /* C_GetFunctionList returns the function list. */
- CK_PKCS11_FUNCTION_INFO(C_GetFunctionList)
- #ifdef CK_NEED_ARG_LIST
- (
- CK_FUNCTION_LIST_PTR_PTR ppFunctionList /* receives pointer to
- * function list */
- );
- #endif
- /* Slot and token management */
- /* C_GetSlotList obtains a list of slots in the system. */
- CK_PKCS11_FUNCTION_INFO(C_GetSlotList)
- #ifdef CK_NEED_ARG_LIST
- (
- CK_BBOOL tokenPresent, /* only slots with tokens? */
- CK_SLOT_ID_PTR pSlotList, /* receives array of slot IDs */
- CK_ULONG_PTR pulCount /* receives number of slots */
- );
- #endif
pkcs11t.h文件:
- #ifndef _PKCS11T_H_
- #define _PKCS11T_H_ 1
- #ifndef CK_DISABLE_TRUE_FALSE
- #ifndef FALSE
- #define FALSE 0
- #endif
- #ifndef TRUE
- #define TRUE !(FALSE)
- #endif
- #endif
- #define CK_TRUE 1
- #define CK_FALSE 0
- /* an unsigned 8-bit value */
- typedef unsigned char CK_BYTE;
- /* an unsigned 8-bit character */
- typedef CK_BYTE CK_CHAR;
- /* an 8-bit UTF-8 character */
- typedef CK_BYTE CK_UTF8CHAR;
- /* a BYTE-sized Boolean flag */
- typedef CK_BYTE CK_BBOOL;
- /* an unsigned value, at least 32 bits long */
- typedef unsigned long int CK_ULONG;
- /* a signed value, the same size as a CK_ULONG */
- /* CK_LONG is new for v2.0 */
- typedef long int CK_LONG;
- /* at least 32 bits; each bit is a Boolean flag */
- typedef CK_ULONG CK_FLAGS;
- /* some special values for certain CK_ULONG variables */
- #define CK_UNAVAILABLE_INFORMATION (~0UL)
- #define CK_EFFECTIVELY_INFINITE 0
- typedef CK_BYTE CK_PTR CK_BYTE_PTR;
- typedef CK_CHAR CK_PTR CK_CHAR_PTR;
- typedef CK_UTF8CHAR CK_PTR CK_UTF8CHAR_PTR;
- typedef CK_ULONG CK_PTR CK_ULONG_PTR;
- typedef void CK_PTR CK_VOID_PTR;
- /* Pointer to a CK_VOID_PTR-- i.e., pointer to pointer to void */
- typedef CK_VOID_PTR CK_PTR CK_VOID_PTR_PTR;
- /* The following value is always invalid if used as a session */
- /* handle or object handle */
- #define CK_INVALID_HANDLE 0
- typedef struct CK_VERSION {
- CK_BYTE major; /* integer portion of version number */
- CK_BYTE minor; /* 1/100ths portion of version number */
- } CK_VERSION;
通过#define CK_PKCS11_FUNCTION_INFO(name)...
然后#include "pkcs11f.h"
然后再#undef CK_PKCS11_FUNCTION_INFO(name)
再#define CK_PKCS11_FUNCTION_INFO(name)...
再#include "pkc11f.h"
然后#undef CK_PKCS11_FUNCTION_INFO(name)
再#include "pkc11f.h" .............
如此反复三次,使同一个头文件获得了不同的函数声明(有函数的声明,也有函数指针的声明,同时还定义了一个包含函数指针的结构体)。
真是妙啊!
阅读(1737) | 评论(0) | 转发(0) |