Cryptoki: a cryptographic Token Interface


Platform- and compiler-dependent directives for C or C++



Download 360.55 Kb.
Page24/196
Date22.12.2023
Size360.55 Kb.
#63026
1   ...   20   21   22   23   24   25   26   27   ...   196
v201-95
pkcs11-base-v2.40-cos01

7. Platform- and compiler-dependent directives for C or C++


There is a large array of Cryptoki-related data types which are defined in the Cryptoki header files. Certain packing- and pointer-related aspects of these types are platform- and compiler-dependent; these aspects are therefore resolved on a platform-by-platform (or compiler-by-compiler) basis outside of the Cryptoki header files by means of preprocessor directives.
This means that when writing C or C++ code, certain preprocessor directives must be issued before including a Cryptoki header file. These directives are described in the remainder of Section .

7.1. Structure packing


Cryptoki structures are packed to occupy as little space as is possible. In particular, on the Win32 and Win16 platforms, Cryptoki structures should be packed with 1-byte alignment. In a UNIX environment, it may or may not be necessary (or even possible) to alter the byte-alignment of structures.

7.2. Pointer-related macros


Because different platforms and compilers have different ways of dealing with different types of pointers, Cryptoki requires the following 6 macros to be set outside the scope of Cryptoki:
  • CK_PTR


CK_PTR is the “indirection string” a given platform and compiler uses to make a pointer to an object. It is used in the following fashion:
typedef CK_BYTE CK_PTR CK_BYTE_PTR;
  • CK_DEFINE_FUNCTION


CK_DEFINE_FUNCTION(returnType, name), when followed by a parentheses-enclosed list of arguments and a function definition, defines a Cryptoki API function in a Cryptoki library. returnType is the return type of the function, and name is its name. It is used in the following fashion:
CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(
CK_VOID_PTR pReserved
)
{
...
}
  • CK_DECLARE_FUNCTION


CK_DECLARE_FUNCTION(returnType, name), when followed by a parentheses-enclosed list of arguments and a semicolon, declares a Cryptoki API function in a Cryptoki library. returnType is the return type of the function, and name is its name. It is used in the following fashion:
CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
CK_VOID_PTR pReserved
);
1   ...   20   21   22   23   24   25   26   27   ...   196




The database is protected by copyright ©ininet.org 2024
send message

    Main page