Engine for the ICSF backend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
7.3 KiB

  1. /* hw_pkcs11_err.c */
  2. /*
  3. * PKCS#11 engine for the OpenSSL project 2002
  4. * Developped by Bull Trustway R&D Networking & Security
  5. * Introduced and tested with Bull TrustWay CC2000 crypto hardware
  6. * Afchine.Madjlessi@bull.net Bull S.A. France
  7. * http://www.servers.bull.com/trustway
  8. */
  9. #include <stdio.h>
  10. #include <openssl/err.h>
  11. #include "e_pkcs11_err.h"
  12. /* BEGIN ERROR CODES */
  13. #ifndef OPENSSL_NO_ERR
  14. static ERR_STRING_DATA pkcs11_str_functs[]=
  15. {
  16. {ERR_PACK(0,PKCS11_F_INIT,0), "PKCS11_INIT"},
  17. {ERR_PACK(0,PKCS11_F_FINISH,0), "PKCS11_FINISH"},
  18. {ERR_PACK(0,PKCS11_F_DESTROY,0), "PKCS11_DESTROY"},
  19. {ERR_PACK(0,PKCS11_F_CTRL,0), "PKCS11_CTRL"},
  20. {ERR_PACK(0,PKCS11_F_RSA_INIT,0), "PKCS11_RSA_INIT"},
  21. {ERR_PACK(0,PKCS11_F_RSA_FINISH,0), "PKCS11_RSA_FINISH"},
  22. {ERR_PACK(0,PKCS11_F_FINDORCREATEKEY,0),"PKCS11_FINDORCREATEKEY"},
  23. {ERR_PACK(0,PKCS11_F_RSA_GEN_KEY,0), "PKCS11_RSA_GEN_KEY"},
  24. {ERR_PACK(0,PKCS11_F_RSA_PUB_ENC,0), "PKCS11_RSA_PUB_ENC"},
  25. {ERR_PACK(0,PKCS11_F_RSA_PRIV_ENC,0), "PKCS11_RSA_PRIV_ENC"},
  26. {ERR_PACK(0,PKCS11_F_RSA_PUB_DEC,0), "PKCS11_RSA_PUB_DEC"},
  27. {ERR_PACK(0,PKCS11_F_RSA_PRIV_DEC,0), "PKCS11_RSA_PRIV_DEC"},
  28. {ERR_PACK(0,PKCS11_F_RSA_SIGN,0), "PKCS11_RSA_SIGN"},
  29. {ERR_PACK(0,PKCS11_F_RSA_VERIFY,0), "PKCS11_RSA_VERIFY"},
  30. {ERR_PACK(0,PKCS11_F_RAND_ADD,0), "PKCS11_RAND_ADD"},
  31. {ERR_PACK(0,PKCS11_F_RAND_BYTES,0), "PKCS11_RAND_BYTES"},
  32. {ERR_PACK(0,PKCS11_F_GETSESSION,0), "PKCS11_GETSESSION"},
  33. {ERR_PACK(0,PKCS11_F_FREESESSION,0), "PKCS11_FREESESSION"},
  34. {ERR_PACK(0,PKCS11_F_INITKEY,0), "PKCS11_INITKEY"},
  35. {ERR_PACK(0,PKCS11_F_DIGESTINIT,0), "PKCS11_DIGESTINIT"},
  36. {ERR_PACK(0,PKCS11_F_DIGESTUPDATE,0), "PKCS11_DIGESTUPDATE"},
  37. {ERR_PACK(0,PKCS11_F_DIGESTFINISH,0), "PKCS11_DIGESTFINISH"},
  38. {ERR_PACK(0,PKCS11_F_CIPHER_UPDATE,0), "PKCS11_CIPHER_UPDATE"},
  39. {ERR_PACK(0,PKCS11_F_PREINIT,0), "PKCS11_PREINIT"},
  40. {ERR_PACK(0,PKCS11_F_ADDTOKEN,0), "PKCS11_ADDTOKEN"},
  41. {ERR_PACK(0,PKCS11_F_LOAD_PRIVKEY,0), "PKCS11_LOAD_PRIVKEY"},
  42. {ERR_PACK(0,PKCS11_F_LOAD_PUBKEY,0), "PKCS11_LOAD_PUBKEY"},
  43. {ERR_PACK(0,PKCS11_F_DIGESTCOPY,0), "PKCS11_DIGESTCOPY"},
  44. {ERR_PACK(0,PKCS11_F_GET_PKCS11_CIPHERS,0), "PKCS11_GET_PKCS11_CIPHERS"},
  45. {ERR_PACK(0,PKCS11_F_GET_PKCS11_DIGESTS,0), "PKCS11_GET_PKCS11_DIGESTS"},
  46. {ERR_PACK(0,PKCS11_F_ENGINE_CIPHERS,0), "PKCS11_ENGINE_CIPHERS"},
  47. {ERR_PACK(0,PKCS11_F_ENGINE_DIGESTS,0), "PKCS11_ENGINE_DIGESTS"},
  48. {0,NULL}
  49. };
  50. static ERR_STRING_DATA pkcs11_str_reasons[]=
  51. {
  52. {PKCS11_R_ALREADY_LOADED ,"PKCS#11 DSO already loaded"},
  53. {PKCS11_R_DSO_FAILURE ,"unable to load PKCS#11 DSO"},
  54. {PKCS11_R_NOT_LOADED ,"PKCS#11 DSO not loaded"},
  55. {PKCS11_R_PASSED_NULL_PARAMETER ,"null parameter passed"},
  56. {PKCS11_R_COMMAND_NOT_IMPLEMENTED ,"command not implemented"},
  57. {PKCS11_R_INITIALIZE ,"C_Initialize failed"},
  58. {PKCS11_R_FINALIZE ,"C_Finalize failed"},
  59. {PKCS11_R_GETINFO ,"C_GetInfo faile"},
  60. {PKCS11_R_GETSLOTLIST ,"C_GetSlotList failed"},
  61. {PKCS11_R_NO_MODULUS_OR_NO_EXPONENT ,"no modulus or no exponent"},
  62. {PKCS11_R_ATTRIBUT_SENSITIVE_OR_INVALID ,"attrribute sensitive or invalid "},
  63. {PKCS11_R_GETATTRIBUTVALUE ,"C_GetAttributeValue failed"},
  64. {PKCS11_R_NO_MODULUS ,"no modulus"},
  65. {PKCS11_R_NO_EXPONENT ,"no exponent"},
  66. {PKCS11_R_FINDOBJECTSINIT ,"C_FindObjectsInit failed"},
  67. {PKCS11_R_FINDOBJECTS ,"C_FindObjects failed"},
  68. {PKCS11_R_FINDOBJECTSFINAL ,"C_FindObjectsFinal failed"},
  69. {PKCS11_R_OBJECT_NOT_FOUND ,"object not found"},
  70. {PKCS11_R_CREATEOBJECT ,"C_CreateObject failed"},
  71. {PKCS11_R_DESTROYOBJECT ,"C_DestroyObject failed"},
  72. {PKCS11_R_OPENSESSION ,"C_OpenSession failed"},
  73. {PKCS11_R_CLOSESESSION ,"C_CloseSession failed"},
  74. {PKCS11_R_ENCRYPTINIT ,"C_EncryptInit failed"},
  75. {PKCS11_R_ENCRYPT ,"C_Encrypt failed"},
  76. {PKCS11_R_SIGNINIT ,"C_SignInit failed"},
  77. {PKCS11_R_SIGN ,"C_Sign failed"},
  78. {PKCS11_R_DECRYPTINIT ,"C_DecryptInit failed"},
  79. {PKCS11_R_DECRYPT ,"C_Decrypt failed"},
  80. {PKCS11_R_VERIFYINIT ,"C_VerifyRecover failed"},
  81. {PKCS11_R_VERIFY ,"C_Verify failed "},
  82. {PKCS11_R_VERIFYRECOVERINIT ,"C_VerifyRecoverInit failed"},
  83. {PKCS11_R_VERIFYRECOVER ,"C_VerifyRecover failed"},
  84. {PKCS11_R_GEN_KEY ,"C_GenerateKeyPair failed"},
  85. {PKCS11_R_SEEDRANDOM ,"C_SeedRandom failed"},
  86. {PKCS11_R_GENERATERANDOM ,"C_GenerateRandom failed"},
  87. {PKCS11_R_INVALID_MESSAGE_LENGTH ,"invalid message length"},
  88. {PKCS11_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
  89. {PKCS11_R_UNKNOWN_ASN1_OBJECT_ID ,"unknown asn1 onject id"},
  90. {PKCS11_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"},
  91. {PKCS11_R_DIGEST_TOO_BIG ,"digest too big"},
  92. {PKCS11_R_MALLOC_FAILURE ,"malloc failure"},
  93. {PKCS11_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"control command not implemented"},
  94. {PKCS11_R_GETSLOTINFO ,"C_GetSlotInfo failed"},
  95. {PKCS11_R_GETMECHANISMLIST ,"C_GetMechanismList failed"},
  96. {PKCS11_R_GETMECHANISMINFO ,"C_GetMechanismInfo failed"},
  97. {PKCS11_R_BADMECHANISM ,"bad mechanism"},
  98. {PKCS11_R_DIGESTINIT ,"C_DigestInit failed"},
  99. {PKCS11_R_DIGESTUPDATE ,"C_DigestUpdate failed"},
  100. {PKCS11_R_DIGESTFINAL ,"C_DigestFinal failed"},
  101. {PKCS11_R_NOTOKENS ,"no hardware tokens found"},
  102. {PKCS11_R_NOTOKENFORALGORITHM ,"no tokens available to accelerate algorithm"},
  103. {PKCS11_R_DIGEST ,"C_Digest failed"},
  104. {PKCS11_R_TOKEN_NOT_AVAILABLE ,"Token in requested slot is not available"},
  105. {PKCS11_R_NO_SLOT_SELECTED ,"No slot selected, please add SLOT_ID=<num> to your"
  106. " openssl.cnf ibmpkcs11_section"},
  107. {0,NULL}
  108. };
  109. #endif
  110. static int pkcs11_lib_error_code=0;
  111. static int pkcs11_error_init=1;
  112. void ERR_load_pkcs11_strings(void)
  113. {
  114. if (pkcs11_lib_error_code == 0)
  115. pkcs11_lib_error_code = ERR_get_next_error_library();
  116. if (pkcs11_error_init)
  117. {
  118. pkcs11_error_init=0;
  119. #ifndef OPENSSL_NO_ERR
  120. ERR_load_strings(pkcs11_lib_error_code,pkcs11_str_functs);
  121. ERR_load_strings(pkcs11_lib_error_code,pkcs11_str_reasons);
  122. #endif
  123. }
  124. }
  125. void ERR_unload_pkcs11_strings(void)
  126. {
  127. if (pkcs11_error_init == 0)
  128. {
  129. #ifndef OPENSSL_NO_ERR
  130. ERR_unload_strings(pkcs11_lib_error_code,pkcs11_str_functs);
  131. ERR_unload_strings(pkcs11_lib_error_code,pkcs11_str_reasons);
  132. #endif
  133. pkcs11_error_init = 1;
  134. }
  135. }
  136. void ERR_pkcs11_error(int function, int reason, char *file, int line)
  137. {
  138. if (pkcs11_lib_error_code == 0)
  139. pkcs11_lib_error_code=ERR_get_next_error_library();
  140. ERR_PUT_error(pkcs11_lib_error_code,function,reason,file,line);
  141. //ERR_print_errors_fp(stderr);
  142. }