Chinaunix首页 | 论坛 | 博客
  • 博客访问: 50598
  • 博文数量: 27
  • 博客积分: 716
  • 博客等级: 上士
  • 技术积分: 285
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-31 11:12
文章分类

全部博文(27)

文章存档

2012年(8)

2011年(19)

我的朋友

分类: C/C++

2011-09-15 23:25:58

pkcs11.h文件:
  1. #include "pkcs11t.h"

  2. #define __PASTE(x,y) x##y


  3. /* ==============================================================
  4.  * Define the "extern" form of all the entry points.
  5.  * ==============================================================
  6.  */

  7. #define CK_NEED_ARG_LIST 1
  8. #define CK_PKCS11_FUNCTION_INFO(name) \
  9.   extern CK_DECLARE_FUNCTION(CK_RV, name)

  10. /* pkcs11f.h has all the information about the Cryptoki
  11.  * function prototypes. */
  12. #include "pkcs11f.h"

  13. #undef CK_NEED_ARG_LIST
  14. #undef CK_PKCS11_FUNCTION_INFO


  15. /* ==============================================================
  16.  * Define the typedef form of all the entry points. That is, for
  17.  * each Cryptoki function C_XXX, define a type CK_C_XXX which is
  18.  * a pointer to that kind of function.
  19.  * ==============================================================
  20.  */

  21. #define CK_NEED_ARG_LIST 1
  22. #define CK_PKCS11_FUNCTION_INFO(name) \
  23.   typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))

  24. /* pkcs11f.h has all the information about the Cryptoki
  25.  * function prototypes. */
  26. #include "pkcs11f.h"

  27. #undef CK_NEED_ARG_LIST
  28. #undef CK_PKCS11_FUNCTION_INFO


  29. /* ==============================================================
  30.  * Define structed vector of entry points. A CK_FUNCTION_LIST
  31.  * contains a CK_VERSION indicating a library's Cryptoki version
  32.  * and then a whole slew of function pointers to the routines in
  33.  * the library. This type was declared, but not defined, in
  34.  * pkcs11t.h.
  35.  * ==============================================================
  36.  */

  37. #define CK_PKCS11_FUNCTION_INFO(name) \
  38.   __PASTE(CK_,name) name;
  39.   
  40. struct CK_FUNCTION_LIST {

  41.   CK_VERSION version; /* Cryptoki version */

  42. /* Pile all the function pointers into the CK_FUNCTION_LIST. */
  43. /* pkcs11f.h has all the information about the Cryptoki
  44.  * function prototypes. */
  45. #include "pkcs11f.h"

  46. };

  47. #undef CK_PKCS11_FUNCTION_INFO


  48. #undef __PASTE

  49. #ifdef __cplusplus
  50. }
  51. #endif

  52. #endif

pkcs11f.h文件:

  1. /* C_Initialize initializes the Cryptoki library. */
  2. CK_PKCS11_FUNCTION_INFO(C_Initialize)
  3. #ifdef CK_NEED_ARG_LIST
  4. (
  5. CK_VOID_PTR pInitArgs /* if this is not NULL_PTR, it gets
  6. * cast to CK_C_INITIALIZE_ARGS_PTR
  7. * and dereferenced */
  8. );
  9. #endif


  10. /* C_Finalize indicates that an application is done with the
  11. * Cryptoki library. */
  12. CK_PKCS11_FUNCTION_INFO(C_Finalize)
  13. #ifdef CK_NEED_ARG_LIST
  14. (
  15. CK_VOID_PTR pReserved /* reserved. Should be NULL_PTR */
  16. );
  17. #endif


  18. /* C_GetInfo returns general information about Cryptoki. */
  19. CK_PKCS11_FUNCTION_INFO(C_GetInfo)
  20. #ifdef CK_NEED_ARG_LIST
  21. (
  22. CK_INFO_PTR pInfo /* location that receives information */
  23. );
  24. #endif


  25. /* C_GetFunctionList returns the function list. */
  26. CK_PKCS11_FUNCTION_INFO(C_GetFunctionList)
  27. #ifdef CK_NEED_ARG_LIST
  28. (
  29. CK_FUNCTION_LIST_PTR_PTR ppFunctionList /* receives pointer to
  30. * function list */
  31. );
  32. #endif



  33. /* Slot and token management */

  34. /* C_GetSlotList obtains a list of slots in the system. */
  35. CK_PKCS11_FUNCTION_INFO(C_GetSlotList)
  36. #ifdef CK_NEED_ARG_LIST
  37. (
  38. CK_BBOOL tokenPresent, /* only slots with tokens? */
  39. CK_SLOT_ID_PTR pSlotList, /* receives array of slot IDs */
  40. CK_ULONG_PTR pulCount /* receives number of slots */
  41. );
  42. #endif

pkcs11t.h文件:

  1. #ifndef _PKCS11T_H_
  2. #define _PKCS11T_H_ 1

  3. #ifndef CK_DISABLE_TRUE_FALSE
  4. #ifndef FALSE
  5. #define FALSE 0
  6. #endif

  7. #ifndef TRUE
  8. #define TRUE !(FALSE)
  9. #endif
  10. #endif

  11. #define CK_TRUE 1
  12. #define CK_FALSE 0

  13. /* an unsigned 8-bit value */
  14. typedef unsigned char CK_BYTE;

  15. /* an unsigned 8-bit character */
  16. typedef CK_BYTE CK_CHAR;

  17. /* an 8-bit UTF-8 character */
  18. typedef CK_BYTE CK_UTF8CHAR;

  19. /* a BYTE-sized Boolean flag */
  20. typedef CK_BYTE CK_BBOOL;

  21. /* an unsigned value, at least 32 bits long */
  22. typedef unsigned long int CK_ULONG;

  23. /* a signed value, the same size as a CK_ULONG */
  24. /* CK_LONG is new for v2.0 */
  25. typedef long int CK_LONG;

  26. /* at least 32 bits; each bit is a Boolean flag */
  27. typedef CK_ULONG CK_FLAGS;


  28. /* some special values for certain CK_ULONG variables */
  29. #define CK_UNAVAILABLE_INFORMATION (~0UL)
  30. #define CK_EFFECTIVELY_INFINITE 0


  31. typedef CK_BYTE CK_PTR CK_BYTE_PTR;
  32. typedef CK_CHAR CK_PTR CK_CHAR_PTR;
  33. typedef CK_UTF8CHAR CK_PTR CK_UTF8CHAR_PTR;
  34. typedef CK_ULONG CK_PTR CK_ULONG_PTR;
  35. typedef void CK_PTR CK_VOID_PTR;

  36. /* Pointer to a CK_VOID_PTR-- i.e., pointer to pointer to void */
  37. typedef CK_VOID_PTR CK_PTR CK_VOID_PTR_PTR;


  38. /* The following value is always invalid if used as a session */
  39. /* handle or object handle */
  40. #define CK_INVALID_HANDLE 0


  41. typedef struct CK_VERSION {
  42.   CK_BYTE major; /* integer portion of version number */
  43.   CK_BYTE minor; /* 1/100ths portion of version number */
  44. } 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"  .............

如此反复三次,使同一个头文件获得了不同的函数声明(有函数的声明,也有函数指针的声明,同时还定义了一个包含函数指针的结构体)。

真是妙啊!

 

阅读(1731) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~