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