1*b106467fSJason King /* Copyright (c) OASIS Open 2016. All Rights Reserved./ 2*b106467fSJason King * /Distributed under the terms of the OASIS IPR Policy, 3*b106467fSJason King * [http://www.oasis-open.org/policies-guidelines/ipr], AS-IS, WITHOUT ANY 4*b106467fSJason King * IMPLIED OR EXPRESS WARRANTY; there is no warranty of MERCHANTABILITY, FITNESS FOR A 5*b106467fSJason King * PARTICULAR PURPOSE or NONINFRINGEMENT of the rights of others. 6*b106467fSJason King */ 77c478bd9Sstevel@tonic-gate 8*b106467fSJason King /* Latest version of the specification: 9*b106467fSJason King * http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/pkcs11-base-v2.40.html 107c478bd9Sstevel@tonic-gate */ 117c478bd9Sstevel@tonic-gate 127c478bd9Sstevel@tonic-gate #ifndef _PKCS11_H_ 137c478bd9Sstevel@tonic-gate #define _PKCS11_H_ 1 147c478bd9Sstevel@tonic-gate 157c478bd9Sstevel@tonic-gate #ifdef __cplusplus 167c478bd9Sstevel@tonic-gate extern "C" { 177c478bd9Sstevel@tonic-gate #endif 187c478bd9Sstevel@tonic-gate 197c478bd9Sstevel@tonic-gate /* Before including this file (pkcs11.h) (or pkcs11t.h by 20*b106467fSJason King * itself), 5 platform-specific macros must be defined. These 217c478bd9Sstevel@tonic-gate * macros are described below, and typical definitions for them 227c478bd9Sstevel@tonic-gate * are also given. Be advised that these definitions can depend 237c478bd9Sstevel@tonic-gate * on both the platform and the compiler used (and possibly also 247c478bd9Sstevel@tonic-gate * on whether a Cryptoki library is linked statically or 257c478bd9Sstevel@tonic-gate * dynamically). 267c478bd9Sstevel@tonic-gate * 27*b106467fSJason King * In addition to defining these 5 macros, the packing convention 287c478bd9Sstevel@tonic-gate * for Cryptoki structures should be set. The Cryptoki 297c478bd9Sstevel@tonic-gate * convention on packing is that structures should be 1-byte 307c478bd9Sstevel@tonic-gate * aligned. 317c478bd9Sstevel@tonic-gate * 327c478bd9Sstevel@tonic-gate * If you're using Microsoft Developer Studio 5.0 to produce 337c478bd9Sstevel@tonic-gate * Win32 stuff, this might be done by using the following 347c478bd9Sstevel@tonic-gate * preprocessor directive before including pkcs11.h or pkcs11t.h: 357c478bd9Sstevel@tonic-gate * 367c478bd9Sstevel@tonic-gate * #pragma pack(push, cryptoki, 1) 377c478bd9Sstevel@tonic-gate * 387c478bd9Sstevel@tonic-gate * and using the following preprocessor directive after including 397c478bd9Sstevel@tonic-gate * pkcs11.h or pkcs11t.h: 407c478bd9Sstevel@tonic-gate * 417c478bd9Sstevel@tonic-gate * #pragma pack(pop, cryptoki) 427c478bd9Sstevel@tonic-gate * 437c478bd9Sstevel@tonic-gate * If you're using an earlier version of Microsoft Developer 447c478bd9Sstevel@tonic-gate * Studio to produce Win16 stuff, this might be done by using 457c478bd9Sstevel@tonic-gate * the following preprocessor directive before including 467c478bd9Sstevel@tonic-gate * pkcs11.h or pkcs11t.h: 477c478bd9Sstevel@tonic-gate * 487c478bd9Sstevel@tonic-gate * #pragma pack(1) 497c478bd9Sstevel@tonic-gate * 507c478bd9Sstevel@tonic-gate * In a UNIX environment, you're on your own for this. You might 517c478bd9Sstevel@tonic-gate * not need to do (or be able to do!) anything. 527c478bd9Sstevel@tonic-gate * 537c478bd9Sstevel@tonic-gate * 547c478bd9Sstevel@tonic-gate * Now for the macros: 557c478bd9Sstevel@tonic-gate * 567c478bd9Sstevel@tonic-gate * 577c478bd9Sstevel@tonic-gate * 1. CK_PTR: The indirection string for making a pointer to an 587c478bd9Sstevel@tonic-gate * object. It can be used like this: 597c478bd9Sstevel@tonic-gate * 607c478bd9Sstevel@tonic-gate * typedef CK_BYTE CK_PTR CK_BYTE_PTR; 617c478bd9Sstevel@tonic-gate * 627c478bd9Sstevel@tonic-gate * If you're using Microsoft Developer Studio 5.0 to produce 637c478bd9Sstevel@tonic-gate * Win32 stuff, it might be defined by: 647c478bd9Sstevel@tonic-gate * 657c478bd9Sstevel@tonic-gate * #define CK_PTR * 667c478bd9Sstevel@tonic-gate * 677c478bd9Sstevel@tonic-gate * If you're using an earlier version of Microsoft Developer 687c478bd9Sstevel@tonic-gate * Studio to produce Win16 stuff, it might be defined by: 697c478bd9Sstevel@tonic-gate * 707c478bd9Sstevel@tonic-gate * #define CK_PTR far * 717c478bd9Sstevel@tonic-gate * 727c478bd9Sstevel@tonic-gate * In a typical UNIX environment, it might be defined by: 737c478bd9Sstevel@tonic-gate * 747c478bd9Sstevel@tonic-gate * #define CK_PTR * 757c478bd9Sstevel@tonic-gate * 767c478bd9Sstevel@tonic-gate * 77*b106467fSJason King * 2. CK_DECLARE_FUNCTION(returnType, name): A macro which makes 787c478bd9Sstevel@tonic-gate * an importable Cryptoki library function declaration out of a 797c478bd9Sstevel@tonic-gate * return type and a function name. It should be used in the 807c478bd9Sstevel@tonic-gate * following fashion: 817c478bd9Sstevel@tonic-gate * 827c478bd9Sstevel@tonic-gate * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)( 837c478bd9Sstevel@tonic-gate * CK_VOID_PTR pReserved 847c478bd9Sstevel@tonic-gate * ); 857c478bd9Sstevel@tonic-gate * 867c478bd9Sstevel@tonic-gate * If you're using Microsoft Developer Studio 5.0 to declare a 877c478bd9Sstevel@tonic-gate * function in a Win32 Cryptoki .dll, it might be defined by: 887c478bd9Sstevel@tonic-gate * 897c478bd9Sstevel@tonic-gate * #define CK_DECLARE_FUNCTION(returnType, name) \ 907c478bd9Sstevel@tonic-gate * returnType __declspec(dllimport) name 917c478bd9Sstevel@tonic-gate * 927c478bd9Sstevel@tonic-gate * If you're using an earlier version of Microsoft Developer 937c478bd9Sstevel@tonic-gate * Studio to declare a function in a Win16 Cryptoki .dll, it 947c478bd9Sstevel@tonic-gate * might be defined by: 957c478bd9Sstevel@tonic-gate * 967c478bd9Sstevel@tonic-gate * #define CK_DECLARE_FUNCTION(returnType, name) \ 977c478bd9Sstevel@tonic-gate * returnType __export _far _pascal name 987c478bd9Sstevel@tonic-gate * 997c478bd9Sstevel@tonic-gate * In a UNIX environment, it might be defined by: 1007c478bd9Sstevel@tonic-gate * 1017c478bd9Sstevel@tonic-gate * #define CK_DECLARE_FUNCTION(returnType, name) \ 1027c478bd9Sstevel@tonic-gate * returnType name 1037c478bd9Sstevel@tonic-gate * 1047c478bd9Sstevel@tonic-gate * 105*b106467fSJason King * 3. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro 1067c478bd9Sstevel@tonic-gate * which makes a Cryptoki API function pointer declaration or 1077c478bd9Sstevel@tonic-gate * function pointer type declaration out of a return type and a 1087c478bd9Sstevel@tonic-gate * function name. It should be used in the following fashion: 1097c478bd9Sstevel@tonic-gate * 1107c478bd9Sstevel@tonic-gate * // Define funcPtr to be a pointer to a Cryptoki API function 1117c478bd9Sstevel@tonic-gate * // taking arguments args and returning CK_RV. 1127c478bd9Sstevel@tonic-gate * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args); 1137c478bd9Sstevel@tonic-gate * 1147c478bd9Sstevel@tonic-gate * or 1157c478bd9Sstevel@tonic-gate * 1167c478bd9Sstevel@tonic-gate * // Define funcPtrType to be the type of a pointer to a 1177c478bd9Sstevel@tonic-gate * // Cryptoki API function taking arguments args and returning 1187c478bd9Sstevel@tonic-gate * // CK_RV, and then define funcPtr to be a variable of type 1197c478bd9Sstevel@tonic-gate * // funcPtrType. 1207c478bd9Sstevel@tonic-gate * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args); 1217c478bd9Sstevel@tonic-gate * funcPtrType funcPtr; 1227c478bd9Sstevel@tonic-gate * 1237c478bd9Sstevel@tonic-gate * If you're using Microsoft Developer Studio 5.0 to access 1247c478bd9Sstevel@tonic-gate * functions in a Win32 Cryptoki .dll, in might be defined by: 1257c478bd9Sstevel@tonic-gate * 1267c478bd9Sstevel@tonic-gate * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \ 1277c478bd9Sstevel@tonic-gate * returnType __declspec(dllimport) (* name) 1287c478bd9Sstevel@tonic-gate * 1297c478bd9Sstevel@tonic-gate * If you're using an earlier version of Microsoft Developer 1307c478bd9Sstevel@tonic-gate * Studio to access functions in a Win16 Cryptoki .dll, it might 1317c478bd9Sstevel@tonic-gate * be defined by: 1327c478bd9Sstevel@tonic-gate * 1337c478bd9Sstevel@tonic-gate * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \ 1347c478bd9Sstevel@tonic-gate * returnType __export _far _pascal (* name) 1357c478bd9Sstevel@tonic-gate * 1367c478bd9Sstevel@tonic-gate * In a UNIX environment, it might be defined by: 1377c478bd9Sstevel@tonic-gate * 1387c478bd9Sstevel@tonic-gate * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \ 1397c478bd9Sstevel@tonic-gate * returnType (* name) 1407c478bd9Sstevel@tonic-gate * 1417c478bd9Sstevel@tonic-gate * 142*b106467fSJason King * 4. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes 1437c478bd9Sstevel@tonic-gate * a function pointer type for an application callback out of 1447c478bd9Sstevel@tonic-gate * a return type for the callback and a name for the callback. 1457c478bd9Sstevel@tonic-gate * It should be used in the following fashion: 1467c478bd9Sstevel@tonic-gate * 1477c478bd9Sstevel@tonic-gate * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args); 1487c478bd9Sstevel@tonic-gate * 1497c478bd9Sstevel@tonic-gate * to declare a function pointer, myCallback, to a callback 1507c478bd9Sstevel@tonic-gate * which takes arguments args and returns a CK_RV. It can also 1517c478bd9Sstevel@tonic-gate * be used like this: 1527c478bd9Sstevel@tonic-gate * 1537c478bd9Sstevel@tonic-gate * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args); 1547c478bd9Sstevel@tonic-gate * myCallbackType myCallback; 1557c478bd9Sstevel@tonic-gate * 1567c478bd9Sstevel@tonic-gate * If you're using Microsoft Developer Studio 5.0 to do Win32 1577c478bd9Sstevel@tonic-gate * Cryptoki development, it might be defined by: 1587c478bd9Sstevel@tonic-gate * 1597c478bd9Sstevel@tonic-gate * #define CK_CALLBACK_FUNCTION(returnType, name) \ 1607c478bd9Sstevel@tonic-gate * returnType (* name) 1617c478bd9Sstevel@tonic-gate * 1627c478bd9Sstevel@tonic-gate * If you're using an earlier version of Microsoft Developer 1637c478bd9Sstevel@tonic-gate * Studio to do Win16 development, it might be defined by: 1647c478bd9Sstevel@tonic-gate * 1657c478bd9Sstevel@tonic-gate * #define CK_CALLBACK_FUNCTION(returnType, name) \ 1667c478bd9Sstevel@tonic-gate * returnType _far _pascal (* name) 1677c478bd9Sstevel@tonic-gate * 1687c478bd9Sstevel@tonic-gate * In a UNIX environment, it might be defined by: 1697c478bd9Sstevel@tonic-gate * 1707c478bd9Sstevel@tonic-gate * #define CK_CALLBACK_FUNCTION(returnType, name) \ 1717c478bd9Sstevel@tonic-gate * returnType (* name) 1727c478bd9Sstevel@tonic-gate * 1737c478bd9Sstevel@tonic-gate * 174*b106467fSJason King * 5. NULL_PTR: This macro is the value of a NULL pointer. 1757c478bd9Sstevel@tonic-gate * 1767c478bd9Sstevel@tonic-gate * In any ANSI/ISO C environment (and in many others as well), 1777c478bd9Sstevel@tonic-gate * this should best be defined by 1787c478bd9Sstevel@tonic-gate * 1797c478bd9Sstevel@tonic-gate * #ifndef NULL_PTR 1807c478bd9Sstevel@tonic-gate * #define NULL_PTR 0 1817c478bd9Sstevel@tonic-gate * #endif 1827c478bd9Sstevel@tonic-gate */ 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* All the various Cryptoki types and #define'd values are in the 186*b106467fSJason King * file pkcs11t.h. 187*b106467fSJason King */ 1887c478bd9Sstevel@tonic-gate #include "pkcs11t.h" 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate #define __PASTE(x,y) x##y 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate /* ============================================================== 1947c478bd9Sstevel@tonic-gate * Define the "extern" form of all the entry points. 1957c478bd9Sstevel@tonic-gate * ============================================================== 1967c478bd9Sstevel@tonic-gate */ 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate #define CK_NEED_ARG_LIST 1 1997c478bd9Sstevel@tonic-gate #define CK_PKCS11_FUNCTION_INFO(name) \ 2007c478bd9Sstevel@tonic-gate extern CK_DECLARE_FUNCTION(CK_RV, name) 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate /* pkcs11f.h has all the information about the Cryptoki 203*b106467fSJason King * function prototypes. 204*b106467fSJason King */ 2057c478bd9Sstevel@tonic-gate #include "pkcs11f.h" 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate #undef CK_NEED_ARG_LIST 2087c478bd9Sstevel@tonic-gate #undef CK_PKCS11_FUNCTION_INFO 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate /* ============================================================== 2127c478bd9Sstevel@tonic-gate * Define the typedef form of all the entry points. That is, for 2137c478bd9Sstevel@tonic-gate * each Cryptoki function C_XXX, define a type CK_C_XXX which is 2147c478bd9Sstevel@tonic-gate * a pointer to that kind of function. 2157c478bd9Sstevel@tonic-gate * ============================================================== 2167c478bd9Sstevel@tonic-gate */ 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate #define CK_NEED_ARG_LIST 1 2197c478bd9Sstevel@tonic-gate #define CK_PKCS11_FUNCTION_INFO(name) \ 2207c478bd9Sstevel@tonic-gate typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name)) 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate /* pkcs11f.h has all the information about the Cryptoki 223*b106467fSJason King * function prototypes. 224*b106467fSJason King */ 2257c478bd9Sstevel@tonic-gate #include "pkcs11f.h" 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate #undef CK_NEED_ARG_LIST 2287c478bd9Sstevel@tonic-gate #undef CK_PKCS11_FUNCTION_INFO 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate /* ============================================================== 2327c478bd9Sstevel@tonic-gate * Define structed vector of entry points. A CK_FUNCTION_LIST 2337c478bd9Sstevel@tonic-gate * contains a CK_VERSION indicating a library's Cryptoki version 2347c478bd9Sstevel@tonic-gate * and then a whole slew of function pointers to the routines in 2357c478bd9Sstevel@tonic-gate * the library. This type was declared, but not defined, in 2367c478bd9Sstevel@tonic-gate * pkcs11t.h. 2377c478bd9Sstevel@tonic-gate * ============================================================== 2387c478bd9Sstevel@tonic-gate */ 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate #define CK_PKCS11_FUNCTION_INFO(name) \ 2417c478bd9Sstevel@tonic-gate __PASTE(CK_,name) name; 242*b106467fSJason King 2437c478bd9Sstevel@tonic-gate struct CK_FUNCTION_LIST { 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate CK_VERSION version; /* Cryptoki version */ 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* Pile all the function pointers into the CK_FUNCTION_LIST. */ 2487c478bd9Sstevel@tonic-gate /* pkcs11f.h has all the information about the Cryptoki 249*b106467fSJason King * function prototypes. 250*b106467fSJason King */ 2517c478bd9Sstevel@tonic-gate #include "pkcs11f.h" 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate }; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate #undef CK_PKCS11_FUNCTION_INFO 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate #undef __PASTE 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate #endif 2637c478bd9Sstevel@tonic-gate 264*b106467fSJason King #endif /* _PKCS11_H_ */ 265