error.c 40 KB

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