Using Cryptographic Hardware

CK_RV rv;

CK_SESSION_HANDLE sessionHandle;

HINSTANCE libHandle;

GetFunctionList GetList;

CK_FUNCTION_LIST_PTR fnctList;

/* Load the library if possible. */

libHandle = LoadLibrary (p11Info->session.libraryName); if (libHandle == (HINSTANCE)NULL_PTR)

return (BE_HARDWARE);

/* Get the PKCS 11 function C_GetFunctionList. With this function, we can get the function list (pointers to all PKCS 11 functions) with one call.

*/

GetList = (GetFunctionList)GetProcAddress (libHandle, "C_GetFunctionList");

if (GetList == (GetFunctionList)0) return (BE_HARDWARE);

if ((rv = GetList (&fnctList)) != 0) return (BE_HARDWARE);

/* We have to initialize PKCS 11. */

if ((rv = fnctList->C_Initialize ((CK_VOID_PTR)NULL_PTR)) != 0)

return (BE_HARDWARE);

/* Now we need to open a session and log in. */ if ((rv = fnctList->C_OpenSession

((CK_SLOT_ID)(session->slotID),

CKF_RW_SESSION CKF_SERIAL_SESSION, (CK_VOID_PTR)&(p11Info->surrenderCtx), (CK_NOTIFY)HI_PKCS11Notify, &sessionHandle)) != 0)

return (BE_HARDWARE);

if ((rv = fnctList->C_Login (sessionHandle, CKU_USER,

(CK_CHAR_PTR)(session->passPhrase.data), (CK_ULONG)(session->passPhrase.len))) != 0)

return (BE_HARDWARE);

C h a p t e r 4 U s i n g C r y p t o - C

1 4 3

Page 165
Image 165
RSA Security 5.2.2 manual Return Behardware