#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>
int main(int argc,char *argv[])
{
CK_ULONG ulSlotCount = 0;
CK_ULONG i = 0;
CK_ULONG j = 0;
const unsigned char* pError = NULL;
const unsigned char* pMech = NULL;
int match = 0;
static unsigned char binaryData[] = { 0x55, 0x73, 0xAC, 0x2D, 0x43 };
if (
CKR_OK != (rv = C_Initialize( &initArgs ))) {
printf( "PKCS11 example10: failed C_Initialize (error:%lx)", rv );
return -1;
}
{
printf( "PKCS11 example10: memory allocation failed" );
return -2;
}
if (
CKR_OK == (rv = C_GetSlotList(
CK_FALSE, pSlotList, &ulSlotCount )))
{
for( i=0; i < ulSlotCount; i++ )
{
{
match = strncmp( (const char*)oneSlot.slotDescription, "Futurex Cryptoki Slot #0 ", 64 );
if (0 == match)
{
pEncoded = Futurex_C_FX_HexEncode( pSlotList[i], (
const CK_CHAR_PTR)binaryData, (
CK_LONG)5 );
pDecoded = Futurex_C_FX_HexDecode( pSlotList[i], pEncoded );
for( j=0; j < 5; j++ )
{
if (binaryData[j] != pDecoded[j]) {
printf( "PKCS11 example10: HEX functions did not work as expected" );
}
}
if (NULL != pEncoded) Futurex_C_FX_MemFree( pSlotList[i], pEncoded );
if (NULL != pDecoded) Futurex_C_FX_MemFree( pSlotList[i], pDecoded );
match = -1;
if (NULL != pError) match = strncmp( (const char*)pError, (const char*)"ATTRIBUTE_VALUE_INVALID", 23 );
if (0 != match && NULL != pError) {
printf( "PKCS11 example10: GetErrorString [%s] instead of expected value", pError );
}
match = -1;
if (NULL != pMech) match = strncmp( (const char*)pMech, (const char*)"CKM_RSA_PKCS_KEY_PAIR_GEN", 25 );
if (0 != match && NULL != pError) {
printf( "PKCS11 example10: GetMechanismString [%s] instead of expected value", pMech );
}
if ( NULL != (pMutex = Futurex_C_FX_GenericCreateMutex( pSlotList[i] )))
{
bLocked = Futurex_C_FX_GenericLockMutex( pSlotList[i], pMutex );
if (!bLocked) {
printf( "PKCS11 example10: GenericLockMutex failed" );
}
bUnlocked = Futurex_C_FX_GenericUnlockMutex( pSlotList[i], pMutex );
if (!bUnlocked) {
printf( "PKCS11 example10: GenericUnlockMutex failed" );
}
bFreeLock = Futurex_C_FX_GenericDestroyMutex( pSlotList[i], pMutex );
if (!bFreeLock) {
printf( "PKCS11 example10: GenericDestroyMutex failed" );
}
}
else printf( "PKCS11 example10: GenericCreateMutex failed" );
Futurex_C_FX_SleepMS( pSlotList[i], 5000 );
Futurex_C_FX_ThreadID( pSlotList[i] );
if (
CKR_OK != (rv = Futurex_C_FX_ReloadTokenInfo( pSlotList[i], 0 ))) {
printf( "PKCS11 example10: failed ReloadTokenInfo (error:%lx)", rv );
}
}
}
}
}
}
if (
NULL_PTR != pSlotList) free( pSlotList );
printf( "PKCS11 example10: failed C_Finalize %lx", rv );
return -3;
}
return 0;
}