error.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * Error message information
  3. *
  4. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  5. * SPDX-License-Identifier: GPL-2.0
  6. *
  7. * This program 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. * This program 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 along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * This file is part of mbed TLS (https://tls.mbed.org)
  22. */
  23. #if !defined(MBEDTLS_CONFIG_FILE)
  24. #include "mbedtls/config.h"
  25. #else
  26. #include MBEDTLS_CONFIG_FILE
  27. #endif
  28. #if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
  29. #include "mbedtls/error.h"
  30. #include <string.h>
  31. #endif
  32. #if defined(MBEDTLS_PLATFORM_C)
  33. #include "mbedtls/platform.h"
  34. #else
  35. #define mbedtls_snprintf snprintf
  36. #define mbedtls_time_t time_t
  37. #endif
  38. #if defined(MBEDTLS_ERROR_C)
  39. #include <stdio.h>
  40. #if defined(MBEDTLS_AES_C)
  41. #include "mbedtls/aes.h"
  42. #endif
  43. #if defined(MBEDTLS_BASE64_C)
  44. #include "mbedtls/base64.h"
  45. #endif
  46. #if defined(MBEDTLS_BIGNUM_C)
  47. #include "mbedtls/bignum.h"
  48. #endif
  49. #if defined(MBEDTLS_BLOWFISH_C)
  50. #include "mbedtls/blowfish.h"
  51. #endif
  52. #if defined(MBEDTLS_CAMELLIA_C)
  53. #include "mbedtls/camellia.h"
  54. #endif
  55. #if defined(MBEDTLS_CCM_C)
  56. #include "mbedtls/ccm.h"
  57. #endif
  58. #if defined(MBEDTLS_CIPHER_C)
  59. #include "mbedtls/cipher.h"
  60. #endif
  61. #if defined(MBEDTLS_CTR_DRBG_C)
  62. #include "mbedtls/ctr_drbg.h"
  63. #endif
  64. #if defined(MBEDTLS_DES_C)
  65. #include "mbedtls/des.h"
  66. #endif
  67. #if defined(MBEDTLS_DHM_C)
  68. #include "mbedtls/dhm.h"
  69. #endif
  70. #if defined(MBEDTLS_ECP_C)
  71. #include "mbedtls/ecp.h"
  72. #endif
  73. #if defined(MBEDTLS_ENTROPY_C)
  74. #include "mbedtls/entropy.h"
  75. #endif
  76. #if defined(MBEDTLS_GCM_C)
  77. #include "mbedtls/gcm.h"
  78. #endif
  79. #if defined(MBEDTLS_HMAC_DRBG_C)
  80. #include "mbedtls/hmac_drbg.h"
  81. #endif
  82. #if defined(MBEDTLS_MD_C)
  83. #include "mbedtls/md.h"
  84. #endif
  85. #if defined(MBEDTLS_NET_C)
  86. #include "mbedtls/net_sockets.h"
  87. #endif
  88. #if defined(MBEDTLS_OID_C)
  89. #include "mbedtls/oid.h"
  90. #endif
  91. #if defined(MBEDTLS_PADLOCK_C)
  92. #include "mbedtls/padlock.h"
  93. #endif
  94. #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
  95. #include "mbedtls/pem.h"
  96. #endif
  97. #if defined(MBEDTLS_PK_C)
  98. #include "mbedtls/pk.h"
  99. #endif
  100. #if defined(MBEDTLS_PKCS12_C)
  101. #include "mbedtls/pkcs12.h"
  102. #endif
  103. #if defined(MBEDTLS_PKCS5_C)
  104. #include "mbedtls/pkcs5.h"
  105. #endif
  106. #if defined(MBEDTLS_RSA_C)
  107. #include "mbedtls/rsa.h"
  108. #endif
  109. #if defined(MBEDTLS_SSL_TLS_C)
  110. #include "mbedtls/ssl.h"
  111. #endif
  112. #if defined(MBEDTLS_THREADING_C)
  113. #include "mbedtls/threading.h"
  114. #endif
  115. #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
  116. #include "mbedtls/x509.h"
  117. #endif
  118. #if defined(MBEDTLS_XTEA_C)
  119. #include "mbedtls/xtea.h"
  120. #endif
  121. void mbedtls_strerror( int ret, char *buf, size_t buflen )
  122. {
  123. size_t len;
  124. int use_ret;
  125. if( buflen == 0 )
  126. return;
  127. memset( buf, 0x00, buflen );
  128. if( ret < 0 )
  129. ret = -ret;
  130. if( ret & 0xFF80 )
  131. {
  132. use_ret = ret & 0xFF80;
  133. // High level error codes
  134. //
  135. // BEGIN generated code
  136. #if defined(MBEDTLS_CIPHER_C)
  137. if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
  138. mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
  139. if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
  140. mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
  141. if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
  142. mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
  143. if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
  144. mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
  145. if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
  146. mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
  147. if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
  148. mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
  149. if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
  150. mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid, eg because it was free()ed" );
  151. #endif /* MBEDTLS_CIPHER_C */
  152. #if defined(MBEDTLS_DHM_C)
  153. if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
  154. mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters to function" );
  155. if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
  156. mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
  157. if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
  158. mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
  159. if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
  160. mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
  161. if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
  162. mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
  163. if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
  164. mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
  165. if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
  166. mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
  167. if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
  168. mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
  169. if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
  170. mbedtls_snprintf( buf, buflen, "DHM - Read/write of file failed" );
  171. #endif /* MBEDTLS_DHM_C */
  172. #if defined(MBEDTLS_ECP_C)
  173. if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
  174. mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
  175. if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
  176. mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
  177. if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
  178. mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
  179. if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
  180. mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
  181. if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
  182. mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
  183. if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
  184. mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
  185. if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
  186. mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
  187. if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
  188. mbedtls_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
  189. #endif /* MBEDTLS_ECP_C */
  190. #if defined(MBEDTLS_MD_C)
  191. if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
  192. mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
  193. if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
  194. mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
  195. if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
  196. mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
  197. if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
  198. mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
  199. #endif /* MBEDTLS_MD_C */
  200. #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
  201. if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
  202. mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
  203. if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
  204. mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
  205. if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
  206. mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
  207. if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
  208. mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
  209. if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
  210. mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
  211. if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
  212. mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
  213. if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
  214. mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
  215. if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
  216. mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
  217. if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
  218. mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
  219. #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
  220. #if defined(MBEDTLS_PK_C)
  221. if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
  222. mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
  223. if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
  224. mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
  225. if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
  226. mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
  227. if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
  228. mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
  229. if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
  230. mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
  231. if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
  232. mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
  233. if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
  234. mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
  235. if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
  236. mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
  237. if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
  238. mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
  239. if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
  240. mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
  241. if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
  242. mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
  243. if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
  244. mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
  245. if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
  246. mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
  247. if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
  248. mbedtls_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
  249. #endif /* MBEDTLS_PK_C */
  250. #if defined(MBEDTLS_PKCS12_C)
  251. if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
  252. mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
  253. if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
  254. mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
  255. if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
  256. mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
  257. if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
  258. mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
  259. #endif /* MBEDTLS_PKCS12_C */
  260. #if defined(MBEDTLS_PKCS5_C)
  261. if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
  262. mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
  263. if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
  264. mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
  265. if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
  266. mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
  267. if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
  268. mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
  269. #endif /* MBEDTLS_PKCS5_C */
  270. #if defined(MBEDTLS_RSA_C)
  271. if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
  272. mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
  273. if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
  274. mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
  275. if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
  276. mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
  277. if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
  278. mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the library's validity check" );
  279. if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
  280. mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
  281. if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
  282. mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
  283. if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
  284. mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
  285. if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
  286. mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
  287. if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
  288. mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
  289. #endif /* MBEDTLS_RSA_C */
  290. #if defined(MBEDTLS_SSL_TLS_C)
  291. if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
  292. mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
  293. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
  294. mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
  295. if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
  296. mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
  297. if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
  298. mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
  299. if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
  300. mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
  301. if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
  302. mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
  303. if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
  304. mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
  305. if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
  306. mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
  307. if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
  308. mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
  309. if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
  310. mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
  311. if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
  312. mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
  313. if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
  314. mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
  315. if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
  316. mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
  317. if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
  318. mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
  319. if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
  320. {
  321. mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
  322. return;
  323. }
  324. if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
  325. mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
  326. if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
  327. mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
  328. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
  329. mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
  330. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
  331. mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
  332. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
  333. mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
  334. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
  335. mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
  336. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
  337. mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
  338. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
  339. mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
  340. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
  341. mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
  342. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
  343. mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
  344. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
  345. mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
  346. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
  347. mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
  348. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
  349. mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
  350. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
  351. mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
  352. if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
  353. mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
  354. if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
  355. mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
  356. if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
  357. mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
  358. if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
  359. mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
  360. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
  361. mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
  362. if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
  363. mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
  364. if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
  365. mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
  366. if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
  367. mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
  368. if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
  369. mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
  370. if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
  371. mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
  372. if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
  373. mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
  374. if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
  375. mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
  376. if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
  377. mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
  378. if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
  379. mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
  380. if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
  381. mbedtls_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
  382. if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
  383. mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" );
  384. if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
  385. mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
  386. if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
  387. mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
  388. if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
  389. mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
  390. if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
  391. mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
  392. if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
  393. mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
  394. if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
  395. mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
  396. #endif /* MBEDTLS_SSL_TLS_C */
  397. #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
  398. if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
  399. mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
  400. if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
  401. mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
  402. if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
  403. mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
  404. if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
  405. mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
  406. if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
  407. mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
  408. if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
  409. mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
  410. if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
  411. mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
  412. if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
  413. mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
  414. if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
  415. mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
  416. if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
  417. mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
  418. if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
  419. mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
  420. if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
  421. mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
  422. if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
  423. mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
  424. if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
  425. mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
  426. if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
  427. mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
  428. if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
  429. mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
  430. if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
  431. mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
  432. if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
  433. mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
  434. if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
  435. mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
  436. #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
  437. // END generated code
  438. if( strlen( buf ) == 0 )
  439. mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
  440. }
  441. use_ret = ret & ~0xFF80;
  442. if( use_ret == 0 )
  443. return;
  444. // If high level code is present, make a concatenation between both
  445. // error strings.
  446. //
  447. len = strlen( buf );
  448. if( len > 0 )
  449. {
  450. if( buflen - len < 5 )
  451. return;
  452. mbedtls_snprintf( buf + len, buflen - len, " : " );
  453. buf += len + 3;
  454. buflen -= len + 3;
  455. }
  456. // Low level error codes
  457. //
  458. // BEGIN generated code
  459. #if defined(MBEDTLS_AES_C)
  460. if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
  461. mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
  462. if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
  463. mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
  464. #endif /* MBEDTLS_AES_C */
  465. #if defined(MBEDTLS_ASN1_PARSE_C)
  466. if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
  467. mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
  468. if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
  469. mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
  470. if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
  471. mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
  472. if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
  473. mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
  474. if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
  475. mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
  476. if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
  477. mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
  478. if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
  479. mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
  480. #endif /* MBEDTLS_ASN1_PARSE_C */
  481. #if defined(MBEDTLS_BASE64_C)
  482. if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
  483. mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
  484. if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
  485. mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
  486. #endif /* MBEDTLS_BASE64_C */
  487. #if defined(MBEDTLS_BIGNUM_C)
  488. if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
  489. mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
  490. if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
  491. mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
  492. if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
  493. mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
  494. if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
  495. mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
  496. if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
  497. mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
  498. if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
  499. mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
  500. if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
  501. mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
  502. if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
  503. mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
  504. #endif /* MBEDTLS_BIGNUM_C */
  505. #if defined(MBEDTLS_BLOWFISH_C)
  506. if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
  507. mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
  508. if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
  509. mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
  510. #endif /* MBEDTLS_BLOWFISH_C */
  511. #if defined(MBEDTLS_CAMELLIA_C)
  512. if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
  513. mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
  514. if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
  515. mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
  516. #endif /* MBEDTLS_CAMELLIA_C */
  517. #if defined(MBEDTLS_CCM_C)
  518. if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
  519. mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to function" );
  520. if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
  521. mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
  522. #endif /* MBEDTLS_CCM_C */
  523. #if defined(MBEDTLS_CTR_DRBG_C)
  524. if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
  525. mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
  526. if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
  527. mbedtls_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
  528. if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
  529. mbedtls_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
  530. if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
  531. mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
  532. #endif /* MBEDTLS_CTR_DRBG_C */
  533. #if defined(MBEDTLS_DES_C)
  534. if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
  535. mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
  536. #endif /* MBEDTLS_DES_C */
  537. #if defined(MBEDTLS_ENTROPY_C)
  538. if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
  539. mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
  540. if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
  541. mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
  542. if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
  543. mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
  544. if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
  545. mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
  546. if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
  547. mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
  548. #endif /* MBEDTLS_ENTROPY_C */
  549. #if defined(MBEDTLS_GCM_C)
  550. if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
  551. mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
  552. if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
  553. mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
  554. #endif /* MBEDTLS_GCM_C */
  555. #if defined(MBEDTLS_HMAC_DRBG_C)
  556. if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
  557. mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
  558. if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
  559. mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
  560. if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
  561. mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
  562. if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
  563. mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
  564. #endif /* MBEDTLS_HMAC_DRBG_C */
  565. #if defined(MBEDTLS_NET_C)
  566. if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
  567. mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
  568. if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
  569. mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
  570. if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
  571. mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
  572. if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
  573. mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
  574. if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
  575. mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
  576. if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
  577. mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
  578. if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
  579. mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
  580. if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
  581. mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
  582. if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
  583. mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
  584. if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
  585. mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
  586. if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
  587. mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
  588. #endif /* MBEDTLS_NET_C */
  589. #if defined(MBEDTLS_OID_C)
  590. if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
  591. mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
  592. if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
  593. mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
  594. #endif /* MBEDTLS_OID_C */
  595. #if defined(MBEDTLS_PADLOCK_C)
  596. if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
  597. mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
  598. #endif /* MBEDTLS_PADLOCK_C */
  599. #if defined(MBEDTLS_THREADING_C)
  600. if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
  601. mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
  602. if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
  603. mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
  604. if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
  605. mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
  606. #endif /* MBEDTLS_THREADING_C */
  607. #if defined(MBEDTLS_XTEA_C)
  608. if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
  609. mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
  610. #endif /* MBEDTLS_XTEA_C */
  611. // END generated code
  612. if( strlen( buf ) != 0 )
  613. return;
  614. mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
  615. }
  616. #else /* MBEDTLS_ERROR_C */
  617. #if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
  618. /*
  619. * Provide an non-function in case MBEDTLS_ERROR_C is not defined
  620. */
  621. void mbedtls_strerror( int ret, char *buf, size_t buflen )
  622. {
  623. ((void) ret);
  624. if( buflen > 0 )
  625. buf[0] = '\0';
  626. }
  627. #endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
  628. #endif /* MBEDTLS_ERROR_C */