error.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. /*
  2. * Error message information
  3. *
  4. * Copyright The Mbed TLS Contributors
  5. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  6. */
  7. #include "common.h"
  8. #include "mbedtls/error.h"
  9. #if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
  10. #if defined(MBEDTLS_ERROR_C)
  11. #include "mbedtls/platform.h"
  12. #include <stdio.h>
  13. #include <string.h>
  14. #if defined(MBEDTLS_AES_C)
  15. #include "mbedtls/aes.h"
  16. #endif
  17. #if defined(MBEDTLS_ARC4_C)
  18. #include "mbedtls/arc4.h"
  19. #endif
  20. #if defined(MBEDTLS_ARIA_C)
  21. #include "mbedtls/aria.h"
  22. #endif
  23. #if defined(MBEDTLS_ASN1_PARSE_C)
  24. #include "mbedtls/asn1.h"
  25. #endif
  26. #if defined(MBEDTLS_BASE64_C)
  27. #include "mbedtls/base64.h"
  28. #endif
  29. #if defined(MBEDTLS_BIGNUM_C)
  30. #include "mbedtls/bignum.h"
  31. #endif
  32. #if defined(MBEDTLS_BLOWFISH_C)
  33. #include "mbedtls/blowfish.h"
  34. #endif
  35. #if defined(MBEDTLS_CAMELLIA_C)
  36. #include "mbedtls/camellia.h"
  37. #endif
  38. #if defined(MBEDTLS_CCM_C)
  39. #include "mbedtls/ccm.h"
  40. #endif
  41. #if defined(MBEDTLS_CHACHA20_C)
  42. #include "mbedtls/chacha20.h"
  43. #endif
  44. #if defined(MBEDTLS_CHACHAPOLY_C)
  45. #include "mbedtls/chachapoly.h"
  46. #endif
  47. #if defined(MBEDTLS_CIPHER_C)
  48. #include "mbedtls/cipher.h"
  49. #endif
  50. #if defined(MBEDTLS_CMAC_C)
  51. #include "mbedtls/cmac.h"
  52. #endif
  53. #if defined(MBEDTLS_CTR_DRBG_C)
  54. #include "mbedtls/ctr_drbg.h"
  55. #endif
  56. #if defined(MBEDTLS_DES_C)
  57. #include "mbedtls/des.h"
  58. #endif
  59. #if defined(MBEDTLS_DHM_C)
  60. #include "mbedtls/dhm.h"
  61. #endif
  62. #if defined(MBEDTLS_ECP_C)
  63. #include "mbedtls/ecp.h"
  64. #endif
  65. #if defined(MBEDTLS_ENTROPY_C)
  66. #include "mbedtls/entropy.h"
  67. #endif
  68. #if defined(MBEDTLS_ERROR_C)
  69. #include "mbedtls/error.h"
  70. #endif
  71. #if defined(MBEDTLS_GCM_C)
  72. #include "mbedtls/gcm.h"
  73. #endif
  74. #if defined(MBEDTLS_HKDF_C)
  75. #include "mbedtls/hkdf.h"
  76. #endif
  77. #if defined(MBEDTLS_HMAC_DRBG_C)
  78. #include "mbedtls/hmac_drbg.h"
  79. #endif
  80. #if defined(MBEDTLS_MD_C)
  81. #include "mbedtls/md.h"
  82. #endif
  83. #if defined(MBEDTLS_MD2_C)
  84. #include "mbedtls/md2.h"
  85. #endif
  86. #if defined(MBEDTLS_MD4_C)
  87. #include "mbedtls/md4.h"
  88. #endif
  89. #if defined(MBEDTLS_MD5_C)
  90. #include "mbedtls/md5.h"
  91. #endif
  92. #if defined(MBEDTLS_NET_C)
  93. #include "mbedtls/net_sockets.h"
  94. #endif
  95. #if defined(MBEDTLS_OID_C)
  96. #include "mbedtls/oid.h"
  97. #endif
  98. #if defined(MBEDTLS_PADLOCK_C)
  99. #include "mbedtls/padlock.h"
  100. #endif
  101. #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
  102. #include "mbedtls/pem.h"
  103. #endif
  104. #if defined(MBEDTLS_PK_C)
  105. #include "mbedtls/pk.h"
  106. #endif
  107. #if defined(MBEDTLS_PKCS12_C)
  108. #include "mbedtls/pkcs12.h"
  109. #endif
  110. #if defined(MBEDTLS_PKCS5_C)
  111. #include "mbedtls/pkcs5.h"
  112. #endif
  113. #if defined(MBEDTLS_PLATFORM_C)
  114. #include "mbedtls/platform.h"
  115. #endif
  116. #if defined(MBEDTLS_POLY1305_C)
  117. #include "mbedtls/poly1305.h"
  118. #endif
  119. #if defined(MBEDTLS_RIPEMD160_C)
  120. #include "mbedtls/ripemd160.h"
  121. #endif
  122. #if defined(MBEDTLS_RSA_C)
  123. #include "mbedtls/rsa.h"
  124. #endif
  125. #if defined(MBEDTLS_SHA1_C)
  126. #include "mbedtls/sha1.h"
  127. #endif
  128. #if defined(MBEDTLS_SHA256_C)
  129. #include "mbedtls/sha256.h"
  130. #endif
  131. #if defined(MBEDTLS_SHA512_C)
  132. #include "mbedtls/sha512.h"
  133. #endif
  134. #if defined(MBEDTLS_SSL_TLS_C)
  135. #include "mbedtls/ssl.h"
  136. #endif
  137. #if defined(MBEDTLS_THREADING_C)
  138. #include "mbedtls/threading.h"
  139. #endif
  140. #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
  141. #include "mbedtls/x509.h"
  142. #endif
  143. #if defined(MBEDTLS_XTEA_C)
  144. #include "mbedtls/xtea.h"
  145. #endif
  146. const char *mbedtls_high_level_strerr(int error_code)
  147. {
  148. int high_level_error_code;
  149. if (error_code < 0) {
  150. error_code = -error_code;
  151. }
  152. /* Extract the high-level part from the error code. */
  153. high_level_error_code = error_code & 0xFF80;
  154. switch (high_level_error_code) {
  155. /* Begin Auto-Generated Code. */
  156. #if defined(MBEDTLS_CIPHER_C)
  157. case -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE):
  158. return( "CIPHER - The selected feature is not available" );
  159. case -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA):
  160. return( "CIPHER - Bad input parameters" );
  161. case -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED):
  162. return( "CIPHER - Failed to allocate memory" );
  163. case -(MBEDTLS_ERR_CIPHER_INVALID_PADDING):
  164. return( "CIPHER - Input data contains invalid padding and is rejected" );
  165. case -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED):
  166. return( "CIPHER - Decryption of block requires a full block" );
  167. case -(MBEDTLS_ERR_CIPHER_AUTH_FAILED):
  168. return( "CIPHER - Authentication failed (for AEAD modes)" );
  169. case -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT):
  170. return( "CIPHER - The context is invalid. For example, because it was freed" );
  171. case -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED):
  172. return( "CIPHER - Cipher hardware accelerator failed" );
  173. #endif /* MBEDTLS_CIPHER_C */
  174. #if defined(MBEDTLS_DHM_C)
  175. case -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA):
  176. return( "DHM - Bad input parameters" );
  177. case -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED):
  178. return( "DHM - Reading of the DHM parameters failed" );
  179. case -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED):
  180. return( "DHM - Making of the DHM parameters failed" );
  181. case -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED):
  182. return( "DHM - Reading of the public values failed" );
  183. case -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED):
  184. return( "DHM - Making of the public value failed" );
  185. case -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED):
  186. return( "DHM - Calculation of the DHM secret failed" );
  187. case -(MBEDTLS_ERR_DHM_INVALID_FORMAT):
  188. return( "DHM - The ASN.1 data is not formatted correctly" );
  189. case -(MBEDTLS_ERR_DHM_ALLOC_FAILED):
  190. return( "DHM - Allocation of memory failed" );
  191. case -(MBEDTLS_ERR_DHM_FILE_IO_ERROR):
  192. return( "DHM - Read or write of file failed" );
  193. case -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED):
  194. return( "DHM - DHM hardware accelerator failed" );
  195. case -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED):
  196. return( "DHM - Setting the modulus and generator failed" );
  197. #endif /* MBEDTLS_DHM_C */
  198. #if defined(MBEDTLS_ECP_C)
  199. case -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA):
  200. return( "ECP - Bad input parameters to function" );
  201. case -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL):
  202. return( "ECP - The buffer is too small to write to" );
  203. case -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE):
  204. return( "ECP - The requested feature is not available, for example, the requested curve is not supported" );
  205. case -(MBEDTLS_ERR_ECP_VERIFY_FAILED):
  206. return( "ECP - The signature is not valid" );
  207. case -(MBEDTLS_ERR_ECP_ALLOC_FAILED):
  208. return( "ECP - Memory allocation failed" );
  209. case -(MBEDTLS_ERR_ECP_RANDOM_FAILED):
  210. return( "ECP - Generation of random value, such as ephemeral key, failed" );
  211. case -(MBEDTLS_ERR_ECP_INVALID_KEY):
  212. return( "ECP - Invalid private or public key" );
  213. case -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH):
  214. return( "ECP - The buffer contains a valid signature followed by more data" );
  215. case -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED):
  216. return( "ECP - The ECP hardware accelerator failed" );
  217. case -(MBEDTLS_ERR_ECP_IN_PROGRESS):
  218. return( "ECP - Operation in progress, call again with the same parameters to continue" );
  219. #endif /* MBEDTLS_ECP_C */
  220. #if defined(MBEDTLS_MD_C)
  221. case -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE):
  222. return( "MD - The selected feature is not available" );
  223. case -(MBEDTLS_ERR_MD_BAD_INPUT_DATA):
  224. return( "MD - Bad input parameters to function" );
  225. case -(MBEDTLS_ERR_MD_ALLOC_FAILED):
  226. return( "MD - Failed to allocate memory" );
  227. case -(MBEDTLS_ERR_MD_FILE_IO_ERROR):
  228. return( "MD - Opening or reading of file failed" );
  229. case -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED):
  230. return( "MD - MD hardware accelerator failed" );
  231. #endif /* MBEDTLS_MD_C */
  232. #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
  233. case -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT):
  234. return( "PEM - No PEM header or footer found" );
  235. case -(MBEDTLS_ERR_PEM_INVALID_DATA):
  236. return( "PEM - PEM string is not as expected" );
  237. case -(MBEDTLS_ERR_PEM_ALLOC_FAILED):
  238. return( "PEM - Failed to allocate memory" );
  239. case -(MBEDTLS_ERR_PEM_INVALID_ENC_IV):
  240. return( "PEM - RSA IV is not in hex-format" );
  241. case -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG):
  242. return( "PEM - Unsupported key encryption algorithm" );
  243. case -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED):
  244. return( "PEM - Private key password can't be empty" );
  245. case -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH):
  246. return( "PEM - Given private key password does not allow for correct decryption" );
  247. case -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE):
  248. return( "PEM - Unavailable feature, e.g. hashing/encryption combination" );
  249. case -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA):
  250. return( "PEM - Bad input parameters to function" );
  251. #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
  252. #if defined(MBEDTLS_PK_C)
  253. case -(MBEDTLS_ERR_PK_ALLOC_FAILED):
  254. return( "PK - Memory allocation failed" );
  255. case -(MBEDTLS_ERR_PK_TYPE_MISMATCH):
  256. return( "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
  257. case -(MBEDTLS_ERR_PK_BAD_INPUT_DATA):
  258. return( "PK - Bad input parameters to function" );
  259. case -(MBEDTLS_ERR_PK_FILE_IO_ERROR):
  260. return( "PK - Read/write of file failed" );
  261. case -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION):
  262. return( "PK - Unsupported key version" );
  263. case -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT):
  264. return( "PK - Invalid key tag or value" );
  265. case -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG):
  266. return( "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
  267. case -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED):
  268. return( "PK - Private key password can't be empty" );
  269. case -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH):
  270. return( "PK - Given private key password does not allow for correct decryption" );
  271. case -(MBEDTLS_ERR_PK_INVALID_PUBKEY):
  272. return( "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
  273. case -(MBEDTLS_ERR_PK_INVALID_ALG):
  274. return( "PK - The algorithm tag or value is invalid" );
  275. case -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE):
  276. return( "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
  277. case -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE):
  278. return( "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
  279. case -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH):
  280. return( "PK - The buffer contains a valid signature followed by more data" );
  281. case -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED):
  282. return( "PK - PK hardware accelerator failed" );
  283. #endif /* MBEDTLS_PK_C */
  284. #if defined(MBEDTLS_PKCS12_C)
  285. case -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA):
  286. return( "PKCS12 - Bad input parameters to function" );
  287. case -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE):
  288. return( "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
  289. case -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT):
  290. return( "PKCS12 - PBE ASN.1 data not as expected" );
  291. case -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH):
  292. return( "PKCS12 - Given private key password does not allow for correct decryption" );
  293. #endif /* MBEDTLS_PKCS12_C */
  294. #if defined(MBEDTLS_PKCS5_C)
  295. case -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA):
  296. return( "PKCS5 - Bad input parameters to function" );
  297. case -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT):
  298. return( "PKCS5 - Unexpected ASN.1 data" );
  299. case -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE):
  300. return( "PKCS5 - Requested encryption or digest alg not available" );
  301. case -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH):
  302. return( "PKCS5 - Given private key password does not allow for correct decryption" );
  303. #endif /* MBEDTLS_PKCS5_C */
  304. #if defined(MBEDTLS_RSA_C)
  305. case -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA):
  306. return( "RSA - Bad input parameters to function" );
  307. case -(MBEDTLS_ERR_RSA_INVALID_PADDING):
  308. return( "RSA - Input data contains invalid padding and is rejected" );
  309. case -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED):
  310. return( "RSA - Something failed during generation of a key" );
  311. case -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED):
  312. return( "RSA - Key failed to pass the validity check of the library" );
  313. case -(MBEDTLS_ERR_RSA_PUBLIC_FAILED):
  314. return( "RSA - The public key operation failed" );
  315. case -(MBEDTLS_ERR_RSA_PRIVATE_FAILED):
  316. return( "RSA - The private key operation failed" );
  317. case -(MBEDTLS_ERR_RSA_VERIFY_FAILED):
  318. return( "RSA - The PKCS#1 verification failed" );
  319. case -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE):
  320. return( "RSA - The output buffer for decryption is not large enough" );
  321. case -(MBEDTLS_ERR_RSA_RNG_FAILED):
  322. return( "RSA - The random generator failed to generate non-zeros" );
  323. case -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION):
  324. return( "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality" );
  325. case -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED):
  326. return( "RSA - RSA hardware accelerator failed" );
  327. #endif /* MBEDTLS_RSA_C */
  328. #if defined(MBEDTLS_SSL_TLS_C)
  329. case -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE):
  330. return( "SSL - The requested feature is not available" );
  331. case -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA):
  332. return( "SSL - Bad input parameters to function" );
  333. case -(MBEDTLS_ERR_SSL_INVALID_MAC):
  334. return( "SSL - Verification of the message MAC failed" );
  335. case -(MBEDTLS_ERR_SSL_INVALID_RECORD):
  336. return( "SSL - An invalid SSL record was received" );
  337. case -(MBEDTLS_ERR_SSL_CONN_EOF):
  338. return( "SSL - The connection indicated an EOF" );
  339. case -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER):
  340. return( "SSL - An unknown cipher was received" );
  341. case -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN):
  342. return( "SSL - The server has no ciphersuites in common with the client" );
  343. case -(MBEDTLS_ERR_SSL_NO_RNG):
  344. return( "SSL - No RNG was provided to the SSL module" );
  345. case -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE):
  346. return( "SSL - No client certification received from the client, but required by the authentication mode" );
  347. case -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE):
  348. return( "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
  349. case -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED):
  350. return( "SSL - The own certificate is not set, but needed by the server" );
  351. case -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED):
  352. return( "SSL - The own private key or pre-shared key is not set, but needed" );
  353. case -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED):
  354. return( "SSL - No CA Chain is set, but required to operate" );
  355. case -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE):
  356. return( "SSL - An unexpected message was received from our peer" );
  357. case -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE):
  358. return( "SSL - A fatal alert message was received from our peer" );
  359. case -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED):
  360. return( "SSL - Verification of our peer failed" );
  361. case -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY):
  362. return( "SSL - The peer notified us that the connection is going to be closed" );
  363. case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO):
  364. return( "SSL - Processing of the ClientHello handshake message failed" );
  365. case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO):
  366. return( "SSL - Processing of the ServerHello handshake message failed" );
  367. case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE):
  368. return( "SSL - Processing of the Certificate handshake message failed" );
  369. case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST):
  370. return( "SSL - Processing of the CertificateRequest handshake message failed" );
  371. case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE):
  372. return( "SSL - Processing of the ServerKeyExchange handshake message failed" );
  373. case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE):
  374. return( "SSL - Processing of the ServerHelloDone handshake message failed" );
  375. case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE):
  376. return( "SSL - Processing of the ClientKeyExchange handshake message failed" );
  377. case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP):
  378. return( "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
  379. case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS):
  380. return( "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
  381. case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY):
  382. return( "SSL - Processing of the CertificateVerify handshake message failed" );
  383. case -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC):
  384. return( "SSL - Processing of the ChangeCipherSpec handshake message failed" );
  385. case -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED):
  386. return( "SSL - Processing of the Finished handshake message failed" );
  387. case -(MBEDTLS_ERR_SSL_ALLOC_FAILED):
  388. return( "SSL - Memory allocation failed" );
  389. case -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED):
  390. return( "SSL - Hardware acceleration function returned with error" );
  391. case -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH):
  392. return( "SSL - Hardware acceleration function skipped / left alone data" );
  393. case -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED):
  394. return( "SSL - Processing of the compression / decompression failed" );
  395. case -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION):
  396. return( "SSL - Handshake protocol not within min/max boundaries" );
  397. case -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET):
  398. return( "SSL - Processing of the NewSessionTicket handshake message failed" );
  399. case -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED):
  400. return( "SSL - Session ticket has expired" );
  401. case -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH):
  402. return( "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
  403. case -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY):
  404. return( "SSL - Unknown identity received (eg, PSK identity)" );
  405. case -(MBEDTLS_ERR_SSL_INTERNAL_ERROR):
  406. return( "SSL - Internal error (eg, unexpected failure in lower-level module)" );
  407. case -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING):
  408. return( "SSL - A counter would wrap (eg, too many messages exchanged)" );
  409. case -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO):
  410. return( "SSL - Unexpected message at ServerHello in renegotiation" );
  411. case -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED):
  412. return( "SSL - DTLS client must retry for hello verification" );
  413. case -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL):
  414. return( "SSL - A buffer is too small to receive or write a message" );
  415. case -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE):
  416. return( "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
  417. case -(MBEDTLS_ERR_SSL_WANT_READ):
  418. return( "SSL - No data of requested type currently available on underlying transport" );
  419. case -(MBEDTLS_ERR_SSL_WANT_WRITE):
  420. return( "SSL - Connection requires a write call" );
  421. case -(MBEDTLS_ERR_SSL_TIMEOUT):
  422. return( "SSL - The operation timed out" );
  423. case -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT):
  424. return( "SSL - The client initiated a reconnect from the same port" );
  425. case -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD):
  426. return( "SSL - Record header looks valid but is not expected" );
  427. case -(MBEDTLS_ERR_SSL_NON_FATAL):
  428. return( "SSL - The alert message received indicates a non-fatal error" );
  429. case -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH):
  430. return( "SSL - Couldn't set the hash for verifying CertificateVerify" );
  431. case -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING):
  432. return( "SSL - Internal-only message signaling that further message-processing should be done" );
  433. case -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS):
  434. return( "SSL - The asynchronous operation is not completed yet" );
  435. case -(MBEDTLS_ERR_SSL_EARLY_MESSAGE):
  436. return( "SSL - Internal-only message signaling that a message arrived early" );
  437. case -(MBEDTLS_ERR_SSL_UNEXPECTED_CID):
  438. return( "SSL - An encrypted DTLS-frame with an unexpected CID was received" );
  439. case -(MBEDTLS_ERR_SSL_VERSION_MISMATCH):
  440. return( "SSL - An operation failed due to an unexpected version or configuration" );
  441. case -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS):
  442. return( "SSL - A cryptographic operation is in progress. Try again later" );
  443. case -(MBEDTLS_ERR_SSL_BAD_CONFIG):
  444. return( "SSL - Invalid value in SSL config" );
  445. case -(MBEDTLS_ERR_SSL_CACHE_ENTRY_NOT_FOUND):
  446. return( "SSL - Cache entry not found" );
  447. case -(MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME):
  448. return( "SSL - Attempt to verify a certificate without an expected hostname. This is usually insecure. In TLS clients, when a client authenticates a server through its certificate, the client normally checks three things: - the certificate chain must be valid; - the chain must start from a trusted CA; - the certificate must cover the server name that is expected by the client. Omitting any of these checks is generally insecure, and can allow a malicious server to impersonate a legitimate server. The third check may be safely skipped in some unusual scenarios, such as networks where eavesdropping is a risk but not active attacks, or a private PKI where the client equally trusts all servers that are accredited by the root CA. You should call mbedtls_ssl_set_hostname() with the expected server name before starting a TLS handshake on a client (unless the client is set up to only use PSK-based authentication, which does not rely on the host name). If you have determined that server name verification is not required for security in your scenario, call mbedtls_ssl_set_hostname() with \\p NULL as the server name. This error is raised if all of the following conditions are met: - A TLS client is configured with the authentication mode #MBEDTLS_SSL_VERIFY_REQUIRED (default). - Certificate authentication is enabled. - The client does not call mbedtls_ssl_set_hostname(). - The configuration option #MBEDTLS_SSL_CLI_ALLOW_WEAK_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME is not enabled" );
  449. #endif /* MBEDTLS_SSL_TLS_C */
  450. #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
  451. case -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE):
  452. return( "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
  453. case -(MBEDTLS_ERR_X509_UNKNOWN_OID):
  454. return( "X509 - Requested OID is unknown" );
  455. case -(MBEDTLS_ERR_X509_INVALID_FORMAT):
  456. return( "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
  457. case -(MBEDTLS_ERR_X509_INVALID_VERSION):
  458. return( "X509 - The CRT/CRL/CSR version element is invalid" );
  459. case -(MBEDTLS_ERR_X509_INVALID_SERIAL):
  460. return( "X509 - The serial tag or value is invalid" );
  461. case -(MBEDTLS_ERR_X509_INVALID_ALG):
  462. return( "X509 - The algorithm tag or value is invalid" );
  463. case -(MBEDTLS_ERR_X509_INVALID_NAME):
  464. return( "X509 - The name tag or value is invalid" );
  465. case -(MBEDTLS_ERR_X509_INVALID_DATE):
  466. return( "X509 - The date tag or value is invalid" );
  467. case -(MBEDTLS_ERR_X509_INVALID_SIGNATURE):
  468. return( "X509 - The signature tag or value invalid" );
  469. case -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS):
  470. return( "X509 - The extension tag or value is invalid" );
  471. case -(MBEDTLS_ERR_X509_UNKNOWN_VERSION):
  472. return( "X509 - CRT/CRL/CSR has an unsupported version number" );
  473. case -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG):
  474. return( "X509 - Signature algorithm (oid) is unsupported" );
  475. case -(MBEDTLS_ERR_X509_SIG_MISMATCH):
  476. return( "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
  477. case -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED):
  478. return( "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
  479. case -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT):
  480. return( "X509 - Format not recognized as DER or PEM" );
  481. case -(MBEDTLS_ERR_X509_BAD_INPUT_DATA):
  482. return( "X509 - Input invalid" );
  483. case -(MBEDTLS_ERR_X509_ALLOC_FAILED):
  484. return( "X509 - Allocation of memory failed" );
  485. case -(MBEDTLS_ERR_X509_FILE_IO_ERROR):
  486. return( "X509 - Read/write of file failed" );
  487. case -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL):
  488. return( "X509 - Destination buffer is too small" );
  489. case -(MBEDTLS_ERR_X509_FATAL_ERROR):
  490. return( "X509 - A fatal error occurred, eg the chain is too long or the vrfy callback failed" );
  491. #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
  492. /* End Auto-Generated Code. */
  493. default:
  494. break;
  495. }
  496. return NULL;
  497. }
  498. const char *mbedtls_low_level_strerr(int error_code)
  499. {
  500. int low_level_error_code;
  501. if (error_code < 0) {
  502. error_code = -error_code;
  503. }
  504. /* Extract the low-level part from the error code. */
  505. low_level_error_code = error_code & ~0xFF80;
  506. switch (low_level_error_code) {
  507. /* Begin Auto-Generated Code. */
  508. #if defined(MBEDTLS_AES_C)
  509. case -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH):
  510. return( "AES - Invalid key length" );
  511. case -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH):
  512. return( "AES - Invalid data input length" );
  513. case -(MBEDTLS_ERR_AES_BAD_INPUT_DATA):
  514. return( "AES - Invalid input data" );
  515. case -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE):
  516. return( "AES - Feature not available. For example, an unsupported AES key size" );
  517. case -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED):
  518. return( "AES - AES hardware accelerator failed" );
  519. #endif /* MBEDTLS_AES_C */
  520. #if defined(MBEDTLS_ARC4_C)
  521. case -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED):
  522. return( "ARC4 - ARC4 hardware accelerator failed" );
  523. #endif /* MBEDTLS_ARC4_C */
  524. #if defined(MBEDTLS_ARIA_C)
  525. case -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA):
  526. return( "ARIA - Bad input data" );
  527. case -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH):
  528. return( "ARIA - Invalid data input length" );
  529. case -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE):
  530. return( "ARIA - Feature not available. For example, an unsupported ARIA key size" );
  531. case -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED):
  532. return( "ARIA - ARIA hardware accelerator failed" );
  533. #endif /* MBEDTLS_ARIA_C */
  534. #if defined(MBEDTLS_ASN1_PARSE_C)
  535. case -(MBEDTLS_ERR_ASN1_OUT_OF_DATA):
  536. return( "ASN1 - Out of data when parsing an ASN1 data structure" );
  537. case -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG):
  538. return( "ASN1 - ASN1 tag was of an unexpected value" );
  539. case -(MBEDTLS_ERR_ASN1_INVALID_LENGTH):
  540. return( "ASN1 - Error when trying to determine the length or invalid length" );
  541. case -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH):
  542. return( "ASN1 - Actual length differs from expected length" );
  543. case -(MBEDTLS_ERR_ASN1_INVALID_DATA):
  544. return( "ASN1 - Data is invalid" );
  545. case -(MBEDTLS_ERR_ASN1_ALLOC_FAILED):
  546. return( "ASN1 - Memory allocation failed" );
  547. case -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL):
  548. return( "ASN1 - Buffer too small when writing ASN.1 data structure" );
  549. #endif /* MBEDTLS_ASN1_PARSE_C */
  550. #if defined(MBEDTLS_BASE64_C)
  551. case -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL):
  552. return( "BASE64 - Output buffer too small" );
  553. case -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER):
  554. return( "BASE64 - Invalid character in input" );
  555. #endif /* MBEDTLS_BASE64_C */
  556. #if defined(MBEDTLS_BIGNUM_C)
  557. case -(MBEDTLS_ERR_MPI_FILE_IO_ERROR):
  558. return( "BIGNUM - An error occurred while reading from or writing to a file" );
  559. case -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA):
  560. return( "BIGNUM - Bad input parameters to function" );
  561. case -(MBEDTLS_ERR_MPI_INVALID_CHARACTER):
  562. return( "BIGNUM - There is an invalid character in the digit string" );
  563. case -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL):
  564. return( "BIGNUM - The buffer is too small to write to" );
  565. case -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE):
  566. return( "BIGNUM - The input arguments are negative or result in illegal output" );
  567. case -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO):
  568. return( "BIGNUM - The input argument for division is zero, which is not allowed" );
  569. case -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE):
  570. return( "BIGNUM - The input arguments are not acceptable" );
  571. case -(MBEDTLS_ERR_MPI_ALLOC_FAILED):
  572. return( "BIGNUM - Memory allocation failed" );
  573. #endif /* MBEDTLS_BIGNUM_C */
  574. #if defined(MBEDTLS_BLOWFISH_C)
  575. case -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA):
  576. return( "BLOWFISH - Bad input data" );
  577. case -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH):
  578. return( "BLOWFISH - Invalid data input length" );
  579. case -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED):
  580. return( "BLOWFISH - Blowfish hardware accelerator failed" );
  581. #endif /* MBEDTLS_BLOWFISH_C */
  582. #if defined(MBEDTLS_CAMELLIA_C)
  583. case -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA):
  584. return( "CAMELLIA - Bad input data" );
  585. case -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH):
  586. return( "CAMELLIA - Invalid data input length" );
  587. case -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED):
  588. return( "CAMELLIA - Camellia hardware accelerator failed" );
  589. #endif /* MBEDTLS_CAMELLIA_C */
  590. #if defined(MBEDTLS_CCM_C)
  591. case -(MBEDTLS_ERR_CCM_BAD_INPUT):
  592. return( "CCM - Bad input parameters to the function" );
  593. case -(MBEDTLS_ERR_CCM_AUTH_FAILED):
  594. return( "CCM - Authenticated decryption failed" );
  595. case -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED):
  596. return( "CCM - CCM hardware accelerator failed" );
  597. #endif /* MBEDTLS_CCM_C */
  598. #if defined(MBEDTLS_CHACHA20_C)
  599. case -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA):
  600. return( "CHACHA20 - Invalid input parameter(s)" );
  601. case -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE):
  602. return( "CHACHA20 - Feature not available. For example, s part of the API is not implemented" );
  603. case -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED):
  604. return( "CHACHA20 - Chacha20 hardware accelerator failed" );
  605. #endif /* MBEDTLS_CHACHA20_C */
  606. #if defined(MBEDTLS_CHACHAPOLY_C)
  607. case -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE):
  608. return( "CHACHAPOLY - The requested operation is not permitted in the current state" );
  609. case -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED):
  610. return( "CHACHAPOLY - Authenticated decryption failed: data was not authentic" );
  611. #endif /* MBEDTLS_CHACHAPOLY_C */
  612. #if defined(MBEDTLS_CMAC_C)
  613. case -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED):
  614. return( "CMAC - CMAC hardware accelerator failed" );
  615. #endif /* MBEDTLS_CMAC_C */
  616. #if defined(MBEDTLS_CTR_DRBG_C)
  617. case -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED):
  618. return( "CTR_DRBG - The entropy source failed" );
  619. case -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG):
  620. return( "CTR_DRBG - The requested random buffer length is too big" );
  621. case -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG):
  622. return( "CTR_DRBG - The input (entropy + additional data) is too large" );
  623. case -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR):
  624. return( "CTR_DRBG - Read or write error in file" );
  625. #endif /* MBEDTLS_CTR_DRBG_C */
  626. #if defined(MBEDTLS_DES_C)
  627. case -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH):
  628. return( "DES - The data input has an invalid length" );
  629. case -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED):
  630. return( "DES - DES hardware accelerator failed" );
  631. #endif /* MBEDTLS_DES_C */
  632. #if defined(MBEDTLS_ENTROPY_C)
  633. case -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED):
  634. return( "ENTROPY - Critical entropy source failure" );
  635. case -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES):
  636. return( "ENTROPY - No more sources can be added" );
  637. case -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED):
  638. return( "ENTROPY - No sources have been added to poll" );
  639. case -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE):
  640. return( "ENTROPY - No strong sources have been added to poll" );
  641. case -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR):
  642. return( "ENTROPY - Read/write error in file" );
  643. #endif /* MBEDTLS_ENTROPY_C */
  644. #if defined(MBEDTLS_ERROR_C)
  645. case -(MBEDTLS_ERR_ERROR_GENERIC_ERROR):
  646. return( "ERROR - Generic error" );
  647. case -(MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED):
  648. return( "ERROR - This is a bug in the library" );
  649. #endif /* MBEDTLS_ERROR_C */
  650. #if defined(MBEDTLS_GCM_C)
  651. case -(MBEDTLS_ERR_GCM_AUTH_FAILED):
  652. return( "GCM - Authenticated decryption failed" );
  653. case -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED):
  654. return( "GCM - GCM hardware accelerator failed" );
  655. case -(MBEDTLS_ERR_GCM_BAD_INPUT):
  656. return( "GCM - Bad input parameters to function" );
  657. #endif /* MBEDTLS_GCM_C */
  658. #if defined(MBEDTLS_HKDF_C)
  659. case -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA):
  660. return( "HKDF - Bad input parameters to function" );
  661. #endif /* MBEDTLS_HKDF_C */
  662. #if defined(MBEDTLS_HMAC_DRBG_C)
  663. case -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG):
  664. return( "HMAC_DRBG - Too many random requested in single call" );
  665. case -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG):
  666. return( "HMAC_DRBG - Input too large (Entropy + additional)" );
  667. case -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR):
  668. return( "HMAC_DRBG - Read/write error in file" );
  669. case -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED):
  670. return( "HMAC_DRBG - The entropy source failed" );
  671. #endif /* MBEDTLS_HMAC_DRBG_C */
  672. #if defined(MBEDTLS_MD2_C)
  673. case -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED):
  674. return( "MD2 - MD2 hardware accelerator failed" );
  675. #endif /* MBEDTLS_MD2_C */
  676. #if defined(MBEDTLS_MD4_C)
  677. case -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED):
  678. return( "MD4 - MD4 hardware accelerator failed" );
  679. #endif /* MBEDTLS_MD4_C */
  680. #if defined(MBEDTLS_MD5_C)
  681. case -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED):
  682. return( "MD5 - MD5 hardware accelerator failed" );
  683. #endif /* MBEDTLS_MD5_C */
  684. #if defined(MBEDTLS_NET_C)
  685. case -(MBEDTLS_ERR_NET_SOCKET_FAILED):
  686. return( "NET - Failed to open a socket" );
  687. case -(MBEDTLS_ERR_NET_CONNECT_FAILED):
  688. return( "NET - The connection to the given server / port failed" );
  689. case -(MBEDTLS_ERR_NET_BIND_FAILED):
  690. return( "NET - Binding of the socket failed" );
  691. case -(MBEDTLS_ERR_NET_LISTEN_FAILED):
  692. return( "NET - Could not listen on the socket" );
  693. case -(MBEDTLS_ERR_NET_ACCEPT_FAILED):
  694. return( "NET - Could not accept the incoming connection" );
  695. case -(MBEDTLS_ERR_NET_RECV_FAILED):
  696. return( "NET - Reading information from the socket failed" );
  697. case -(MBEDTLS_ERR_NET_SEND_FAILED):
  698. return( "NET - Sending information through the socket failed" );
  699. case -(MBEDTLS_ERR_NET_CONN_RESET):
  700. return( "NET - Connection was reset by peer" );
  701. case -(MBEDTLS_ERR_NET_UNKNOWN_HOST):
  702. return( "NET - Failed to get an IP address for the given hostname" );
  703. case -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL):
  704. return( "NET - Buffer is too small to hold the data" );
  705. case -(MBEDTLS_ERR_NET_INVALID_CONTEXT):
  706. return( "NET - The context is invalid, eg because it was free()ed" );
  707. case -(MBEDTLS_ERR_NET_POLL_FAILED):
  708. return( "NET - Polling the net context failed" );
  709. case -(MBEDTLS_ERR_NET_BAD_INPUT_DATA):
  710. return( "NET - Input invalid" );
  711. #endif /* MBEDTLS_NET_C */
  712. #if defined(MBEDTLS_OID_C)
  713. case -(MBEDTLS_ERR_OID_NOT_FOUND):
  714. return( "OID - OID is not found" );
  715. case -(MBEDTLS_ERR_OID_BUF_TOO_SMALL):
  716. return( "OID - output buffer is too small" );
  717. #endif /* MBEDTLS_OID_C */
  718. #if defined(MBEDTLS_PADLOCK_C)
  719. case -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED):
  720. return( "PADLOCK - Input data should be aligned" );
  721. #endif /* MBEDTLS_PADLOCK_C */
  722. #if defined(MBEDTLS_PLATFORM_C)
  723. case -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED):
  724. return( "PLATFORM - Hardware accelerator failed" );
  725. case -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED):
  726. return( "PLATFORM - The requested feature is not supported by the platform" );
  727. #endif /* MBEDTLS_PLATFORM_C */
  728. #if defined(MBEDTLS_POLY1305_C)
  729. case -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA):
  730. return( "POLY1305 - Invalid input parameter(s)" );
  731. case -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE):
  732. return( "POLY1305 - Feature not available. For example, s part of the API is not implemented" );
  733. case -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED):
  734. return( "POLY1305 - Poly1305 hardware accelerator failed" );
  735. #endif /* MBEDTLS_POLY1305_C */
  736. #if defined(MBEDTLS_RIPEMD160_C)
  737. case -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED):
  738. return( "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
  739. #endif /* MBEDTLS_RIPEMD160_C */
  740. #if defined(MBEDTLS_SHA1_C)
  741. case -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED):
  742. return( "SHA1 - SHA-1 hardware accelerator failed" );
  743. case -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA):
  744. return( "SHA1 - SHA-1 input data was malformed" );
  745. #endif /* MBEDTLS_SHA1_C */
  746. #if defined(MBEDTLS_SHA256_C)
  747. case -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED):
  748. return( "SHA256 - SHA-256 hardware accelerator failed" );
  749. case -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA):
  750. return( "SHA256 - SHA-256 input data was malformed" );
  751. #endif /* MBEDTLS_SHA256_C */
  752. #if defined(MBEDTLS_SHA512_C)
  753. case -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED):
  754. return( "SHA512 - SHA-512 hardware accelerator failed" );
  755. case -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA):
  756. return( "SHA512 - SHA-512 input data was malformed" );
  757. #endif /* MBEDTLS_SHA512_C */
  758. #if defined(MBEDTLS_THREADING_C)
  759. case -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE):
  760. return( "THREADING - The selected feature is not available" );
  761. case -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA):
  762. return( "THREADING - Bad input parameters to function" );
  763. case -(MBEDTLS_ERR_THREADING_MUTEX_ERROR):
  764. return( "THREADING - Locking / unlocking / free failed with error code" );
  765. #endif /* MBEDTLS_THREADING_C */
  766. #if defined(MBEDTLS_XTEA_C)
  767. case -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH):
  768. return( "XTEA - The data input has an invalid length" );
  769. case -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED):
  770. return( "XTEA - XTEA hardware accelerator failed" );
  771. #endif /* MBEDTLS_XTEA_C */
  772. /* End Auto-Generated Code. */
  773. default:
  774. break;
  775. }
  776. return NULL;
  777. }
  778. void mbedtls_strerror(int ret, char *buf, size_t buflen)
  779. {
  780. size_t len;
  781. int use_ret;
  782. const char *high_level_error_description = NULL;
  783. const char *low_level_error_description = NULL;
  784. if (buflen == 0) {
  785. return;
  786. }
  787. memset(buf, 0x00, buflen);
  788. if (ret < 0) {
  789. ret = -ret;
  790. }
  791. if (ret & 0xFF80) {
  792. use_ret = ret & 0xFF80;
  793. // Translate high level error code.
  794. high_level_error_description = mbedtls_high_level_strerr(ret);
  795. if (high_level_error_description == NULL) {
  796. mbedtls_snprintf(buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret);
  797. } else {
  798. mbedtls_snprintf(buf, buflen, "%s", high_level_error_description);
  799. }
  800. #if defined(MBEDTLS_SSL_TLS_C)
  801. // Early return in case of a fatal error - do not try to translate low
  802. // level code.
  803. if (use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE)) {
  804. return;
  805. }
  806. #endif /* MBEDTLS_SSL_TLS_C */
  807. }
  808. use_ret = ret & ~0xFF80;
  809. if (use_ret == 0) {
  810. return;
  811. }
  812. // If high level code is present, make a concatenation between both
  813. // error strings.
  814. //
  815. len = strlen(buf);
  816. if (len > 0) {
  817. if (buflen - len < 5) {
  818. return;
  819. }
  820. mbedtls_snprintf(buf + len, buflen - len, " : ");
  821. buf += len + 3;
  822. buflen -= len + 3;
  823. }
  824. // Translate low level error code.
  825. low_level_error_description = mbedtls_low_level_strerr(ret);
  826. if (low_level_error_description == NULL) {
  827. mbedtls_snprintf(buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret);
  828. } else {
  829. mbedtls_snprintf(buf, buflen, "%s", low_level_error_description);
  830. }
  831. }
  832. #else /* MBEDTLS_ERROR_C */
  833. /*
  834. * Provide a dummy implementation when MBEDTLS_ERROR_C is not defined
  835. */
  836. void mbedtls_strerror(int ret, char *buf, size_t buflen)
  837. {
  838. ((void) ret);
  839. if (buflen > 0) {
  840. buf[0] = '\0';
  841. }
  842. }
  843. #endif /* MBEDTLS_ERROR_C */
  844. #if defined(MBEDTLS_TEST_HOOKS)
  845. void (*mbedtls_test_hook_error_add)(int, int, const char *, int);
  846. #endif
  847. #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */