error.c 46 KB

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