⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 api_interface.c

📁 IBM的Linux上的PKCS#11实现
💻 C
📖 第 1 页 / 共 5 页
字号:
   CK_RV   rv;   API_Slot_t  *sltp;   STDLL_FcnList_t  *fcn;   CK_SLOT_ID        slotID;   Session_Struct_t   *sessp;   ST_SESSION_T rSession;   LOG("C_Encrypt");   if (API_Initialized() == FALSE ){      st_err_log(72, __FILE__, __LINE__);      return CKR_CRYPTOKI_NOT_INITIALIZED;   }   if (!pData || !pulEncryptedDataLen){      st_err_log(5, __FILE__, __LINE__, __FUNCTION__);       return CKR_ARGUMENTS_BAD;   }   // Validate Session   if (!Valid_Session((Session_Struct_t *)hSession,&rSession)){      st_err_log(40, __FILE__, __LINE__);      return CKR_SESSION_HANDLE_INVALID;   }   // Get local pointers to session   slotID = rSession.slotID;   sltp = &(Anchor->SltList[slotID]);   if (sltp->DLLoaded == FALSE ){      st_err_log(50, __FILE__, __LINE__);             return CKR_TOKEN_NOT_PRESENT;   }   if ( (fcn=sltp->FcnList) == NULL ){      st_err_log(50, __FILE__, __LINE__);       return CKR_TOKEN_NOT_PRESENT;   }   if (fcn->ST_Encrypt){      // Map the Session to the slot session      rv = fcn->ST_Encrypt(rSession,pData,ulDataLen,pEncryptedData,pulEncryptedDataLen);      LOGIT(LOG_DEBUG,"Called STDLL rv = 0x%x",rv);   } else {      st_err_log(142, __FILE__, __LINE__, __FUNCTION__);       rv = CKR_FUNCTION_NOT_SUPPORTED;   }   return rv;}//------------------------------------------------------------------------// API function C_EncryptFinal   //------------------------------------------------------------------------CK_RV CK_ENTRY C_EncryptFinal ( CK_SESSION_HANDLE hSession,                       CK_BYTE_PTR       pLastEncryptedPart,                       CK_ULONG_PTR      pulLastEncryptedPartLen                     ){   CK_RV   rv;   API_Slot_t  *sltp;   STDLL_FcnList_t  *fcn;   CK_SLOT_ID        slotID;   Session_Struct_t   *sessp;   ST_SESSION_T rSession;   LOG("C_EncryptFinal");   if (API_Initialized() == FALSE ){      st_err_log(72, __FILE__, __LINE__);      return CKR_CRYPTOKI_NOT_INITIALIZED;   }   // See comments for DecryptFinal   if ( !pulLastEncryptedPartLen){      st_err_log(5, __FILE__, __LINE__, __FUNCTION__);       return CKR_ARGUMENTS_BAD;   }   // Validate Session   if (!Valid_Session((Session_Struct_t *)hSession,&rSession)){      st_err_log(40, __FILE__, __LINE__);      return CKR_SESSION_HANDLE_INVALID;   }   // Get local pointers to session   slotID = rSession.slotID;   sltp = &(Anchor->SltList[slotID]);   if (sltp->DLLoaded == FALSE ){      st_err_log(50, __FILE__, __LINE__);             return CKR_TOKEN_NOT_PRESENT;   }   if ( (fcn=sltp->FcnList) == NULL ){      st_err_log(50, __FILE__, __LINE__);       return CKR_TOKEN_NOT_PRESENT;   }   if (fcn->ST_EncryptFinal){      // Map the Session to the slot session      rv = fcn->ST_EncryptFinal(rSession,pLastEncryptedPart,pulLastEncryptedPartLen);      LOGIT(LOG_DEBUG,"Called STDLL rv = 0x%x",rv);   } else {      st_err_log(142, __FILE__, __LINE__, __FUNCTION__);       rv = CKR_FUNCTION_NOT_SUPPORTED;   }   return rv;}//------------------------------------------------------------------------// API function C_EncryptInit   //------------------------------------------------------------------------CK_RV CK_ENTRY C_EncryptInit ( CK_SESSION_HANDLE hSession,                      CK_MECHANISM_PTR  pMechanism,                      CK_OBJECT_HANDLE  hKey                    ){   CK_RV   rv;   API_Slot_t  *sltp;   STDLL_FcnList_t  *fcn;   CK_SLOT_ID        slotID;   Session_Struct_t   *sessp;   ST_SESSION_T rSession;   LOG("C_EncryptInit");   if (API_Initialized() == FALSE ){      st_err_log(72, __FILE__, __LINE__);      return CKR_CRYPTOKI_NOT_INITIALIZED;   }   if (!pMechanism){      st_err_log(28, __FILE__, __LINE__);       return CKR_MECHANISM_INVALID;   }   // Validate Session   if (!Valid_Session((Session_Struct_t *)hSession,&rSession)){      st_err_log(40, __FILE__, __LINE__);      return CKR_SESSION_HANDLE_INVALID;   }   // Get local pointers to session   slotID = rSession.slotID;   sltp = &(Anchor->SltList[slotID]);   if (sltp->DLLoaded == FALSE ){      st_err_log(50, __FILE__, __LINE__);             return CKR_TOKEN_NOT_PRESENT;   }   if ( (fcn=sltp->FcnList) == NULL ){      st_err_log(50, __FILE__, __LINE__);       return CKR_TOKEN_NOT_PRESENT;   }   if (fcn->ST_EncryptInit){      // Map the Session to the slot session      rv = fcn->ST_EncryptInit(rSession,pMechanism,hKey);      LOGIT(LOG_DEBUG,"Called STDLL rv = 0x%x",rv);   } else {      st_err_log(142, __FILE__, __LINE__, __FUNCTION__);       rv = CKR_FUNCTION_NOT_SUPPORTED;   }   return rv;      st_err_log(142, __FILE__, __LINE__, __FUNCTION__);    return CKR_FUNCTION_NOT_SUPPORTED;}//------------------------------------------------------------------------// API function C_EncryptUpdate  //------------------------------------------------------------------------CK_RV CK_ENTRY C_EncryptUpdate ( CK_SESSION_HANDLE hSession,                        CK_BYTE_PTR       pPart,                        CK_ULONG          ulPartLen,                        CK_BYTE_PTR       pEncryptedPart,                        CK_ULONG_PTR      pulEncryptedPartLen                      ){   CK_RV   rv;   API_Slot_t  *sltp;   STDLL_FcnList_t  *fcn;   CK_SLOT_ID        slotID;   Session_Struct_t   *sessp;   ST_SESSION_T rSession;   LOG("C_EncryptUpdate");   if (API_Initialized() == FALSE ){      st_err_log(72, __FILE__, __LINE__);      return CKR_CRYPTOKI_NOT_INITIALIZED;   }   if (!pPart || !pulEncryptedPartLen){      st_err_log(5, __FILE__, __LINE__, __FUNCTION__);       return CKR_ARGUMENTS_BAD;   }   // Validate Session   if (!Valid_Session((Session_Struct_t *)hSession,&rSession)){      st_err_log(40, __FILE__, __LINE__);      return CKR_SESSION_HANDLE_INVALID;   }   // Get local pointers to session   slotID = rSession.slotID;   sltp = &(Anchor->SltList[slotID]);   if (sltp->DLLoaded == FALSE ){      st_err_log(50, __FILE__, __LINE__);             return CKR_TOKEN_NOT_PRESENT;   }   if ( (fcn=sltp->FcnList) == NULL ){      st_err_log(50, __FILE__, __LINE__);       return CKR_TOKEN_NOT_PRESENT;   }   if (fcn->ST_EncryptUpdate){      // Map the Session to the slot session      rv = fcn->ST_EncryptUpdate(rSession,pPart,ulPartLen,pEncryptedPart,pulEncryptedPartLen);      LOGIT(LOG_DEBUG,"Called STDLL rv = 0x%x",rv);   } else {      st_err_log(142, __FILE__, __LINE__, __FUNCTION__);       rv = CKR_FUNCTION_NOT_SUPPORTED;   }   return rv;}//------------------------------------------------------------------------// API function C_Finalize//------------------------------------------------------------------------//  Netscape Required////////------------------------------------------------------------------------CK_RV CK_ENTRY C_Finalize ( CK_VOID_PTR pReserved ){   API_Slot_t *sltp;   CK_SLOT_ID slotID;   LOG("C_Finalize");   if (API_Initialized() == FALSE ){      st_err_log(72, __FILE__, __LINE__);      return CKR_CRYPTOKI_NOT_INITIALIZED;   }   if (pReserved != NULL) {      st_err_log(5, __FILE__, __LINE__, __FUNCTION__);       return CKR_ARGUMENTS_BAD;   }   pthread_mutex_lock(&GlobMutex); // Grab Process level Global MUTEX   Terminate_All_Process_Sessions();// Terminate the sessions    // unload all the STDLL's from the application   // This is in case the APP decides to do the re-initialize and   // continue on   // //   for (slotID=0;slotID<NUMBER_SLOTS_MANAGED;slotID++){      sltp = &(Anchor->SltList[slotID]);      if (sltp->pSTcloseall) {         sltp->pSTcloseall(slotID);  // call the terminate function..      }      if (sltp->pSTfini){         sltp->pSTfini(slotID);  // call the terminate function..      }      DL_UnLoad(sltp,slotID);   }   // Un register from Slot D   API_UnRegister();     detach_shared_memory(Anchor->SharedMemP);   free(Anchor); // Free API Proc Struct   Anchor = NULL;   // Unlock    pthread_mutex_unlock(&GlobMutex);   return CKR_OK;} // end of C_Finalize//------------------------------------------------------------------------// API function C_FindObjects//------------------------------------------------------------------------//  Netscape Required////////------------------------------------------------------------------------CK_RV CK_ENTRY C_FindObjects ( CK_SESSION_HANDLE    hSession,                               CK_OBJECT_HANDLE_PTR phObject,                               CK_ULONG             ulMaxObjectCount,                               CK_ULONG_PTR         pulObjectCount ){   CK_RV   rv;   API_Slot_t  *sltp;   STDLL_FcnList_t  *fcn;   CK_SLOT_ID        slotID;   Session_Struct_t   *sessp;   ST_SESSION_T rSession;   LOG("C_FindObjects");   if (API_Initialized() == FALSE ){      st_err_log(72, __FILE__, __LINE__);      return CKR_CRYPTOKI_NOT_INITIALIZED;   }      if (!phObject || !pulObjectCount ){      st_err_log(5, __FILE__, __LINE__, __FUNCTION__);       return CKR_ARGUMENTS_BAD;   }   // Validate Session   if (!Valid_Session((Session_Struct_t *)hSession,&rSession)){      st_err_log(40, __FILE__, __LINE__);      return CKR_SESSION_HANDLE_INVALID;   }   // Get local pointers to session   slotID = rSession.slotID;   sltp = &(Anchor->SltList[slotID]);   if (sltp->DLLoaded == FALSE ){      st_err_log(50, __FILE__, __LINE__);             return CKR_TOKEN_NOT_PRESENT;   }   if ( (fcn=sltp->FcnList) == NULL ){      st_err_log(50, __FILE__, __LINE__);       return CKR_TOKEN_NOT_PRESENT;   }   if (fcn->ST_FindObjects){      // Map the Session to the slot session      rv = fcn->ST_FindObjects(rSession,phObject,ulMaxObjectCount,pulObjectCount);      LOGIT(LOG_DEBUG,"Called STDLL rv = 0x%x",rv);   } else {      st_err_log(142, __FILE__, __LINE__, __FUNCTION__);       rv = CKR_FUNCTION_NOT_SUPPORTED;   }   return rv;} // end of C_FindObjects//------------------------------------------------------------------------// API function C_FindObjectsFinal//------------------------------------------------------------------------//  Netscape Required////////------------------------------------------------------------------------CK_RV CK_ENTRY C_FindObjectsFinal ( CK_SESSION_HANDLE hSession ){   CK_RV   rv;   API_Slot_t  *sltp;   STDLL_FcnList_t  *fcn;   CK_SLOT_ID        slotID;   Session_Struct_t   *sessp;   ST_SESSION_T rSession;   LOG("C_FindObjectsFinal");   if (API_Initialized() == FALSE ){      st_err_log(72, __FILE__, __LINE__);      return CKR_CRYPTOKI_NOT_INITIALIZED;   }   // Validate Session   if (!Valid_Session((Session_Struct_t *)hSession,&rSession)){      st_err_log(40, __FILE__, __LINE__);      return CKR_SESSION_HANDLE_INVALID;   }   // Get local pointers to session   slotID = rSession.slotID;   sltp = &(Anchor->SltList[slotID]);   if (sltp->DLLoaded == FALSE ){      st_err_log(50, __FILE__, __LINE__);             return CKR_TOKEN_NOT_PRESENT;   }   if ( (fcn=sltp->FcnList) == NULL ){      st_err_log(50, __FILE__, __LINE__);       return CKR_TOKEN_NOT_PRESENT;   }   if

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -