error.c 36 KB

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