error.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /* error.c
  2. *
  3. * Copyright (C) 2006-2023 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. WOLFSSL_ABI
  32. const char* wc_GetErrorString(int error)
  33. {
  34. switch (error) {
  35. case OPEN_RAN_E :
  36. return "opening random device error";
  37. case READ_RAN_E :
  38. return "reading random device error";
  39. case WINCRYPT_E :
  40. return "windows crypt init error";
  41. case CRYPTGEN_E :
  42. return "windows crypt generation error";
  43. case RAN_BLOCK_E :
  44. return "random device read would block error";
  45. case BAD_MUTEX_E :
  46. return "Bad mutex, operation failed";
  47. case WC_TIMEOUT_E:
  48. return "Timeout error";
  49. case WC_PENDING_E:
  50. return "wolfCrypt Operation Pending (would block / eagain) error";
  51. case WC_NOT_PENDING_E:
  52. return "wolfCrypt operation not pending error";
  53. case MP_INIT_E :
  54. return "mp_init error state";
  55. case MP_READ_E :
  56. return "mp_read error state";
  57. case MP_EXPTMOD_E :
  58. return "mp_exptmod error state";
  59. case MP_TO_E :
  60. return "mp_to_xxx error state, can't convert";
  61. case MP_SUB_E :
  62. return "mp_sub error state, can't subtract";
  63. case MP_ADD_E :
  64. return "mp_add error state, can't add";
  65. case MP_MUL_E :
  66. return "mp_mul error state, can't multiply";
  67. case MP_MULMOD_E :
  68. return "mp_mulmod error state, can't multiply mod";
  69. case MP_MOD_E :
  70. return "mp_mod error state, can't mod";
  71. case MP_INVMOD_E :
  72. return "mp_invmod error state, can't inv mod";
  73. case MP_CMP_E :
  74. return "mp_cmp error state";
  75. case MP_ZERO_E :
  76. return "mp zero result, not expected";
  77. case MEMORY_E :
  78. return "out of memory error";
  79. case VAR_STATE_CHANGE_E :
  80. return "Variable state modified by different thread";
  81. case RSA_WRONG_TYPE_E :
  82. return "RSA wrong block type for RSA function";
  83. case RSA_BUFFER_E :
  84. return "RSA buffer error, output too small or input too big";
  85. case BUFFER_E :
  86. return "Buffer error, output too small or input too big";
  87. case ALGO_ID_E :
  88. return "Setting Cert AlgoID error";
  89. case PUBLIC_KEY_E :
  90. return "Setting Cert Public Key error";
  91. case DATE_E :
  92. return "Setting Cert Date validity error";
  93. case SUBJECT_E :
  94. return "Setting Cert Subject name error";
  95. case ISSUER_E :
  96. return "Setting Cert Issuer name error";
  97. case CA_TRUE_E :
  98. return "Setting basic constraint CA true error";
  99. case EXTENSIONS_E :
  100. return "Setting extensions error";
  101. case ASN_PARSE_E :
  102. return "ASN parsing error, invalid input";
  103. case ASN_VERSION_E :
  104. return "ASN version error, invalid number";
  105. case ASN_GETINT_E :
  106. return "ASN get big int error, invalid data";
  107. case ASN_RSA_KEY_E :
  108. return "ASN key init error, invalid input";
  109. case ASN_OBJECT_ID_E :
  110. return "ASN object id error, invalid id";
  111. case ASN_TAG_NULL_E :
  112. return "ASN tag error, not null";
  113. case ASN_EXPECT_0_E :
  114. return "ASN expect error, not zero";
  115. case ASN_BITSTR_E :
  116. return "ASN bit string error, wrong id";
  117. case ASN_UNKNOWN_OID_E :
  118. return "ASN oid error, unknown sum id";
  119. case ASN_DATE_SZ_E :
  120. return "ASN date error, bad size";
  121. case ASN_BEFORE_DATE_E :
  122. return "ASN date error, current date before";
  123. case ASN_AFTER_DATE_E :
  124. return "ASN date error, current date after";
  125. case ASN_SIG_OID_E :
  126. return "ASN signature error, mismatched oid";
  127. case ASN_TIME_E :
  128. return "ASN time error, unknown time type";
  129. case ASN_INPUT_E :
  130. return "ASN input error, not enough data";
  131. case ASN_SIG_CONFIRM_E :
  132. return "ASN sig error, confirm failure";
  133. case ASN_SIG_HASH_E :
  134. return "ASN sig error, unsupported hash type";
  135. case ASN_SIG_KEY_E :
  136. return "ASN sig error, unsupported key type";
  137. case ASN_DH_KEY_E :
  138. return "ASN key init error, invalid input";
  139. case ASN_CRIT_EXT_E:
  140. return "X.509 Critical extension ignored or invalid";
  141. case ASN_ALT_NAME_E:
  142. return "ASN alternate name error";
  143. case ECC_BAD_ARG_E :
  144. return "ECC input argument wrong type, invalid input";
  145. case ASN_ECC_KEY_E :
  146. return "ECC ASN1 bad key data, invalid input";
  147. case ECC_CURVE_OID_E :
  148. return "ECC curve sum OID unsupported, invalid input";
  149. case BAD_FUNC_ARG :
  150. return "Bad function argument";
  151. case NOT_COMPILED_IN :
  152. return "Feature not compiled in";
  153. case UNICODE_SIZE_E :
  154. return "Unicode password too big";
  155. case NO_PASSWORD :
  156. return "No password provided by user";
  157. case ALT_NAME_E :
  158. return "Alt Name problem, too big";
  159. case AES_GCM_AUTH_E:
  160. return "AES-GCM Authentication check fail";
  161. case AES_CCM_AUTH_E:
  162. return "AES-CCM Authentication check fail";
  163. case AES_SIV_AUTH_E:
  164. return "AES-SIV authentication failure";
  165. case ASYNC_INIT_E:
  166. return "Async Init error";
  167. case COMPRESS_INIT_E:
  168. return "Compress Init error";
  169. case COMPRESS_E:
  170. return "Compress error";
  171. case DECOMPRESS_INIT_E:
  172. return "DeCompress Init error";
  173. case DECOMPRESS_E:
  174. return "DeCompress error";
  175. case BAD_ALIGN_E:
  176. return "Bad alignment error, no alloc help";
  177. case ASN_NO_SIGNER_E :
  178. #ifndef OPENSSL_EXTRA
  179. return "ASN no signer error to confirm failure";
  180. #else
  181. return "certificate verify failed";
  182. #endif
  183. case ASN_CRL_CONFIRM_E :
  184. return "ASN CRL sig error, confirm failure";
  185. case ASN_CRL_NO_SIGNER_E :
  186. return "ASN CRL no signer error to confirm failure";
  187. case CRL_CERT_DATE_ERR:
  188. return "CRL date error";
  189. case ASN_OCSP_CONFIRM_E :
  190. return "ASN OCSP sig error, confirm failure";
  191. case ASN_NO_PEM_HEADER:
  192. return "ASN no PEM Header Error";
  193. case BAD_STATE_E:
  194. return "Bad state operation";
  195. case BAD_PADDING_E:
  196. return "Bad padding, message wrong length";
  197. case REQ_ATTRIBUTE_E:
  198. return "Setting cert request attributes error";
  199. case PKCS7_OID_E:
  200. return "PKCS#7 error: mismatched OID value";
  201. case PKCS7_RECIP_E:
  202. return "PKCS#7 error: no matching recipient found";
  203. case WC_PKCS7_WANT_READ_E:
  204. return "PKCS#7 operations wants more input, call again";
  205. case FIPS_NOT_ALLOWED_E:
  206. return "FIPS mode not allowed error";
  207. case ASN_NAME_INVALID_E:
  208. return "Name Constraint error";
  209. case RNG_FAILURE_E:
  210. return "Random Number Generator failed";
  211. case HMAC_MIN_KEYLEN_E:
  212. return "FIPS Mode HMAC Minimum Key Length error";
  213. case RSA_PAD_E:
  214. return "Rsa Padding error";
  215. case LENGTH_ONLY_E:
  216. return "Output length only set, not for other use error";
  217. case IN_CORE_FIPS_E:
  218. return "In Core Integrity check FIPS error";
  219. case AES_KAT_FIPS_E:
  220. return "AES Known Answer Test check FIPS error";
  221. case DES3_KAT_FIPS_E:
  222. return "DES3 Known Answer Test check FIPS error";
  223. case HMAC_KAT_FIPS_E:
  224. return "HMAC Known Answer Test check FIPS error";
  225. case RSA_KAT_FIPS_E:
  226. return "RSA Known Answer Test check FIPS error";
  227. case DRBG_KAT_FIPS_E:
  228. return "DRBG Known Answer Test check FIPS error";
  229. case DRBG_CONT_FIPS_E:
  230. return "DRBG Continuous Test FIPS error";
  231. case AESGCM_KAT_FIPS_E:
  232. return "AESGCM Known Answer Test check FIPS error";
  233. case THREAD_STORE_KEY_E:
  234. return "Thread Storage Key Create error";
  235. case THREAD_STORE_SET_E:
  236. return "Thread Storage Set error";
  237. case MAC_CMP_FAILED_E:
  238. return "MAC comparison failed";
  239. case IS_POINT_E:
  240. return "ECC is point on curve failed";
  241. case ECC_INF_E:
  242. return " ECC point at infinity error";
  243. case ECC_OUT_OF_RANGE_E:
  244. return " ECC Qx or Qy out of range error";
  245. case ECC_PRIV_KEY_E:
  246. return " ECC private key is not valid error";
  247. case SRP_CALL_ORDER_E:
  248. return "SRP function called in the wrong order error";
  249. case SRP_VERIFY_E:
  250. return "SRP proof verification error";
  251. case SRP_BAD_KEY_E:
  252. return "SRP bad key values error";
  253. case ASN_NO_SKID:
  254. return "ASN no Subject Key Identifier found error";
  255. case ASN_NO_AKID:
  256. return "ASN no Authority Key Identifier found error";
  257. case ASN_NO_KEYUSAGE:
  258. return "ASN no Key Usage found error";
  259. case SKID_E:
  260. return "Setting Subject Key Identifier error";
  261. case AKID_E:
  262. return "Setting Authority Key Identifier error";
  263. case KEYUSAGE_E:
  264. return "Key Usage value error";
  265. case EXTKEYUSAGE_E:
  266. return "Extended Key Usage value error";
  267. case CERTPOLICIES_E:
  268. return "Setting Certificate Policies error";
  269. case WC_INIT_E:
  270. return "wolfCrypt Initialize Failure error";
  271. case SIG_VERIFY_E:
  272. return "Signature verify error";
  273. case BAD_COND_E:
  274. return "Bad condition variable operation error";
  275. case SIG_TYPE_E:
  276. return "Signature type not enabled/available";
  277. case HASH_TYPE_E:
  278. return "Hash type not enabled/available";
  279. case WC_KEY_SIZE_E:
  280. return "Key size error, either too small or large";
  281. case ASN_COUNTRY_SIZE_E:
  282. return "Country code size error, either too small or large";
  283. case MISSING_RNG_E:
  284. return "RNG required but not provided";
  285. case ASN_PATHLEN_SIZE_E:
  286. return "ASN CA path length value too large error";
  287. case ASN_PATHLEN_INV_E:
  288. return "ASN CA path length larger than signer error";
  289. case BAD_KEYWRAP_ALG_E:
  290. return "Unsupported key wrap algorithm error";
  291. case BAD_KEYWRAP_IV_E:
  292. return "Decrypted AES key wrap IV does not match expected";
  293. case WC_CLEANUP_E:
  294. return "wolfcrypt cleanup failed";
  295. case ECC_CDH_KAT_FIPS_E:
  296. return "wolfcrypt FIPS ECC CDH Known Answer Test Failure";
  297. case DH_CHECK_PUB_E:
  298. return "DH Check Public Key failure";
  299. case BAD_PATH_ERROR:
  300. return "Bad path for opendir error";
  301. case ASYNC_OP_E:
  302. return "Async operation error";
  303. case BAD_OCSP_RESPONDER:
  304. return "Invalid OCSP Responder, missing specific key usage extensions";
  305. case ECC_PRIVATEONLY_E:
  306. return "Invalid use of private only ECC key";
  307. case WC_HW_E:
  308. return "Error with hardware crypto use";
  309. case WC_HW_WAIT_E:
  310. return "Hardware waiting on resource";
  311. case PSS_SALTLEN_E:
  312. return "PSS - Length of salt is too big for hash algorithm";
  313. case PRIME_GEN_E:
  314. return "Unable to find a prime for RSA key";
  315. case BER_INDEF_E:
  316. return "Unable to decode an indefinite length encoded message";
  317. case RSA_OUT_OF_RANGE_E:
  318. return "Ciphertext to decrypt is out of range";
  319. case RSAPSS_PAT_FIPS_E:
  320. return "wolfcrypt FIPS RSA-PSS Pairwise Agreement Test Failure";
  321. case ECDSA_PAT_FIPS_E:
  322. return "wolfcrypt FIPS ECDSA Pairwise Agreement Test Failure";
  323. case DH_KAT_FIPS_E:
  324. return "wolfcrypt FIPS DH Known Answer Test Failure";
  325. case AESCCM_KAT_FIPS_E:
  326. return "AESCCM Known Answer Test check FIPS error";
  327. case SHA3_KAT_FIPS_E:
  328. return "SHA-3 Known Answer Test check FIPS error";
  329. case ECDHE_KAT_FIPS_E:
  330. return "wolfcrypt FIPS ECDHE Known Answer Test Failure";
  331. case AES_GCM_OVERFLOW_E:
  332. return "AES-GCM invocation counter overflow";
  333. case AES_CCM_OVERFLOW_E:
  334. return "AES-CCM invocation counter overflow";
  335. case RSA_KEY_PAIR_E:
  336. return "RSA Key Pair-Wise Consistency check fail";
  337. case DH_CHECK_PRIV_E:
  338. return "DH Check Private Key failure";
  339. case WC_AFALG_SOCK_E:
  340. return "AF_ALG socket error";
  341. case WC_DEVCRYPTO_E:
  342. return "Error with /dev/crypto";
  343. case ZLIB_INIT_ERROR:
  344. return "zlib init error";
  345. case ZLIB_COMPRESS_ERROR:
  346. return "zlib compress error";
  347. case ZLIB_DECOMPRESS_ERROR:
  348. return "zlib decompress error";
  349. case PKCS7_NO_SIGNER_E:
  350. return "No signer in PKCS#7 signed data";
  351. case CRYPTOCB_UNAVAILABLE:
  352. return "Crypto callback unavailable";
  353. case PKCS7_SIGNEEDS_CHECK:
  354. return "Signature found but no certificate to verify";
  355. case PSS_SALTLEN_RECOVER_E:
  356. return "PSS - Salt length unable to be recovered";
  357. case CHACHA_POLY_OVERFLOW:
  358. return "wolfcrypt - ChaCha20_Poly1305 limit overflow 4GB";
  359. case ASN_SELF_SIGNED_E:
  360. return "ASN self-signed certificate error";
  361. case SAKKE_VERIFY_FAIL_E:
  362. return "SAKKE derivation verification error";
  363. case MISSING_IV:
  364. return "Required IV not set";
  365. case MISSING_KEY:
  366. return "Required key not set";
  367. case BAD_LENGTH_E:
  368. return "Value of length parameter is invalid.";
  369. case ECDSA_KAT_FIPS_E:
  370. return "wolfcrypt FIPS ECDSA Known Answer Test Failure";
  371. case RSA_PAT_FIPS_E:
  372. return "wolfcrypt FIPS RSA Pairwise Agreement Test Failure";
  373. case KDF_TLS12_KAT_FIPS_E:
  374. return "wolfcrypt FIPS TLSv1.2 KDF Known Answer Test Failure";
  375. case KDF_TLS13_KAT_FIPS_E:
  376. return "wolfcrypt FIPS TLSv1.3 KDF Known Answer Test Failure";
  377. case KDF_SSH_KAT_FIPS_E:
  378. return "wolfcrypt FIPS SSH KDF Known Answer Test Failure";
  379. case DHE_PCT_E:
  380. return "wolfcrypt DHE Pairwise Consistency Test Failure";
  381. case ECC_PCT_E:
  382. return "wolfcrypt ECDHE Pairwise Consistency Test Failure";
  383. case FIPS_PRIVATE_KEY_LOCKED_E:
  384. return "Cannot export private key, locked";
  385. case PROTOCOLCB_UNAVAILABLE:
  386. return "Protocol callback unavailable";
  387. case NO_VALID_DEVID:
  388. return "No valid device ID set";
  389. case IO_FAILED_E:
  390. return "Input/output failure";
  391. case SYSLIB_FAILED_E:
  392. return "System/library call failed";
  393. case USE_HW_PSK:
  394. return "Callback indicates that HW has PSK";
  395. case ENTROPY_RT_E:
  396. return "Entropy Repetition Test failed";
  397. case ENTROPY_APT_E:
  398. return "Entropy Adaptive Proportion Test failed";
  399. case ASN_DEPTH_E:
  400. return "Invalid ASN.1 - depth check";
  401. case ASN_LEN_E:
  402. return "ASN.1 length invalid";
  403. case SM4_GCM_AUTH_E:
  404. return "SM4-GCM Authentication check fail";
  405. case SM4_CCM_AUTH_E:
  406. return "SM4-CCM Authentication check fail";
  407. default:
  408. return "unknown error number";
  409. }
  410. }
  411. void wc_ErrorString(int error, char* buffer)
  412. {
  413. XSTRNCPY(buffer, wc_GetErrorString(error), WOLFSSL_MAX_ERROR_SZ);
  414. buffer[WOLFSSL_MAX_ERROR_SZ-1] = 0;
  415. }
  416. #endif /* !NO_ERROR_STRINGS */