Hello,
I have a problem using the pkcs11 library. I am working under linux, and using
gcc. I load the libcryptoki.so dynamically.
The problem is the segmentation fault when trying to call the C_Initialize()
Why is this?
my code:
#include stdio.h
#include dlfcn.h
//
// Predefs for PKCS11
//
#pragma pack(push, cryptoki, 1)
#define CK_PTR *
#define CK_DECLARE_FUNCTION(returnType, name) \
returnType name
#define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
returnType (* name)
#define CK_CALLBACK_FUNCTION(returnType, name) \
returnType (* name)
// defs for PKCS11
//
#include pkcs11.h
#pragma pack(pop, cryptoki)
// end PKCS11
CK_FUNCTION_LIST *funcs;
int main() {
printf(Testing...\n);
CK_C_INITIALIZE_ARGS InitArgs;
InitArgs.CreateMutex=0; //CK_CREATEMUTEX
InitArgs.DestroyMutex=0; //CK_DESTROYMUTEX
InitArgs.LockMutex=0;//CK_LOCKMUTEX
InitArgs.UnlockMutex=0; //CK_UNLOCKMUTEX
InitArgs.flags=CKF_OS_LOCKING_OK;//CK_FLAGS
InitArgs.pReserved=0;//CK_C_INITIALIZE_ARGS
CK_RV rv;
CK_RV rc;
CK_C_GetFunctionList pfC_GetFunctionList;
CK_C_Initialize pfC_Initialize;
void *d;
char *e;
char f[]=/cryptokisample/libcryptoki.so;
printf(do_GetFunctionList...\n);
d=dlopen(f,RTLD_LAZY);
if (d == NULL) {
return 1;
}
pfC_GetFunctionList=(CK_C_GetFunctionList)dlsym(d,C_GetFunctionList);
if (pfC_GetFunctionList == NULL) {
return 1;
}
rc = pfC_GetFunctionList(funcs);
if (rc != CKR_OK) {
printf(error in C_GetFunctionList\n);
return 1;
}
printf(C_GetFunctionList OK\n);
pfC_Initialize = funcs-C_Initialize;
if (pfC_Initialize == NULL) {
return 1;
}
printf(C_Initialize found\n);
rv = pfC_Initialize(InitArgs);
if (rv == CKR_OK) {
printf(C_Initialize OK.\n);
}
return 0;
}
I compile using:
gcc test1.cpp -o test1 -L. -lstdc++ -lpthread -ldl
___
mozilla-crypto mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-crypto