error.c 41 KB

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