error.c 45 KB

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