00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "polarssl/config.h"
00027
00028 #if defined(POLARSSL_ERROR_C)
00029
00030 #include "polarssl/error.h"
00031
00032 #if defined(POLARSSL_AES_C)
00033 #include "polarssl/aes.h"
00034 #endif
00035
00036 #if defined(POLARSSL_BASE64_C)
00037 #include "polarssl/base64.h"
00038 #endif
00039
00040 #if defined(POLARSSL_BIGNUM_C)
00041 #include "polarssl/bignum.h"
00042 #endif
00043
00044 #if defined(POLARSSL_BLOWFISH_C)
00045 #include "polarssl/blowfish.h"
00046 #endif
00047
00048 #if defined(POLARSSL_CAMELLIA_C)
00049 #include "polarssl/camellia.h"
00050 #endif
00051
00052 #if defined(POLARSSL_CIPHER_C)
00053 #include "polarssl/cipher.h"
00054 #endif
00055
00056 #if defined(POLARSSL_CTR_DRBG_C)
00057 #include "polarssl/ctr_drbg.h"
00058 #endif
00059
00060 #if defined(POLARSSL_DES_C)
00061 #include "polarssl/des.h"
00062 #endif
00063
00064 #if defined(POLARSSL_DHM_C)
00065 #include "polarssl/dhm.h"
00066 #endif
00067
00068 #if defined(POLARSSL_ECP_C)
00069 #include "polarssl/ecp.h"
00070 #endif
00071
00072 #if defined(POLARSSL_ENTROPY_C)
00073 #include "polarssl/entropy.h"
00074 #endif
00075
00076 #if defined(POLARSSL_GCM_C)
00077 #include "polarssl/gcm.h"
00078 #endif
00079
00080 #if defined(POLARSSL_MD_C)
00081 #include "polarssl/md.h"
00082 #endif
00083
00084 #if defined(POLARSSL_MD2_C)
00085 #include "polarssl/md2.h"
00086 #endif
00087
00088 #if defined(POLARSSL_MD4_C)
00089 #include "polarssl/md4.h"
00090 #endif
00091
00092 #if defined(POLARSSL_MD5_C)
00093 #include "polarssl/md5.h"
00094 #endif
00095
00096 #if defined(POLARSSL_NET_C)
00097 #include "polarssl/net.h"
00098 #endif
00099
00100 #if defined(POLARSSL_OID_C)
00101 #include "polarssl/oid.h"
00102 #endif
00103
00104 #if defined(POLARSSL_PADLOCK_C)
00105 #include "polarssl/padlock.h"
00106 #endif
00107
00108 #if defined(POLARSSL_PBKDF2_C)
00109 #include "polarssl/pbkdf2.h"
00110 #endif
00111
00112 #if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
00113 #include "polarssl/pem.h"
00114 #endif
00115
00116 #if defined(POLARSSL_PK_C)
00117 #include "polarssl/pk.h"
00118 #endif
00119
00120 #if defined(POLARSSL_PKCS12_C)
00121 #include "polarssl/pkcs12.h"
00122 #endif
00123
00124 #if defined(POLARSSL_PKCS5_C)
00125 #include "polarssl/pkcs5.h"
00126 #endif
00127
00128 #if defined(POLARSSL_RSA_C)
00129 #include "polarssl/rsa.h"
00130 #endif
00131
00132 #if defined(POLARSSL_SHA1_C)
00133 #include "polarssl/sha1.h"
00134 #endif
00135
00136 #if defined(POLARSSL_SHA256_C)
00137 #include "polarssl/sha256.h"
00138 #endif
00139
00140 #if defined(POLARSSL_SHA512_C)
00141 #include "polarssl/sha512.h"
00142 #endif
00143
00144 #if defined(POLARSSL_SSL_TLS_C)
00145 #include "polarssl/ssl.h"
00146 #endif
00147
00148 #if defined(POLARSSL_THREADING_C)
00149 #include "polarssl/threading.h"
00150 #endif
00151
00152 #if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
00153 #include "polarssl/x509.h"
00154 #endif
00155
00156 #if defined(POLARSSL_XTEA_C)
00157 #include "polarssl/xtea.h"
00158 #endif
00159
00160
00161 #include <string.h>
00162
00163 #if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
00164 !defined(EFI32)
00165 #define snprintf _snprintf
00166 #endif
00167
00168 void polarssl_strerror( int ret, char *buf, size_t buflen )
00169 {
00170 size_t len;
00171 int use_ret;
00172
00173 if( buflen == 0 )
00174 return;
00175
00176 memset( buf, 0x00, buflen );
00177
00178 buflen -= 1;
00179
00180 if( ret < 0 )
00181 ret = -ret;
00182
00183 if( ret & 0xFF80 )
00184 {
00185 use_ret = ret & 0xFF80;
00186
00187
00188
00189 #if defined(POLARSSL_CIPHER_C)
00190 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
00191 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
00192 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
00193 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
00194 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
00195 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
00196 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
00197 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
00198 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
00199 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
00200 if( use_ret == -(POLARSSL_ERR_CIPHER_AUTH_FAILED) )
00201 snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
00202 #endif
00203
00204 #if defined(POLARSSL_DHM_C)
00205 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
00206 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
00207 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
00208 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
00209 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
00210 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
00211 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
00212 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
00213 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
00214 snprintf( buf, buflen, "DHM - Making of the public value failed" );
00215 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
00216 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
00217 if( use_ret == -(POLARSSL_ERR_DHM_INVALID_FORMAT) )
00218 snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
00219 if( use_ret == -(POLARSSL_ERR_DHM_MALLOC_FAILED) )
00220 snprintf( buf, buflen, "DHM - Allocation of memory failed" );
00221 if( use_ret == -(POLARSSL_ERR_DHM_FILE_IO_ERROR) )
00222 snprintf( buf, buflen, "DHM - Read/write of file failed" );
00223 #endif
00224
00225 #if defined(POLARSSL_ECP_C)
00226 if( use_ret == -(POLARSSL_ERR_ECP_BAD_INPUT_DATA) )
00227 snprintf( buf, buflen, "ECP - Bad input parameters to function" );
00228 if( use_ret == -(POLARSSL_ERR_ECP_BUFFER_TOO_SMALL) )
00229 snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
00230 if( use_ret == -(POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE) )
00231 snprintf( buf, buflen, "ECP - Requested curve not available" );
00232 if( use_ret == -(POLARSSL_ERR_ECP_VERIFY_FAILED) )
00233 snprintf( buf, buflen, "ECP - The signature is not valid" );
00234 if( use_ret == -(POLARSSL_ERR_ECP_MALLOC_FAILED) )
00235 snprintf( buf, buflen, "ECP - Memory allocation failed" );
00236 if( use_ret == -(POLARSSL_ERR_ECP_RANDOM_FAILED) )
00237 snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
00238 if( use_ret == -(POLARSSL_ERR_ECP_INVALID_KEY) )
00239 snprintf( buf, buflen, "ECP - Invalid private or public key" );
00240 #endif
00241
00242 #if defined(POLARSSL_MD_C)
00243 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
00244 snprintf( buf, buflen, "MD - The selected feature is not available" );
00245 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
00246 snprintf( buf, buflen, "MD - Bad input parameters to function" );
00247 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
00248 snprintf( buf, buflen, "MD - Failed to allocate memory" );
00249 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
00250 snprintf( buf, buflen, "MD - Opening or reading of file failed" );
00251 #endif
00252
00253 #if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
00254 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
00255 snprintf( buf, buflen, "PEM - No PEM header or footer found" );
00256 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
00257 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
00258 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
00259 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
00260 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
00261 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
00262 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
00263 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
00264 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
00265 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
00266 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
00267 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
00268 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
00269 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
00270 if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
00271 snprintf( buf, buflen, "PEM - Bad input parameters to function" );
00272 #endif
00273
00274 #if defined(POLARSSL_PK_C)
00275 if( use_ret == -(POLARSSL_ERR_PK_MALLOC_FAILED) )
00276 snprintf( buf, buflen, "PK - Memory alloation failed" );
00277 if( use_ret == -(POLARSSL_ERR_PK_TYPE_MISMATCH) )
00278 snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
00279 if( use_ret == -(POLARSSL_ERR_PK_BAD_INPUT_DATA) )
00280 snprintf( buf, buflen, "PK - Bad input parameters to function" );
00281 if( use_ret == -(POLARSSL_ERR_PK_FILE_IO_ERROR) )
00282 snprintf( buf, buflen, "PK - Read/write of file failed" );
00283 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_VERSION) )
00284 snprintf( buf, buflen, "PK - Unsupported key version" );
00285 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_FORMAT) )
00286 snprintf( buf, buflen, "PK - Invalid key tag or value" );
00287 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_PK_ALG) )
00288 snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
00289 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_REQUIRED) )
00290 snprintf( buf, buflen, "PK - Private key password can't be empty" );
00291 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_MISMATCH) )
00292 snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
00293 if( use_ret == -(POLARSSL_ERR_PK_INVALID_PUBKEY) )
00294 snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
00295 if( use_ret == -(POLARSSL_ERR_PK_INVALID_ALG) )
00296 snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
00297 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE) )
00298 snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
00299 if( use_ret == -(POLARSSL_ERR_PK_FEATURE_UNAVAILABLE) )
00300 snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
00301 #endif
00302
00303 #if defined(POLARSSL_PKCS12_C)
00304 if( use_ret == -(POLARSSL_ERR_PKCS12_BAD_INPUT_DATA) )
00305 snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
00306 if( use_ret == -(POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE) )
00307 snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
00308 if( use_ret == -(POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT) )
00309 snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
00310 if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
00311 snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
00312 #endif
00313
00314 #if defined(POLARSSL_PKCS5_C)
00315 if( use_ret == -(POLARSSL_ERR_PKCS5_BAD_INPUT_DATA) )
00316 snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
00317 if( use_ret == -(POLARSSL_ERR_PKCS5_INVALID_FORMAT) )
00318 snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
00319 if( use_ret == -(POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE) )
00320 snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
00321 if( use_ret == -(POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH) )
00322 snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
00323 #endif
00324
00325 #if defined(POLARSSL_RSA_C)
00326 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
00327 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
00328 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
00329 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
00330 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
00331 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
00332 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
00333 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
00334 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
00335 snprintf( buf, buflen, "RSA - The public key operation failed" );
00336 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
00337 snprintf( buf, buflen, "RSA - The private key operation failed" );
00338 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
00339 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
00340 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
00341 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
00342 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
00343 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
00344 #endif
00345
00346 #if defined(POLARSSL_SSL_TLS_C)
00347 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
00348 snprintf( buf, buflen, "SSL - The requested feature is not available" );
00349 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
00350 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
00351 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
00352 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
00353 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
00354 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
00355 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
00356 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
00357 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
00358 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
00359 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
00360 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
00361 if( use_ret == -(POLARSSL_ERR_SSL_NO_SESSION_FOUND) )
00362 snprintf( buf, buflen, "SSL - No session to recover was found" );
00363 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
00364 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
00365 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
00366 snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
00367 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
00368 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
00369 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
00370 snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
00371 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
00372 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
00373 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
00374 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
00375 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
00376 {
00377 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
00378 return;
00379 }
00380 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
00381 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
00382 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
00383 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
00384 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
00385 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
00386 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
00387 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
00388 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
00389 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
00390 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
00391 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
00392 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
00393 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
00394 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
00395 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
00396 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
00397 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
00398 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
00399 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
00400 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
00401 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
00402 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
00403 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
00404 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
00405 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
00406 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
00407 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
00408 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
00409 snprintf( buf, buflen, "SSL - Memory allocation failed" );
00410 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
00411 snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
00412 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
00413 snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
00414 if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
00415 snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
00416 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
00417 snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
00418 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
00419 snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
00420 if( use_ret == -(POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED) )
00421 snprintf( buf, buflen, "SSL - Session ticket has expired" );
00422 if( use_ret == -(POLARSSL_ERR_SSL_PK_TYPE_MISMATCH) )
00423 snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
00424 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_IDENTITY) )
00425 snprintf( buf, buflen, "SSL - Unkown identity received (eg, PSK identity)" );
00426 if( use_ret == -(POLARSSL_ERR_SSL_INTERNAL_ERROR) )
00427 snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
00428 #endif
00429
00430 #if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
00431 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
00432 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
00433 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_OID) )
00434 snprintf( buf, buflen, "X509 - Requested OID is unknown" );
00435 if( use_ret == -(POLARSSL_ERR_X509_INVALID_FORMAT) )
00436 snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
00437 if( use_ret == -(POLARSSL_ERR_X509_INVALID_VERSION) )
00438 snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
00439 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SERIAL) )
00440 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
00441 if( use_ret == -(POLARSSL_ERR_X509_INVALID_ALG) )
00442 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
00443 if( use_ret == -(POLARSSL_ERR_X509_INVALID_NAME) )
00444 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
00445 if( use_ret == -(POLARSSL_ERR_X509_INVALID_DATE) )
00446 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
00447 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SIGNATURE) )
00448 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
00449 if( use_ret == -(POLARSSL_ERR_X509_INVALID_EXTENSIONS) )
00450 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
00451 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_VERSION) )
00452 snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
00453 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_SIG_ALG) )
00454 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
00455 if( use_ret == -(POLARSSL_ERR_X509_SIG_MISMATCH) )
00456 snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::x509_crt sig_oid)" );
00457 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
00458 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
00459 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
00460 snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
00461 if( use_ret == -(POLARSSL_ERR_X509_BAD_INPUT_DATA) )
00462 snprintf( buf, buflen, "X509 - Input invalid" );
00463 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
00464 snprintf( buf, buflen, "X509 - Allocation of memory failed" );
00465 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
00466 snprintf( buf, buflen, "X509 - Read/write of file failed" );
00467 #endif
00468
00469 if( strlen( buf ) == 0 )
00470 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
00471 }
00472
00473 use_ret = ret & ~0xFF80;
00474
00475 if( use_ret == 0 )
00476 return;
00477
00478
00479
00480
00481 len = strlen( buf );
00482
00483 if( len > 0 )
00484 {
00485 if( buflen - len < 5 )
00486 return;
00487
00488 snprintf( buf + len, buflen - len, " : " );
00489
00490 buf += len + 3;
00491 buflen -= len + 3;
00492 }
00493
00494
00495
00496 #if defined(POLARSSL_AES_C)
00497 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
00498 snprintf( buf, buflen, "AES - Invalid key length" );
00499 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
00500 snprintf( buf, buflen, "AES - Invalid data input length" );
00501 #endif
00502
00503 #if defined(POLARSSL_ASN1_PARSE_C)
00504 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
00505 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
00506 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
00507 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
00508 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
00509 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
00510 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
00511 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
00512 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
00513 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
00514 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
00515 snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
00516 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
00517 snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
00518 #endif
00519
00520 #if defined(POLARSSL_BASE64_C)
00521 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
00522 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
00523 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
00524 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
00525 #endif
00526
00527 #if defined(POLARSSL_BIGNUM_C)
00528 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
00529 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
00530 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
00531 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
00532 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
00533 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
00534 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
00535 snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
00536 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
00537 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
00538 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
00539 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
00540 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
00541 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
00542 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
00543 snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
00544 #endif
00545
00546 #if defined(POLARSSL_BLOWFISH_C)
00547 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
00548 snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
00549 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
00550 snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
00551 #endif
00552
00553 #if defined(POLARSSL_CAMELLIA_C)
00554 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
00555 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
00556 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
00557 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
00558 #endif
00559
00560 #if defined(POLARSSL_CTR_DRBG_C)
00561 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
00562 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
00563 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
00564 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
00565 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
00566 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
00567 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
00568 snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
00569 #endif
00570
00571 #if defined(POLARSSL_DES_C)
00572 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
00573 snprintf( buf, buflen, "DES - The data input has an invalid length" );
00574 #endif
00575
00576 #if defined(POLARSSL_ENTROPY_C)
00577 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
00578 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
00579 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
00580 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
00581 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
00582 snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
00583 #endif
00584
00585 #if defined(POLARSSL_GCM_C)
00586 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
00587 snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
00588 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
00589 snprintf( buf, buflen, "GCM - Bad input parameters to function" );
00590 #endif
00591
00592 #if defined(POLARSSL_MD2_C)
00593 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
00594 snprintf( buf, buflen, "MD2 - Read/write error in file" );
00595 #endif
00596
00597 #if defined(POLARSSL_MD4_C)
00598 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
00599 snprintf( buf, buflen, "MD4 - Read/write error in file" );
00600 #endif
00601
00602 #if defined(POLARSSL_MD5_C)
00603 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
00604 snprintf( buf, buflen, "MD5 - Read/write error in file" );
00605 #endif
00606
00607 #if defined(POLARSSL_NET_C)
00608 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
00609 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
00610 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
00611 snprintf( buf, buflen, "NET - Failed to open a socket" );
00612 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
00613 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
00614 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
00615 snprintf( buf, buflen, "NET - Binding of the socket failed" );
00616 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
00617 snprintf( buf, buflen, "NET - Could not listen on the socket" );
00618 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
00619 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
00620 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
00621 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
00622 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
00623 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
00624 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
00625 snprintf( buf, buflen, "NET - Connection was reset by peer" );
00626 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
00627 snprintf( buf, buflen, "NET - Connection requires a read call" );
00628 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
00629 snprintf( buf, buflen, "NET - Connection requires a write call" );
00630 #endif
00631
00632 #if defined(POLARSSL_OID_C)
00633 if( use_ret == -(POLARSSL_ERR_OID_NOT_FOUND) )
00634 snprintf( buf, buflen, "OID - OID is not found" );
00635 #endif
00636
00637 #if defined(POLARSSL_PADLOCK_C)
00638 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
00639 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
00640 #endif
00641
00642 #if defined(POLARSSL_PBKDF2_C)
00643 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
00644 snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
00645 #endif
00646
00647 #if defined(POLARSSL_SHA1_C)
00648 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
00649 snprintf( buf, buflen, "SHA1 - Read/write error in file" );
00650 #endif
00651
00652 #if defined(POLARSSL_SHA256_C)
00653 if( use_ret == -(POLARSSL_ERR_SHA256_FILE_IO_ERROR) )
00654 snprintf( buf, buflen, "SHA256 - Read/write error in file" );
00655 #endif
00656
00657 #if defined(POLARSSL_SHA512_C)
00658 if( use_ret == -(POLARSSL_ERR_SHA512_FILE_IO_ERROR) )
00659 snprintf( buf, buflen, "SHA512 - Read/write error in file" );
00660 #endif
00661
00662 #if defined(POLARSSL_THREADING_C)
00663 if( use_ret == -(POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE) )
00664 snprintf( buf, buflen, "THREADING - The selected feature is not available" );
00665 if( use_ret == -(POLARSSL_ERR_THREADING_BAD_INPUT_DATA) )
00666 snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
00667 if( use_ret == -(POLARSSL_ERR_THREADING_MUTEX_ERROR) )
00668 snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
00669 #endif
00670
00671 #if defined(POLARSSL_XTEA_C)
00672 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
00673 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
00674 #endif
00675
00676 if( strlen( buf ) != 0 )
00677 return;
00678
00679 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
00680 }
00681
00682 #if defined(POLARSSL_ERROR_STRERROR_BC)
00683 void error_strerror( int ret, char *buf, size_t buflen )
00684 {
00685 polarssl_strerror( ret, buf, buflen );
00686 }
00687 #endif
00688
00689 #else
00690
00691 #if defined(POLARSSL_ERROR_STRERROR_DUMMY)
00692
00693 #include <string.h>
00694
00695
00696
00697
00698 void polarssl_strerror( int ret, char *buf, size_t buflen )
00699 {
00700 ((void) ret);
00701
00702 if( buflen > 0 )
00703 buf[0] = '\0';
00704 }
00705
00706 #if defined(POLARSSL_ERROR_STRERROR_BC)
00707 void error_strerror( int ret, char *buf, size_t buflen )
00708 {
00709 polarssl_strerror( ret, buf, buflen );
00710 }
00711 #endif
00712 #endif
00713
00714 #endif