error.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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_ARIA_C)
  18. #include "mbedtls/aria.h"
  19. #endif
  20. #if defined(MBEDTLS_ASN1_PARSE_C)
  21. #include "mbedtls/asn1.h"
  22. #endif
  23. #if defined(MBEDTLS_BASE64_C)
  24. #include "mbedtls/base64.h"
  25. #endif
  26. #if defined(MBEDTLS_BIGNUM_C)
  27. #include "mbedtls/bignum.h"
  28. #endif
  29. #if defined(MBEDTLS_CAMELLIA_C)
  30. #include "mbedtls/camellia.h"
  31. #endif
  32. #if defined(MBEDTLS_CCM_C)
  33. #include "mbedtls/ccm.h"
  34. #endif
  35. #if defined(MBEDTLS_CHACHA20_C)
  36. #include "mbedtls/chacha20.h"
  37. #endif
  38. #if defined(MBEDTLS_CHACHAPOLY_C)
  39. #include "mbedtls/chachapoly.h"
  40. #endif
  41. #if defined(MBEDTLS_CIPHER_C)
  42. #include "mbedtls/cipher.h"
  43. #endif
  44. #if defined(MBEDTLS_CTR_DRBG_C)
  45. #include "mbedtls/ctr_drbg.h"
  46. #endif
  47. #if defined(MBEDTLS_DES_C)
  48. #include "mbedtls/des.h"
  49. #endif
  50. #if defined(MBEDTLS_DHM_C)
  51. #include "mbedtls/dhm.h"
  52. #endif
  53. #if defined(MBEDTLS_ECP_C)
  54. #include "mbedtls/ecp.h"
  55. #endif
  56. #if defined(MBEDTLS_ENTROPY_C)
  57. #include "mbedtls/entropy.h"
  58. #endif
  59. #if defined(MBEDTLS_ERROR_C)
  60. #include "mbedtls/error.h"
  61. #endif
  62. #if defined(MBEDTLS_PLATFORM_C)
  63. #include "mbedtls/platform.h"
  64. #endif
  65. #if defined(MBEDTLS_GCM_C)
  66. #include "mbedtls/gcm.h"
  67. #endif
  68. #if defined(MBEDTLS_HKDF_C)
  69. #include "mbedtls/hkdf.h"
  70. #endif
  71. #if defined(MBEDTLS_HMAC_DRBG_C)
  72. #include "mbedtls/hmac_drbg.h"
  73. #endif
  74. #if defined(MBEDTLS_LMS_C)
  75. #include "mbedtls/lms.h"
  76. #endif
  77. #if defined(MBEDTLS_MD_C)
  78. #include "mbedtls/md.h"
  79. #endif
  80. #if defined(MBEDTLS_NET_C)
  81. #include "mbedtls/net_sockets.h"
  82. #endif
  83. #if defined(MBEDTLS_OID_C)
  84. #include "mbedtls/oid.h"
  85. #endif
  86. #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
  87. #include "mbedtls/pem.h"
  88. #endif
  89. #if defined(MBEDTLS_PK_C)
  90. #include "mbedtls/pk.h"
  91. #endif
  92. #if defined(MBEDTLS_PKCS12_C)
  93. #include "mbedtls/pkcs12.h"
  94. #endif
  95. #if defined(MBEDTLS_PKCS5_C)
  96. #include "mbedtls/pkcs5.h"
  97. #endif
  98. #if defined(MBEDTLS_PKCS7_C)
  99. #include "mbedtls/pkcs7.h"
  100. #endif
  101. #if defined(MBEDTLS_POLY1305_C)
  102. #include "mbedtls/poly1305.h"
  103. #endif
  104. #if defined(MBEDTLS_RSA_C)
  105. #include "mbedtls/rsa.h"
  106. #endif
  107. #if defined(MBEDTLS_SHA1_C)
  108. #include "mbedtls/sha1.h"
  109. #endif
  110. #if defined(MBEDTLS_SHA256_C)
  111. #include "mbedtls/sha256.h"
  112. #endif
  113. #if defined(MBEDTLS_SHA3_C)
  114. #include "mbedtls/sha3.h"
  115. #endif
  116. #if defined(MBEDTLS_SHA512_C)
  117. #include "mbedtls/sha512.h"
  118. #endif
  119. #if defined(MBEDTLS_SSL_TLS_C)
  120. #include "mbedtls/ssl.h"
  121. #endif
  122. #if defined(MBEDTLS_THREADING_C)
  123. #include "mbedtls/threading.h"
  124. #endif
  125. #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
  126. #include "mbedtls/x509.h"
  127. #endif
  128. const char *mbedtls_high_level_strerr(int error_code)
  129. {
  130. int high_level_error_code;
  131. if (error_code < 0) {
  132. error_code = -error_code;
  133. }
  134. /* Extract the high-level part from the error code. */
  135. high_level_error_code = error_code & 0xFF80;
  136. switch (high_level_error_code) {
  137. /* Begin Auto-Generated Code. */
  138. #if defined(MBEDTLS_CIPHER_C)
  139. case -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE):
  140. return( "CIPHER - The selected feature is not available" );
  141. case -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA):
  142. return( "CIPHER - Bad input parameters" );
  143. case -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED):
  144. return( "CIPHER - Failed to allocate memory" );
  145. case -(MBEDTLS_ERR_CIPHER_INVALID_PADDING):
  146. return( "CIPHER - Input data contains invalid padding and is rejected" );
  147. case -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED):
  148. return( "CIPHER - Decryption of block requires a full block" );
  149. case -(MBEDTLS_ERR_CIPHER_AUTH_FAILED):
  150. return( "CIPHER - Authentication failed (for AEAD modes)" );
  151. case -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT):
  152. return( "CIPHER - The context is invalid. For example, because it was freed" );
  153. #endif /* MBEDTLS_CIPHER_C */
  154. #if defined(MBEDTLS_DHM_C)
  155. case -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA):
  156. return( "DHM - Bad input parameters" );
  157. case -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED):
  158. return( "DHM - Reading of the DHM parameters failed" );
  159. case -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED):
  160. return( "DHM - Making of the DHM parameters failed" );
  161. case -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED):
  162. return( "DHM - Reading of the public values failed" );
  163. case -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED):
  164. return( "DHM - Making of the public value failed" );
  165. case -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED):
  166. return( "DHM - Calculation of the DHM secret failed" );
  167. case -(MBEDTLS_ERR_DHM_INVALID_FORMAT):
  168. return( "DHM - The ASN.1 data is not formatted correctly" );
  169. case -(MBEDTLS_ERR_DHM_ALLOC_FAILED):
  170. return( "DHM - Allocation of memory failed" );
  171. case -(MBEDTLS_ERR_DHM_FILE_IO_ERROR):
  172. return( "DHM - Read or write of file failed" );
  173. case -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED):
  174. return( "DHM - Setting the modulus and generator failed" );
  175. #endif /* MBEDTLS_DHM_C */
  176. #if defined(MBEDTLS_ECP_C)
  177. case -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA):
  178. return( "ECP - Bad input parameters to function" );
  179. case -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL):
  180. return( "ECP - The buffer is too small to write to" );
  181. case -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE):
  182. return( "ECP - The requested feature is not available, for example, the requested curve is not supported" );
  183. case -(MBEDTLS_ERR_ECP_VERIFY_FAILED):
  184. return( "ECP - The signature is not valid" );
  185. case -(MBEDTLS_ERR_ECP_ALLOC_FAILED):
  186. return( "ECP - Memory allocation failed" );
  187. case -(MBEDTLS_ERR_ECP_RANDOM_FAILED):
  188. return( "ECP - Generation of random value, such as ephemeral key, failed" );
  189. case -(MBEDTLS_ERR_ECP_INVALID_KEY):
  190. return( "ECP - Invalid private or public key" );
  191. case -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH):
  192. return( "ECP - The buffer contains a valid signature followed by more data" );
  193. case -(MBEDTLS_ERR_ECP_IN_PROGRESS):
  194. return( "ECP - Operation in progress, call again with the same parameters to continue" );
  195. #endif /* MBEDTLS_ECP_C */
  196. #if defined(MBEDTLS_MD_C)
  197. case -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE):
  198. return( "MD - The selected feature is not available" );
  199. case -(MBEDTLS_ERR_MD_BAD_INPUT_DATA):
  200. return( "MD - Bad input parameters to function" );
  201. case -(MBEDTLS_ERR_MD_ALLOC_FAILED):
  202. return( "MD - Failed to allocate memory" );
  203. case -(MBEDTLS_ERR_MD_FILE_IO_ERROR):
  204. return( "MD - Opening or reading of file failed" );
  205. #endif /* MBEDTLS_MD_C */
  206. #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
  207. case -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT):
  208. return( "PEM - No PEM header or footer found" );
  209. case -(MBEDTLS_ERR_PEM_INVALID_DATA):
  210. return( "PEM - PEM string is not as expected" );
  211. case -(MBEDTLS_ERR_PEM_ALLOC_FAILED):
  212. return( "PEM - Failed to allocate memory" );
  213. case -(MBEDTLS_ERR_PEM_INVALID_ENC_IV):
  214. return( "PEM - RSA IV is not in hex-format" );
  215. case -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG):
  216. return( "PEM - Unsupported key encryption algorithm" );
  217. case -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED):
  218. return( "PEM - Private key password can't be empty" );
  219. case -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH):
  220. return( "PEM - Given private key password does not allow for correct decryption" );
  221. case -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE):
  222. return( "PEM - Unavailable feature, e.g. hashing/encryption combination" );
  223. case -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA):
  224. return( "PEM - Bad input parameters to function" );
  225. #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
  226. #if defined(MBEDTLS_PK_C)
  227. case -(MBEDTLS_ERR_PK_ALLOC_FAILED):
  228. return( "PK - Memory allocation failed" );
  229. case -(MBEDTLS_ERR_PK_TYPE_MISMATCH):
  230. return( "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
  231. case -(MBEDTLS_ERR_PK_BAD_INPUT_DATA):
  232. return( "PK - Bad input parameters to function" );
  233. case -(MBEDTLS_ERR_PK_FILE_IO_ERROR):
  234. return( "PK - Read/write of file failed" );
  235. case -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION):
  236. return( "PK - Unsupported key version" );
  237. case -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT):
  238. return( "PK - Invalid key tag or value" );
  239. case -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG):
  240. return( "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
  241. case -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED):
  242. return( "PK - Private key password can't be empty" );
  243. case -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH):
  244. return( "PK - Given private key password does not allow for correct decryption" );
  245. case -(MBEDTLS_ERR_PK_INVALID_PUBKEY):
  246. return( "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
  247. case -(MBEDTLS_ERR_PK_INVALID_ALG):
  248. return( "PK - The algorithm tag or value is invalid" );
  249. case -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE):
  250. return( "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
  251. case -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE):
  252. return( "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
  253. case -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH):
  254. return( "PK - The buffer contains a valid signature followed by more data" );
  255. case -(MBEDTLS_ERR_PK_BUFFER_TOO_SMALL):
  256. return( "PK - The output buffer is too small" );
  257. #endif /* MBEDTLS_PK_C */
  258. #if defined(MBEDTLS_PKCS12_C)
  259. case -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA):
  260. return( "PKCS12 - Bad input parameters to function" );
  261. case -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE):
  262. return( "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
  263. case -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT):
  264. return( "PKCS12 - PBE ASN.1 data not as expected" );
  265. case -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH):
  266. return( "PKCS12 - Given private key password does not allow for correct decryption" );
  267. #endif /* MBEDTLS_PKCS12_C */
  268. #if defined(MBEDTLS_PKCS5_C)
  269. case -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA):
  270. return( "PKCS5 - Bad input parameters to function" );
  271. case -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT):
  272. return( "PKCS5 - Unexpected ASN.1 data" );
  273. case -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE):
  274. return( "PKCS5 - Requested encryption or digest alg not available" );
  275. case -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH):
  276. return( "PKCS5 - Given private key password does not allow for correct decryption" );
  277. #endif /* MBEDTLS_PKCS5_C */
  278. #if defined(MBEDTLS_PKCS7_C)
  279. case -(MBEDTLS_ERR_PKCS7_INVALID_FORMAT):
  280. return( "PKCS7 - The format is invalid, e.g. different type expected" );
  281. case -(MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE):
  282. return( "PKCS7 - Unavailable feature, e.g. anything other than signed data" );
  283. case -(MBEDTLS_ERR_PKCS7_INVALID_VERSION):
  284. return( "PKCS7 - The PKCS #7 version element is invalid or cannot be parsed" );
  285. case -(MBEDTLS_ERR_PKCS7_INVALID_CONTENT_INFO):
  286. return( "PKCS7 - The PKCS #7 content info is invalid or cannot be parsed" );
  287. case -(MBEDTLS_ERR_PKCS7_INVALID_ALG):
  288. return( "PKCS7 - The algorithm tag or value is invalid or cannot be parsed" );
  289. case -(MBEDTLS_ERR_PKCS7_INVALID_CERT):
  290. return( "PKCS7 - The certificate tag or value is invalid or cannot be parsed" );
  291. case -(MBEDTLS_ERR_PKCS7_INVALID_SIGNATURE):
  292. return( "PKCS7 - Error parsing the signature" );
  293. case -(MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO):
  294. return( "PKCS7 - Error parsing the signer's info" );
  295. case -(MBEDTLS_ERR_PKCS7_BAD_INPUT_DATA):
  296. return( "PKCS7 - Input invalid" );
  297. case -(MBEDTLS_ERR_PKCS7_ALLOC_FAILED):
  298. return( "PKCS7 - Allocation of memory failed" );
  299. case -(MBEDTLS_ERR_PKCS7_VERIFY_FAIL):
  300. return( "PKCS7 - Verification Failed" );
  301. case -(MBEDTLS_ERR_PKCS7_CERT_DATE_INVALID):
  302. return( "PKCS7 - The PKCS #7 date issued/expired dates are invalid" );
  303. #endif /* MBEDTLS_PKCS7_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. #endif /* MBEDTLS_RSA_C */
  324. #if defined(MBEDTLS_SSL_TLS_C)
  325. case -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS):
  326. return( "SSL - A cryptographic operation is in progress. Try again later" );
  327. case -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE):
  328. return( "SSL - The requested feature is not available" );
  329. case -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA):
  330. return( "SSL - Bad input parameters to function" );
  331. case -(MBEDTLS_ERR_SSL_INVALID_MAC):
  332. return( "SSL - Verification of the message MAC failed" );
  333. case -(MBEDTLS_ERR_SSL_INVALID_RECORD):
  334. return( "SSL - An invalid SSL record was received" );
  335. case -(MBEDTLS_ERR_SSL_CONN_EOF):
  336. return( "SSL - The connection indicated an EOF" );
  337. case -(MBEDTLS_ERR_SSL_DECODE_ERROR):
  338. return( "SSL - A message could not be parsed due to a syntactic error" );
  339. case -(MBEDTLS_ERR_SSL_NO_RNG):
  340. return( "SSL - No RNG was provided to the SSL module" );
  341. case -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE):
  342. return( "SSL - No client certification received from the client, but required by the authentication mode" );
  343. case -(MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION):
  344. return( "SSL - Client received an extended server hello containing an unsupported extension" );
  345. case -(MBEDTLS_ERR_SSL_NO_APPLICATION_PROTOCOL):
  346. return( "SSL - No ALPN protocols supported that the client advertises" );
  347. case -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED):
  348. return( "SSL - The own private key or pre-shared key is not set, but needed" );
  349. case -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED):
  350. return( "SSL - No CA Chain is set, but required to operate" );
  351. case -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE):
  352. return( "SSL - An unexpected message was received from our peer" );
  353. case -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE):
  354. return( "SSL - A fatal alert message was received from our peer" );
  355. case -(MBEDTLS_ERR_SSL_UNRECOGNIZED_NAME):
  356. return( "SSL - No server could be identified matching the client's SNI" );
  357. case -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY):
  358. return( "SSL - The peer notified us that the connection is going to be closed" );
  359. case -(MBEDTLS_ERR_SSL_BAD_CERTIFICATE):
  360. return( "SSL - Processing of the Certificate handshake message failed" );
  361. case -(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET):
  362. return( "SSL - A TLS 1.3 NewSessionTicket message has been received" );
  363. case -(MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA):
  364. return( "SSL - Not possible to read early data" );
  365. case -(MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA):
  366. return( "SSL - * Early data has been received as part of an on-going handshake. This error code can be returned only on server side if and only if early data has been enabled by means of the mbedtls_ssl_conf_early_data() API. This error code can then be returned by mbedtls_ssl_handshake(), mbedtls_ssl_handshake_step(), mbedtls_ssl_read() or mbedtls_ssl_write() if early data has been received as part of the handshake sequence they triggered. To read the early data, call mbedtls_ssl_read_early_data()" );
  367. case -(MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA):
  368. return( "SSL - Not possible to write early data" );
  369. case -(MBEDTLS_ERR_SSL_CACHE_ENTRY_NOT_FOUND):
  370. return( "SSL - Cache entry not found" );
  371. case -(MBEDTLS_ERR_SSL_ALLOC_FAILED):
  372. return( "SSL - Memory allocation failed" );
  373. case -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED):
  374. return( "SSL - Hardware acceleration function returned with error" );
  375. case -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH):
  376. return( "SSL - Hardware acceleration function skipped / left alone data" );
  377. case -(MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION):
  378. return( "SSL - Handshake protocol not within min/max boundaries" );
  379. case -(MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE):
  380. return( "SSL - The handshake negotiation failed" );
  381. case -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED):
  382. return( "SSL - Session ticket has expired" );
  383. case -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH):
  384. return( "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
  385. case -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY):
  386. return( "SSL - Unknown identity received (eg, PSK identity)" );
  387. case -(MBEDTLS_ERR_SSL_INTERNAL_ERROR):
  388. return( "SSL - Internal error (eg, unexpected failure in lower-level module)" );
  389. case -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING):
  390. return( "SSL - A counter would wrap (eg, too many messages exchanged)" );
  391. case -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO):
  392. return( "SSL - Unexpected message at ServerHello in renegotiation" );
  393. case -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED):
  394. return( "SSL - DTLS client must retry for hello verification" );
  395. case -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL):
  396. return( "SSL - A buffer is too small to receive or write a message" );
  397. case -(MBEDTLS_ERR_SSL_WANT_READ):
  398. return( "SSL - No data of requested type currently available on underlying transport" );
  399. case -(MBEDTLS_ERR_SSL_WANT_WRITE):
  400. return( "SSL - Connection requires a write call" );
  401. case -(MBEDTLS_ERR_SSL_TIMEOUT):
  402. return( "SSL - The operation timed out" );
  403. case -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT):
  404. return( "SSL - The client initiated a reconnect from the same port" );
  405. case -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD):
  406. return( "SSL - Record header looks valid but is not expected" );
  407. case -(MBEDTLS_ERR_SSL_NON_FATAL):
  408. return( "SSL - The alert message received indicates a non-fatal error" );
  409. case -(MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER):
  410. return( "SSL - A field in a message was incorrect or inconsistent with other fields" );
  411. case -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING):
  412. return( "SSL - Internal-only message signaling that further message-processing should be done" );
  413. case -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS):
  414. return( "SSL - The asynchronous operation is not completed yet" );
  415. case -(MBEDTLS_ERR_SSL_EARLY_MESSAGE):
  416. return( "SSL - Internal-only message signaling that a message arrived early" );
  417. case -(MBEDTLS_ERR_SSL_UNEXPECTED_CID):
  418. return( "SSL - An encrypted DTLS-frame with an unexpected CID was received" );
  419. case -(MBEDTLS_ERR_SSL_VERSION_MISMATCH):
  420. return( "SSL - An operation failed due to an unexpected version or configuration" );
  421. case -(MBEDTLS_ERR_SSL_BAD_CONFIG):
  422. return( "SSL - Invalid value in SSL config" );
  423. case -(MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME):
  424. 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" );
  425. #endif /* MBEDTLS_SSL_TLS_C */
  426. #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
  427. case -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE):
  428. return( "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
  429. case -(MBEDTLS_ERR_X509_UNKNOWN_OID):
  430. return( "X509 - Requested OID is unknown" );
  431. case -(MBEDTLS_ERR_X509_INVALID_FORMAT):
  432. return( "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
  433. case -(MBEDTLS_ERR_X509_INVALID_VERSION):
  434. return( "X509 - The CRT/CRL/CSR version element is invalid" );
  435. case -(MBEDTLS_ERR_X509_INVALID_SERIAL):
  436. return( "X509 - The serial tag or value is invalid" );
  437. case -(MBEDTLS_ERR_X509_INVALID_ALG):
  438. return( "X509 - The algorithm tag or value is invalid" );
  439. case -(MBEDTLS_ERR_X509_INVALID_NAME):
  440. return( "X509 - The name tag or value is invalid" );
  441. case -(MBEDTLS_ERR_X509_INVALID_DATE):
  442. return( "X509 - The date tag or value is invalid" );
  443. case -(MBEDTLS_ERR_X509_INVALID_SIGNATURE):
  444. return( "X509 - The signature tag or value invalid" );
  445. case -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS):
  446. return( "X509 - The extension tag or value is invalid" );
  447. case -(MBEDTLS_ERR_X509_UNKNOWN_VERSION):
  448. return( "X509 - CRT/CRL/CSR has an unsupported version number" );
  449. case -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG):
  450. return( "X509 - Signature algorithm (oid) is unsupported" );
  451. case -(MBEDTLS_ERR_X509_SIG_MISMATCH):
  452. return( "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
  453. case -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED):
  454. return( "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
  455. case -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT):
  456. return( "X509 - Format not recognized as DER or PEM" );
  457. case -(MBEDTLS_ERR_X509_BAD_INPUT_DATA):
  458. return( "X509 - Input invalid" );
  459. case -(MBEDTLS_ERR_X509_ALLOC_FAILED):
  460. return( "X509 - Allocation of memory failed" );
  461. case -(MBEDTLS_ERR_X509_FILE_IO_ERROR):
  462. return( "X509 - Read/write of file failed" );
  463. case -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL):
  464. return( "X509 - Destination buffer is too small" );
  465. case -(MBEDTLS_ERR_X509_FATAL_ERROR):
  466. return( "X509 - A fatal error occurred, eg the chain is too long or the vrfy callback failed" );
  467. #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
  468. /* End Auto-Generated Code. */
  469. default:
  470. break;
  471. }
  472. return NULL;
  473. }
  474. const char *mbedtls_low_level_strerr(int error_code)
  475. {
  476. int low_level_error_code;
  477. if (error_code < 0) {
  478. error_code = -error_code;
  479. }
  480. /* Extract the low-level part from the error code. */
  481. low_level_error_code = error_code & ~0xFF80;
  482. switch (low_level_error_code) {
  483. /* Begin Auto-Generated Code. */
  484. #if defined(MBEDTLS_AES_C)
  485. case -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH):
  486. return( "AES - Invalid key length" );
  487. case -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH):
  488. return( "AES - Invalid data input length" );
  489. case -(MBEDTLS_ERR_AES_BAD_INPUT_DATA):
  490. return( "AES - Invalid input data" );
  491. #endif /* MBEDTLS_AES_C */
  492. #if defined(MBEDTLS_ARIA_C)
  493. case -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA):
  494. return( "ARIA - Bad input data" );
  495. case -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH):
  496. return( "ARIA - Invalid data input length" );
  497. #endif /* MBEDTLS_ARIA_C */
  498. #if defined(MBEDTLS_ASN1_PARSE_C)
  499. case -(MBEDTLS_ERR_ASN1_OUT_OF_DATA):
  500. return( "ASN1 - Out of data when parsing an ASN1 data structure" );
  501. case -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG):
  502. return( "ASN1 - ASN1 tag was of an unexpected value" );
  503. case -(MBEDTLS_ERR_ASN1_INVALID_LENGTH):
  504. return( "ASN1 - Error when trying to determine the length or invalid length" );
  505. case -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH):
  506. return( "ASN1 - Actual length differs from expected length" );
  507. case -(MBEDTLS_ERR_ASN1_INVALID_DATA):
  508. return( "ASN1 - Data is invalid" );
  509. case -(MBEDTLS_ERR_ASN1_ALLOC_FAILED):
  510. return( "ASN1 - Memory allocation failed" );
  511. case -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL):
  512. return( "ASN1 - Buffer too small when writing ASN.1 data structure" );
  513. #endif /* MBEDTLS_ASN1_PARSE_C */
  514. #if defined(MBEDTLS_BASE64_C)
  515. case -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL):
  516. return( "BASE64 - Output buffer too small" );
  517. case -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER):
  518. return( "BASE64 - Invalid character in input" );
  519. #endif /* MBEDTLS_BASE64_C */
  520. #if defined(MBEDTLS_BIGNUM_C)
  521. case -(MBEDTLS_ERR_MPI_FILE_IO_ERROR):
  522. return( "BIGNUM - An error occurred while reading from or writing to a file" );
  523. case -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA):
  524. return( "BIGNUM - Bad input parameters to function" );
  525. case -(MBEDTLS_ERR_MPI_INVALID_CHARACTER):
  526. return( "BIGNUM - There is an invalid character in the digit string" );
  527. case -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL):
  528. return( "BIGNUM - The buffer is too small to write to" );
  529. case -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE):
  530. return( "BIGNUM - The input arguments are negative or result in illegal output" );
  531. case -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO):
  532. return( "BIGNUM - The input argument for division is zero, which is not allowed" );
  533. case -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE):
  534. return( "BIGNUM - The input arguments are not acceptable" );
  535. case -(MBEDTLS_ERR_MPI_ALLOC_FAILED):
  536. return( "BIGNUM - Memory allocation failed" );
  537. #endif /* MBEDTLS_BIGNUM_C */
  538. #if defined(MBEDTLS_CAMELLIA_C)
  539. case -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA):
  540. return( "CAMELLIA - Bad input data" );
  541. case -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH):
  542. return( "CAMELLIA - Invalid data input length" );
  543. #endif /* MBEDTLS_CAMELLIA_C */
  544. #if defined(MBEDTLS_CCM_C)
  545. case -(MBEDTLS_ERR_CCM_BAD_INPUT):
  546. return( "CCM - Bad input parameters to the function" );
  547. case -(MBEDTLS_ERR_CCM_AUTH_FAILED):
  548. return( "CCM - Authenticated decryption failed" );
  549. #endif /* MBEDTLS_CCM_C */
  550. #if defined(MBEDTLS_CHACHA20_C)
  551. case -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA):
  552. return( "CHACHA20 - Invalid input parameter(s)" );
  553. #endif /* MBEDTLS_CHACHA20_C */
  554. #if defined(MBEDTLS_CHACHAPOLY_C)
  555. case -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE):
  556. return( "CHACHAPOLY - The requested operation is not permitted in the current state" );
  557. case -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED):
  558. return( "CHACHAPOLY - Authenticated decryption failed: data was not authentic" );
  559. #endif /* MBEDTLS_CHACHAPOLY_C */
  560. #if defined(MBEDTLS_CTR_DRBG_C)
  561. case -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED):
  562. return( "CTR_DRBG - The entropy source failed" );
  563. case -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG):
  564. return( "CTR_DRBG - The requested random buffer length is too big" );
  565. case -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG):
  566. return( "CTR_DRBG - The input (entropy + additional data) is too large" );
  567. case -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR):
  568. return( "CTR_DRBG - Read or write error in file" );
  569. #endif /* MBEDTLS_CTR_DRBG_C */
  570. #if defined(MBEDTLS_DES_C)
  571. case -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH):
  572. return( "DES - The data input has an invalid length" );
  573. #endif /* MBEDTLS_DES_C */
  574. #if defined(MBEDTLS_ENTROPY_C)
  575. case -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED):
  576. return( "ENTROPY - Critical entropy source failure" );
  577. case -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES):
  578. return( "ENTROPY - No more sources can be added" );
  579. case -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED):
  580. return( "ENTROPY - No sources have been added to poll" );
  581. case -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE):
  582. return( "ENTROPY - No strong sources have been added to poll" );
  583. case -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR):
  584. return( "ENTROPY - Read/write error in file" );
  585. #endif /* MBEDTLS_ENTROPY_C */
  586. #if defined(MBEDTLS_ERROR_C)
  587. case -(MBEDTLS_ERR_ERROR_GENERIC_ERROR):
  588. return( "ERROR - Generic error" );
  589. case -(MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED):
  590. return( "ERROR - This is a bug in the library" );
  591. #endif /* MBEDTLS_ERROR_C */
  592. #if defined(MBEDTLS_PLATFORM_C)
  593. case -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED):
  594. return( "PLATFORM - Hardware accelerator failed" );
  595. case -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED):
  596. return( "PLATFORM - The requested feature is not supported by the platform" );
  597. #endif /* MBEDTLS_PLATFORM_C */
  598. #if defined(MBEDTLS_GCM_C)
  599. case -(MBEDTLS_ERR_GCM_AUTH_FAILED):
  600. return( "GCM - Authenticated decryption failed" );
  601. case -(MBEDTLS_ERR_GCM_BAD_INPUT):
  602. return( "GCM - Bad input parameters to function" );
  603. case -(MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL):
  604. return( "GCM - An output buffer is too small" );
  605. #endif /* MBEDTLS_GCM_C */
  606. #if defined(MBEDTLS_HKDF_C)
  607. case -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA):
  608. return( "HKDF - Bad input parameters to function" );
  609. #endif /* MBEDTLS_HKDF_C */
  610. #if defined(MBEDTLS_HMAC_DRBG_C)
  611. case -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG):
  612. return( "HMAC_DRBG - Too many random requested in single call" );
  613. case -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG):
  614. return( "HMAC_DRBG - Input too large (Entropy + additional)" );
  615. case -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR):
  616. return( "HMAC_DRBG - Read/write error in file" );
  617. case -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED):
  618. return( "HMAC_DRBG - The entropy source failed" );
  619. #endif /* MBEDTLS_HMAC_DRBG_C */
  620. #if defined(MBEDTLS_LMS_C)
  621. case -(MBEDTLS_ERR_LMS_BAD_INPUT_DATA):
  622. return( "LMS - Bad data has been input to an LMS function" );
  623. case -(MBEDTLS_ERR_LMS_OUT_OF_PRIVATE_KEYS):
  624. return( "LMS - Specified LMS key has utilised all of its private keys" );
  625. case -(MBEDTLS_ERR_LMS_VERIFY_FAILED):
  626. return( "LMS - LMS signature verification failed" );
  627. case -(MBEDTLS_ERR_LMS_ALLOC_FAILED):
  628. return( "LMS - LMS failed to allocate space for a private key" );
  629. case -(MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL):
  630. return( "LMS - Input/output buffer is too small to contain requited data" );
  631. #endif /* MBEDTLS_LMS_C */
  632. #if defined(MBEDTLS_NET_C)
  633. case -(MBEDTLS_ERR_NET_SOCKET_FAILED):
  634. return( "NET - Failed to open a socket" );
  635. case -(MBEDTLS_ERR_NET_CONNECT_FAILED):
  636. return( "NET - The connection to the given server / port failed" );
  637. case -(MBEDTLS_ERR_NET_BIND_FAILED):
  638. return( "NET - Binding of the socket failed" );
  639. case -(MBEDTLS_ERR_NET_LISTEN_FAILED):
  640. return( "NET - Could not listen on the socket" );
  641. case -(MBEDTLS_ERR_NET_ACCEPT_FAILED):
  642. return( "NET - Could not accept the incoming connection" );
  643. case -(MBEDTLS_ERR_NET_RECV_FAILED):
  644. return( "NET - Reading information from the socket failed" );
  645. case -(MBEDTLS_ERR_NET_SEND_FAILED):
  646. return( "NET - Sending information through the socket failed" );
  647. case -(MBEDTLS_ERR_NET_CONN_RESET):
  648. return( "NET - Connection was reset by peer" );
  649. case -(MBEDTLS_ERR_NET_UNKNOWN_HOST):
  650. return( "NET - Failed to get an IP address for the given hostname" );
  651. case -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL):
  652. return( "NET - Buffer is too small to hold the data" );
  653. case -(MBEDTLS_ERR_NET_INVALID_CONTEXT):
  654. return( "NET - The context is invalid, eg because it was free()ed" );
  655. case -(MBEDTLS_ERR_NET_POLL_FAILED):
  656. return( "NET - Polling the net context failed" );
  657. case -(MBEDTLS_ERR_NET_BAD_INPUT_DATA):
  658. return( "NET - Input invalid" );
  659. #endif /* MBEDTLS_NET_C */
  660. #if defined(MBEDTLS_OID_C)
  661. case -(MBEDTLS_ERR_OID_NOT_FOUND):
  662. return( "OID - OID is not found" );
  663. case -(MBEDTLS_ERR_OID_BUF_TOO_SMALL):
  664. return( "OID - output buffer is too small" );
  665. #endif /* MBEDTLS_OID_C */
  666. #if defined(MBEDTLS_POLY1305_C)
  667. case -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA):
  668. return( "POLY1305 - Invalid input parameter(s)" );
  669. #endif /* MBEDTLS_POLY1305_C */
  670. #if defined(MBEDTLS_SHA1_C)
  671. case -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA):
  672. return( "SHA1 - SHA-1 input data was malformed" );
  673. #endif /* MBEDTLS_SHA1_C */
  674. #if defined(MBEDTLS_SHA256_C)
  675. case -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA):
  676. return( "SHA256 - SHA-256 input data was malformed" );
  677. #endif /* MBEDTLS_SHA256_C */
  678. #if defined(MBEDTLS_SHA3_C)
  679. case -(MBEDTLS_ERR_SHA3_BAD_INPUT_DATA):
  680. return( "SHA3 - SHA-3 input data was malformed" );
  681. #endif /* MBEDTLS_SHA3_C */
  682. #if defined(MBEDTLS_SHA512_C)
  683. case -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA):
  684. return( "SHA512 - SHA-512 input data was malformed" );
  685. #endif /* MBEDTLS_SHA512_C */
  686. #if defined(MBEDTLS_THREADING_C)
  687. case -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA):
  688. return( "THREADING - Bad input parameters to function" );
  689. case -(MBEDTLS_ERR_THREADING_MUTEX_ERROR):
  690. return( "THREADING - Locking / unlocking / free failed with error code" );
  691. #endif /* MBEDTLS_THREADING_C */
  692. /* End Auto-Generated Code. */
  693. default:
  694. break;
  695. }
  696. return NULL;
  697. }
  698. void mbedtls_strerror(int ret, char *buf, size_t buflen)
  699. {
  700. size_t len;
  701. int use_ret;
  702. const char *high_level_error_description = NULL;
  703. const char *low_level_error_description = NULL;
  704. if (buflen == 0) {
  705. return;
  706. }
  707. memset(buf, 0x00, buflen);
  708. if (ret < 0) {
  709. ret = -ret;
  710. }
  711. if (ret & 0xFF80) {
  712. use_ret = ret & 0xFF80;
  713. // Translate high level error code.
  714. high_level_error_description = mbedtls_high_level_strerr(ret);
  715. if (high_level_error_description == NULL) {
  716. mbedtls_snprintf(buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret);
  717. } else {
  718. mbedtls_snprintf(buf, buflen, "%s", high_level_error_description);
  719. }
  720. #if defined(MBEDTLS_SSL_TLS_C)
  721. // Early return in case of a fatal error - do not try to translate low
  722. // level code.
  723. if (use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE)) {
  724. return;
  725. }
  726. #endif /* MBEDTLS_SSL_TLS_C */
  727. }
  728. use_ret = ret & ~0xFF80;
  729. if (use_ret == 0) {
  730. return;
  731. }
  732. // If high level code is present, make a concatenation between both
  733. // error strings.
  734. //
  735. len = strlen(buf);
  736. if (len > 0) {
  737. if (buflen - len < 5) {
  738. return;
  739. }
  740. mbedtls_snprintf(buf + len, buflen - len, " : ");
  741. buf += len + 3;
  742. buflen -= len + 3;
  743. }
  744. // Translate low level error code.
  745. low_level_error_description = mbedtls_low_level_strerr(ret);
  746. if (low_level_error_description == NULL) {
  747. mbedtls_snprintf(buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret);
  748. } else {
  749. mbedtls_snprintf(buf, buflen, "%s", low_level_error_description);
  750. }
  751. }
  752. #else /* MBEDTLS_ERROR_C */
  753. /*
  754. * Provide a dummy implementation when MBEDTLS_ERROR_C is not defined
  755. */
  756. void mbedtls_strerror(int ret, char *buf, size_t buflen)
  757. {
  758. ((void) ret);
  759. if (buflen > 0) {
  760. buf[0] = '\0';
  761. }
  762. }
  763. #endif /* MBEDTLS_ERROR_C */
  764. #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */