error.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /* error.c
  2. *
  3. * Copyright (C) 2006-2019 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #include <wolfssl/wolfcrypt/error-crypt.h>
  26. #ifdef _MSC_VER
  27. /* 4996 warning to use MS extensions e.g., strcpy_s instead of XSTRNCPY */
  28. #pragma warning(disable: 4996)
  29. #endif
  30. #ifndef NO_ERROR_STRINGS
  31. const char* wc_GetErrorString(int error)
  32. {
  33. switch (error) {
  34. case OPEN_RAN_E :
  35. return "opening random device error";
  36. case READ_RAN_E :
  37. return "reading random device error";
  38. case WINCRYPT_E :
  39. return "windows crypt init error";
  40. case CRYPTGEN_E :
  41. return "windows crypt generation error";
  42. case RAN_BLOCK_E :
  43. return "random device read would block error";
  44. case BAD_MUTEX_E :
  45. return "Bad mutex, operation failed";
  46. case WC_TIMEOUT_E:
  47. return "Timeout error";
  48. case WC_PENDING_E:
  49. return "wolfCrypt Operation Pending (would block / eagain) error";
  50. case WC_NOT_PENDING_E:
  51. return "wolfCrypt operation not pending error";
  52. case MP_INIT_E :
  53. return "mp_init error state";
  54. case MP_READ_E :
  55. return "mp_read error state";
  56. case MP_EXPTMOD_E :
  57. return "mp_exptmod error state";
  58. case MP_TO_E :
  59. return "mp_to_xxx error state, can't convert";
  60. case MP_SUB_E :
  61. return "mp_sub error state, can't subtract";
  62. case MP_ADD_E :
  63. return "mp_add error state, can't add";
  64. case MP_MUL_E :
  65. return "mp_mul error state, can't multiply";
  66. case MP_MULMOD_E :
  67. return "mp_mulmod error state, can't multiply mod";
  68. case MP_MOD_E :
  69. return "mp_mod error state, can't mod";
  70. case MP_INVMOD_E :
  71. return "mp_invmod error state, can't inv mod";
  72. case MP_CMP_E :
  73. return "mp_cmp error state";
  74. case MP_ZERO_E :
  75. return "mp zero result, not expected";
  76. case MEMORY_E :
  77. return "out of memory error";
  78. case VAR_STATE_CHANGE_E :
  79. return "Variable state modified by different thread";
  80. case RSA_WRONG_TYPE_E :
  81. return "RSA wrong block type for RSA function";
  82. case RSA_BUFFER_E :
  83. return "RSA buffer error, output too small or input too big";
  84. case BUFFER_E :
  85. return "Buffer error, output too small or input too big";
  86. case ALGO_ID_E :
  87. return "Setting Cert AlgoID error";
  88. case PUBLIC_KEY_E :
  89. return "Setting Cert Public Key error";
  90. case DATE_E :
  91. return "Setting Cert Date validity error";
  92. case SUBJECT_E :
  93. return "Setting Cert Subject name error";
  94. case ISSUER_E :
  95. return "Setting Cert Issuer name error";
  96. case CA_TRUE_E :
  97. return "Setting basic constraint CA true error";
  98. case EXTENSIONS_E :
  99. return "Setting extensions error";
  100. case ASN_PARSE_E :
  101. return "ASN parsing error, invalid input";
  102. case ASN_VERSION_E :
  103. return "ASN version error, invalid number";
  104. case ASN_GETINT_E :
  105. return "ASN get big int error, invalid data";
  106. case ASN_RSA_KEY_E :
  107. return "ASN key init error, invalid input";
  108. case ASN_OBJECT_ID_E :
  109. return "ASN object id error, invalid id";
  110. case ASN_TAG_NULL_E :
  111. return "ASN tag error, not null";
  112. case ASN_EXPECT_0_E :
  113. return "ASN expect error, not zero";
  114. case ASN_BITSTR_E :
  115. return "ASN bit string error, wrong id";
  116. case ASN_UNKNOWN_OID_E :
  117. return "ASN oid error, unknown sum id";
  118. case ASN_DATE_SZ_E :
  119. return "ASN date error, bad size";
  120. case ASN_BEFORE_DATE_E :
  121. return "ASN date error, current date before";
  122. case ASN_AFTER_DATE_E :
  123. return "ASN date error, current date after";
  124. case ASN_SIG_OID_E :
  125. return "ASN signature error, mismatched oid";
  126. case ASN_TIME_E :
  127. return "ASN time error, unknown time type";
  128. case ASN_INPUT_E :
  129. return "ASN input error, not enough data";
  130. case ASN_SIG_CONFIRM_E :
  131. return "ASN sig error, confirm failure";
  132. case ASN_SIG_HASH_E :
  133. return "ASN sig error, unsupported hash type";
  134. case ASN_SIG_KEY_E :
  135. return "ASN sig error, unsupported key type";
  136. case ASN_DH_KEY_E :
  137. return "ASN key init error, invalid input";
  138. case ASN_NTRU_KEY_E :
  139. return "ASN NTRU key decode error, invalid input";
  140. case ASN_CRIT_EXT_E:
  141. return "X.509 Critical extension ignored or invalid";
  142. case ASN_ALT_NAME_E:
  143. return "ASN alternate name error";
  144. case ECC_BAD_ARG_E :
  145. return "ECC input argument wrong type, invalid input";
  146. case ASN_ECC_KEY_E :
  147. return "ECC ASN1 bad key data, invalid input";
  148. case ECC_CURVE_OID_E :
  149. return "ECC curve sum OID unsupported, invalid input";
  150. case BAD_FUNC_ARG :
  151. return "Bad function argument";
  152. case NOT_COMPILED_IN :
  153. return "Feature not compiled in";
  154. case UNICODE_SIZE_E :
  155. return "Unicode password too big";
  156. case NO_PASSWORD :
  157. return "No password provided by user";
  158. case ALT_NAME_E :
  159. return "Alt Name problem, too big";
  160. case AES_GCM_AUTH_E:
  161. return "AES-GCM Authentication check fail";
  162. case AES_CCM_AUTH_E:
  163. return "AES-CCM Authentication check fail";
  164. case ASYNC_INIT_E:
  165. return "Async Init error";
  166. case COMPRESS_INIT_E:
  167. return "Compress Init error";
  168. case COMPRESS_E:
  169. return "Compress error";
  170. case DECOMPRESS_INIT_E:
  171. return "DeCompress Init error";
  172. case DECOMPRESS_E:
  173. return "DeCompress error";
  174. case BAD_ALIGN_E:
  175. return "Bad alignment error, no alloc help";
  176. case ASN_NO_SIGNER_E :
  177. return "ASN no signer error to confirm failure";
  178. case ASN_CRL_CONFIRM_E :
  179. return "ASN CRL sig error, confirm failure";
  180. case ASN_CRL_NO_SIGNER_E :
  181. return "ASN CRL no signer error to confirm failure";
  182. case ASN_OCSP_CONFIRM_E :
  183. return "ASN OCSP sig error, confirm failure";
  184. case ASN_NO_PEM_HEADER:
  185. return "ASN no PEM Header Error";
  186. case BAD_STATE_E:
  187. return "Bad state operation";
  188. case BAD_PADDING_E:
  189. return "Bad padding, message wrong length";
  190. case REQ_ATTRIBUTE_E:
  191. return "Setting cert request attributes error";
  192. case PKCS7_OID_E:
  193. return "PKCS#7 error: mismatched OID value";
  194. case PKCS7_RECIP_E:
  195. return "PKCS#7 error: no matching recipient found";
  196. case WC_PKCS7_WANT_READ_E:
  197. return "PKCS#7 operations wants more input, call again";
  198. case FIPS_NOT_ALLOWED_E:
  199. return "FIPS mode not allowed error";
  200. case ASN_NAME_INVALID_E:
  201. return "Name Constraint error";
  202. case RNG_FAILURE_E:
  203. return "Random Number Generator failed";
  204. case HMAC_MIN_KEYLEN_E:
  205. return "FIPS Mode HMAC Minimum Key Length error";
  206. case RSA_PAD_E:
  207. return "Rsa Padding error";
  208. case LENGTH_ONLY_E:
  209. return "Output length only set, not for other use error";
  210. case IN_CORE_FIPS_E:
  211. return "In Core Integrity check FIPS error";
  212. case AES_KAT_FIPS_E:
  213. return "AES Known Answer Test check FIPS error";
  214. case DES3_KAT_FIPS_E:
  215. return "DES3 Known Answer Test check FIPS error";
  216. case HMAC_KAT_FIPS_E:
  217. return "HMAC Known Answer Test check FIPS error";
  218. case RSA_KAT_FIPS_E:
  219. return "RSA Known Answer Test check FIPS error";
  220. case DRBG_KAT_FIPS_E:
  221. return "DRBG Known Answer Test check FIPS error";
  222. case DRBG_CONT_FIPS_E:
  223. return "DRBG Continuous Test FIPS error";
  224. case AESGCM_KAT_FIPS_E:
  225. return "AESGCM Known Answer Test check FIPS error";
  226. case THREAD_STORE_KEY_E:
  227. return "Thread Storage Key Create error";
  228. case THREAD_STORE_SET_E:
  229. return "Thread Storage Set error";
  230. case MAC_CMP_FAILED_E:
  231. return "MAC comparison failed";
  232. case IS_POINT_E:
  233. return "ECC is point on curve failed";
  234. case ECC_INF_E:
  235. return " ECC point at infinity error";
  236. case ECC_OUT_OF_RANGE_E:
  237. return " ECC Qx or Qy out of range error";
  238. case ECC_PRIV_KEY_E:
  239. return " ECC private key is not valid error";
  240. case SRP_CALL_ORDER_E:
  241. return "SRP function called in the wrong order error";
  242. case SRP_VERIFY_E:
  243. return "SRP proof verification error";
  244. case SRP_BAD_KEY_E:
  245. return "SRP bad key values error";
  246. case ASN_NO_SKID:
  247. return "ASN no Subject Key Identifier found error";
  248. case ASN_NO_AKID:
  249. return "ASN no Authority Key Identifier found error";
  250. case ASN_NO_KEYUSAGE:
  251. return "ASN no Key Usage found error";
  252. case SKID_E:
  253. return "Setting Subject Key Identifier error";
  254. case AKID_E:
  255. return "Setting Authority Key Identifier error";
  256. case KEYUSAGE_E:
  257. return "Key Usage value error";
  258. case EXTKEYUSAGE_E:
  259. return "Extended Key Usage value error";
  260. case CERTPOLICIES_E:
  261. return "Setting Certificate Policies error";
  262. case WC_INIT_E:
  263. return "wolfCrypt Initialize Failure error";
  264. case SIG_VERIFY_E:
  265. return "Signature verify error";
  266. case BAD_COND_E:
  267. return "Bad condition variable operation error";
  268. case SIG_TYPE_E:
  269. return "Signature type not enabled/available";
  270. case HASH_TYPE_E:
  271. return "Hash type not enabled/available";
  272. case WC_KEY_SIZE_E:
  273. return "Key size error, either too small or large";
  274. case ASN_COUNTRY_SIZE_E:
  275. return "Country code size error, either too small or large";
  276. case MISSING_RNG_E:
  277. return "RNG required but not provided";
  278. case ASN_PATHLEN_SIZE_E:
  279. return "ASN CA path length value too large error";
  280. case ASN_PATHLEN_INV_E:
  281. return "ASN CA path length larger than signer error";
  282. case BAD_KEYWRAP_ALG_E:
  283. return "Unsupported key wrap algorithm error";
  284. case BAD_KEYWRAP_IV_E:
  285. return "Decrypted AES key wrap IV does not match expected";
  286. case WC_CLEANUP_E:
  287. return "wolfcrypt cleanup failed";
  288. case ECC_CDH_KAT_FIPS_E:
  289. return "wolfcrypt FIPS ECC CDH Known Answer Test Failure";
  290. case DH_CHECK_PUB_E:
  291. return "DH Check Public Key failure";
  292. case BAD_PATH_ERROR:
  293. return "Bad path for opendir error";
  294. case ASYNC_OP_E:
  295. return "Async operation error";
  296. case BAD_OCSP_RESPONDER:
  297. return "Invalid OCSP Responder, missing specific key usage extensions";
  298. case ECC_PRIVATEONLY_E:
  299. return "Invalid use of private only ECC key";
  300. case WC_HW_E:
  301. return "Error with hardware crypto use";
  302. case WC_HW_WAIT_E:
  303. return "Hardware waiting on resource";
  304. case PSS_SALTLEN_E:
  305. return "PSS - Length of salt is too big for hash algorithm";
  306. case PRIME_GEN_E:
  307. return "Unable to find a prime for RSA key";
  308. case BER_INDEF_E:
  309. return "Unable to decode an indefinite length encoded message";
  310. case RSA_OUT_OF_RANGE_E:
  311. return "Ciphertext to decrypt is out of range";
  312. case RSAPSS_PAT_FIPS_E:
  313. return "wolfcrypt FIPS RSA-PSS Pairwise Agreement Test Failure";
  314. case ECDSA_PAT_FIPS_E:
  315. return "wolfcrypt FIPS ECDSA Pairwise Agreement Test Failure";
  316. case DH_KAT_FIPS_E:
  317. return "wolfcrypt FIPS DH Known Answer Test Failure";
  318. case AESCCM_KAT_FIPS_E:
  319. return "AESCCM Known Answer Test check FIPS error";
  320. case SHA3_KAT_FIPS_E:
  321. return "SHA-3 Known Answer Test check FIPS error";
  322. case ECDHE_KAT_FIPS_E:
  323. return "wolfcrypt FIPS ECDHE Known Answer Test Failure";
  324. case AES_GCM_OVERFLOW_E:
  325. return "AES-GCM invocation counter overflow";
  326. case AES_CCM_OVERFLOW_E:
  327. return "AES-CCM invocation counter overflow";
  328. case RSA_KEY_PAIR_E:
  329. return "RSA Key Pair-Wise Consistency check fail";
  330. case DH_CHECK_PRIV_E:
  331. return "DH Check Private Key failure";
  332. case WC_AFALG_SOCK_E:
  333. return "AF_ALG socket error";
  334. case WC_DEVCRYPTO_E:
  335. return "Error with /dev/crypto";
  336. case ZLIB_INIT_ERROR:
  337. return "zlib init error";
  338. case ZLIB_COMPRESS_ERROR:
  339. return "zlib compress error";
  340. case ZLIB_DECOMPRESS_ERROR:
  341. return "zlib decompress error";
  342. case PKCS7_NO_SIGNER_E:
  343. return "No signer in PKCS#7 signed data";
  344. case CRYPTOCB_UNAVAILABLE:
  345. return "Crypto callback unavailable";
  346. case PKCS7_SIGNEEDS_CHECK:
  347. return "Signature found but no certificate to verify";
  348. case PSS_SALTLEN_RECOVER_E:
  349. return "PSS - Salt length unable to be recovered";
  350. case ASN_SELF_SIGNED_E:
  351. return "ASN self-signed certificate error";
  352. default:
  353. return "unknown error number";
  354. }
  355. }
  356. void wc_ErrorString(int error, char* buffer)
  357. {
  358. XSTRNCPY(buffer, wc_GetErrorString(error), WOLFSSL_MAX_ERROR_SZ);
  359. }
  360. #endif /* !NO_ERROR_STRINGS */