unit pkcs11;
//-------------------------------------------------------------------
//Coypright (c) 2009,Feitian Technologies Co., Ltd.
//All rights reserved
//Description: Cryptoki function prototypes and variables definition
//Created Time:20090625
//Author:Allen of ITD
//-------------------------------------------------------------------

interface
const
  CKR_OK = 0;
  CKR_DEVICE_ERROR = 48;
  CKR_TOKEN_NOT_PRESENT =342;
  CKR_FUNCTION_FAILED=6;
  
  CKF_RW_SESSION = $2;
  CKF_SERIAL_SESSION = $4;

  CKO_PUBLIC_KEY =$2;
  CKO_PRIVATE_KEY = $3;

  CKA_CLASS = $0;
  CKA_TOKEN =$1;
  CKA_PRIVATE = $2;
  CKA_KEY_TYPE = $100;
  CKA_SUBJECT =  $101;
  CKA_SENSITIVE = $103;
  CKA_ENCRYPT = $104;
  CKA_DECRYPT = $105;
  CKA_WRAP = $106;
  CKA_UNWRAP = $107;
  CKA_MODULUS_BITS = $121;
  CKA_EXTRACTABLE = $162;

  CKK_RSA = $0;

  CKM_RSA_PKCS = $1;

type

  CK_BYTE = byte;
  CK_UTF8CHAR=byte;
  CK_CHAR=byte;
  CK_FLAGS=longint;
  CK_BBOOL=byte;
  CK_ULONG=longword;
  CK_RV=longword;
  CK_SLOT_ID=longword;
  CK_SLOT_ID_PTR=^CK_SLOT_ID;
  CK_ULONG_PTR=^CK_ULONG;
  CK_OBJECT_HANDLE=longword;
  CK_OBJECT_CLASS=longword;
  CK_OBJECT_HANDLE_PTR=^CK_OBJECT_HANDLE;
  CK_SESSION_HANDLE=longword;
  CK_UTF8CHAR_PTR=^CK_UTF8CHAR;
  CK_BYTE_PTR=^CK_BYTE;



  CK_ATTRIBUTE =record
    attrtype:longword;
    pValue:pointer;
    ulValueLen:longword;
  end;

  CK_ATTRIBUTE_PTR=^CK_ATTRIBUTE;

  CK_VERSION = record
    major:CK_BYTE;
    minor:CK_BYTE;
  end;
  CK_SLOT_INFO = record
    slotDescription: array[0..63]of byte;
    manufacturerID: array[0..31] of byte;
    flags:longword;
    hardwareVersion:CK_VERSION;
    firmwareVersion:CK_VERSION;
  end;

  CK_SLOT_INFO_PTR=^CK_SLOT_INFO;
    
  CK_TOKEN_INFO=record
    token_label:array[0..31] of CK_UTF8CHAR;
    manufacturerID:array[0..31] of CK_UTF8CHAR;
    model:array[0..15] of CK_UTF8CHAR;
    serialNumber:array[0..15] of CK_CHAR;
    flags:CK_FLAGS;
    ulMaxSessionCount:CK_ULONG;
    ulSessionCount:CK_ULONG;
    ulMaxRwSessionCount:CK_ULONG;
    ulRwSessionCount:CK_ULONG;
    ulMaxPinLen:CK_ULONG;
    ulMinPinLen:   CK_ULONG;
    ulTotalPublicMemory: CK_ULONG;
    ulFreePublicMemory:CK_ULONG;
    ulTotalPrivateMemory:CK_ULONG ;
    ulFreePrivateMemory:CK_ULONG;
    hardwareVersion:CK_VERSION;
    firmwareVersion:CK_VERSION;
    utcTime:array[0..15] of CK_CHAR;
  end;

  CK_TOKEN_INFO_PTR=^CK_TOKEN_INFO;

    
  CK_INFO=record
    cryptokiVersion:CK_VERSION;                     //Cryptoki interface ver *
    manufacturerID:array[0..31] of CK_UTF8CHAR;     //blank padded
    flags:array[0..3] of char;                      //must be zero
    libraryDescription:array[0..31] of CK_UTF8CHAR; //blank padded
    libraryVersion:CK_VERSION;                      //version of library
  end;
  CK_INFO_PTR=^CK_INFO;

  //CK_MECHANISM is a structure that specifies a particular mechanism
  CK_MECHANISM=record
    mechanism:CK_ULONG;
    pParameter:pointer;
    //ulParameterLen was changed from CK_USHORT to CK_ULONG for v2.0
    ulParameterLen:CK_ULONG;
  end;

  CK_MECHANISM_PTR=^CK_MECHANISM;

  function C_Initialize(pInitArgs: pointer):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_Finalize(pReserved: pointer):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_GetSlotList(tokenPresent: byte; pSlotList :pointer;VAR pulCount:longword):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_GetTokenInfo(slotID: CK_SLOT_ID;  pInfo :CK_TOKEN_INFO_PTR):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_OpenSession(slotID ,flags,pApplication,Notify: longword;VAR phSession:longword):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_CloseSession(phSession:longword):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_Login(phSession:CK_SESSION_HANDLE;userType:longword;pPin:pChar;ulPinLen:longword):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_InitPIN(phSession:CK_SESSION_HANDLE;pPin:pChar;ulPinLen:CK_ULONG):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_FindObjectsInit(phSession:longword;pTemplate: CK_ATTRIBUTE_PTR;ulCount:longword):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_FindObjects(phSession:longword;phObject: CK_OBJECT_HANDLE_PTR;ulMaxObjectCount:longword;pulObjectCount:CK_ULONG_PTR):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_FindObjectsFinal(phSession:longword):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_GetAttributeValue(phSession:longword;hObject:CK_OBJECT_HANDLE;pTemplate: CK_ATTRIBUTE_PTR;ulCount:longword):longword; cdecl; external 'ShuttleCsp11_3003.dll'
  function C_GenerateKeyPair(hSession:CK_SESSION_HANDLE;pMechanism:CK_MECHANISM_PTR;pPublicKeyTemplate:CK_ATTRIBUTE_PTR;ulPublicKeyAttributeCount:CK_ULONG;
                             pPrivateKeyTemplate:CK_ATTRIBUTE_PTR;ulPrivateKeyAttributeCount:CK_ULONG;phPublicKey:CK_OBJECT_HANDLE_PTR;phPrivateKey:CK_OBJECT_HANDLE_PTR):longword;cdecl;external 'ShuttleCsp11_3003.dll'
  function C_SignInit(hSession:CK_SESSION_HANDLE;  pMechanism:CK_MECHANISM_PTR;hKey:CK_OBJECT_HANDLE):longword;cdecl;external 'ShuttleCsp11_3003.dll'
  function C_Sign(hSession:CK_SESSION_HANDLE; pData:CK_BYTE_PTR;ulDataLen:CK_ULONG; pSignature:CK_BYTE_PTR;pulSignatureLen:CK_ULONG_PTR):longword;cdecl;external 'ShuttleCsp11_3003.dll'
  function C_VerifyInit(hSession:CK_SESSION_HANDLE;  pMechanism:CK_MECHANISM_PTR; hKey:CK_OBJECT_HANDLE):longword;cdecl;external 'ShuttleCsp11_3003.dll'
  function C_Verify(hSession:CK_SESSION_HANDLE;  pData:CK_BYTE_PTR;  ulDataLen:CK_ULONG;  pSignature:CK_BYTE_PTR; ulSignatureLen:CK_ULONG):longword;cdecl;external 'ShuttleCsp11_3003.dll'
  function C_EncryptInit(hSession:CK_SESSION_HANDLE; pMechanism:CK_MECHANISM_PTR; hKey:CK_OBJECT_HANDLE):longword;cdecl;external 'ShuttleCsp11_3003.dll'
  function C_Encrypt(hSession:CK_SESSION_HANDLE; pData:CK_BYTE_PTR; ulDataLen:CK_ULONG;
                     pEncryptedData:CK_BYTE_PTR; pulEncryptedDataLen:CK_ULONG_PTR):longword;cdecl;external 'ShuttleCsp11_3003.dll'
  function C_DecryptInit(hSession:CK_SESSION_HANDLE; pMechanism:CK_MECHANISM_PTR; hKey:CK_OBJECT_HANDLE):longword;cdecl;external 'ShuttleCsp11_3003.dll'
  function C_Decrypt(hSession:CK_SESSION_HANDLE; pEncryptedData:CK_BYTE_PTR; ulEncryptedDataLen :CK_ULONG;
                     pData:CK_BYTE_PTR; pulDataLen:CK_ULONG_PTR):longword;cdecl;external 'ShuttleCsp11_3003.dll'


//-----------------------------------------------------------------------


implementation

end.
