error.c 36 KB

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