replaces tabs with spaces.

This commit is contained in:
Moisés Guimarães
2014-09-15 20:32:00 -03:00
parent e9af29e3e3
commit df3ea53494

206
src/ssl.c
View File

@@ -2833,17 +2833,17 @@ int CyaSSL_CTX_load_verify_locations(CYASSL_CTX* ctx, const char* file,
#ifdef USE_WINDOWS_API #ifdef USE_WINDOWS_API
WIN32_FIND_DATAA FindFileData; WIN32_FIND_DATAA FindFileData;
HANDLE hFind; HANDLE hFind;
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
char* name = NULL; char* name = NULL;
#else #else
char name[MAX_FILENAME_SZ]; char name[MAX_FILENAME_SZ];
#endif #endif
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
name = (char*)XMALLOC(MAX_FILENAME_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); name = (char*)XMALLOC(MAX_FILENAME_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (name == NULL) if (name == NULL)
return MEMORY_E; return MEMORY_E;
#endif #endif
XMEMSET(name, 0, MAX_FILENAME_SZ); XMEMSET(name, 0, MAX_FILENAME_SZ);
XSTRNCPY(name, path, MAX_FILENAME_SZ - 4); XSTRNCPY(name, path, MAX_FILENAME_SZ - 4);
@@ -2852,9 +2852,9 @@ int CyaSSL_CTX_load_verify_locations(CYASSL_CTX* ctx, const char* file,
hFind = FindFirstFileA(name, &FindFileData); hFind = FindFirstFileA(name, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) { if (hFind == INVALID_HANDLE_VALUE) {
CYASSL_MSG("FindFirstFile for path verify locations failed"); CYASSL_MSG("FindFirstFile for path verify locations failed");
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif #endif
return BAD_PATH_ERROR; return BAD_PATH_ERROR;
} }
@@ -2869,30 +2869,30 @@ int CyaSSL_CTX_load_verify_locations(CYASSL_CTX* ctx, const char* file,
} }
} while (ret == SSL_SUCCESS && FindNextFileA(hFind, &FindFileData)); } while (ret == SSL_SUCCESS && FindNextFileA(hFind, &FindFileData));
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif #endif
FindClose(hFind); FindClose(hFind);
#elif !defined(NO_CYASSL_DIR) #elif !defined(NO_CYASSL_DIR)
struct dirent* entry; struct dirent* entry;
DIR* dir = opendir(path); DIR* dir = opendir(path);
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
char* name = NULL; char* name = NULL;
#else #else
char name[MAX_FILENAME_SZ]; char name[MAX_FILENAME_SZ];
#endif #endif
if (dir == NULL) { if (dir == NULL) {
CYASSL_MSG("opendir path verify locations failed"); CYASSL_MSG("opendir path verify locations failed");
return BAD_PATH_ERROR; return BAD_PATH_ERROR;
} }
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
name = (char*)XMALLOC(MAX_FILENAME_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); name = (char*)XMALLOC(MAX_FILENAME_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (name == NULL) if (name == NULL)
return MEMORY_E; return MEMORY_E;
#endif #endif
while ( ret == SSL_SUCCESS && (entry = readdir(dir)) != NULL) { while ( ret == SSL_SUCCESS && (entry = readdir(dir)) != NULL) {
struct stat s; struct stat s;
@@ -2910,9 +2910,9 @@ int CyaSSL_CTX_load_verify_locations(CYASSL_CTX* ctx, const char* file,
NULL); NULL);
} }
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif #endif
closedir(dir); closedir(dir);
#endif #endif
@@ -3403,41 +3403,41 @@ static int CyaSSL_SetTmpDH_buffer_wrapper(CYASSL_CTX* ctx, CYASSL* ssl,
der.length = (word32)sz; der.length = (word32)sz;
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
p = (byte*)XMALLOC(pSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); p = (byte*)XMALLOC(pSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
g = (byte*)XMALLOC(gSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); g = (byte*)XMALLOC(gSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (p == NULL || g == NULL) { if (p == NULL || g == NULL) {
XFREE(p, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(p, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(g, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(g, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return MEMORY_E; return MEMORY_E;
} }
#endif #endif
if (format != SSL_FILETYPE_ASN1 && format != SSL_FILETYPE_PEM) if (format != SSL_FILETYPE_ASN1 && format != SSL_FILETYPE_PEM)
ret = SSL_BAD_FILETYPE; ret = SSL_BAD_FILETYPE;
else { else {
if (format == SSL_FILETYPE_PEM) { if (format == SSL_FILETYPE_PEM) {
der.buffer = NULL; der.buffer = NULL;
ret = PemToDer(buf, sz, DH_PARAM_TYPE, &der, ctx->heap, NULL,NULL); ret = PemToDer(buf, sz, DH_PARAM_TYPE, &der, ctx->heap, NULL,NULL);
weOwnDer = 1; weOwnDer = 1;
} }
if (ret == 0) { if (ret == 0) {
if (DhParamsLoad(der.buffer, der.length, p, &pSz, g, &gSz) < 0) if (DhParamsLoad(der.buffer, der.length, p, &pSz, g, &gSz) < 0)
ret = SSL_BAD_FILETYPE; ret = SSL_BAD_FILETYPE;
else if (ssl) else if (ssl)
ret = CyaSSL_SetTmpDH(ssl, p, pSz, g, gSz); ret = CyaSSL_SetTmpDH(ssl, p, pSz, g, gSz);
else else
ret = CyaSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz); ret = CyaSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz);
} }
} }
if (weOwnDer) if (weOwnDer)
XFREE(der.buffer, ctx->heap, DYNAMIC_TYPE_KEY); XFREE(der.buffer, ctx->heap, DYNAMIC_TYPE_KEY);
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
XFREE(p, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(p, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(g, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(g, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif #endif
return ret; return ret;
@@ -9978,7 +9978,7 @@ int CyaSSL_RAND_seed(const void* seed, int len)
/* SSL_SUCCESS on ok */ /* SSL_SUCCESS on ok */
int CyaSSL_RAND_bytes(unsigned char* buf, int num) int CyaSSL_RAND_bytes(unsigned char* buf, int num)
{ {
int ret = 0; int ret = 0;
RNG* rng = NULL; RNG* rng = NULL;
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
RNG* tmpRNG = NULL; RNG* tmpRNG = NULL;
@@ -9988,25 +9988,25 @@ int CyaSSL_RAND_bytes(unsigned char* buf, int num)
CYASSL_ENTER("RAND_bytes"); CYASSL_ENTER("RAND_bytes");
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
tmpRNG = (RNG*)XMALLOC(sizeof(RNG), NULL, DYNAMIC_TYPE_TMP_BUFFER); tmpRNG = (RNG*)XMALLOC(sizeof(RNG), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (tmpRNG == NULL) if (tmpRNG == NULL)
return ret; return ret;
#endif #endif
if (InitRng(tmpRNG) == 0) if (InitRng(tmpRNG) == 0)
rng = tmpRNG; rng = tmpRNG;
else if (initGlobalRNG) else if (initGlobalRNG)
rng = &globalRNG; rng = &globalRNG;
if (rng) { if (rng) {
if (RNG_GenerateBlock(rng, buf, num) != 0) if (RNG_GenerateBlock(rng, buf, num) != 0)
CYASSL_MSG("Bad RNG_GenerateBlock"); CYASSL_MSG("Bad RNG_GenerateBlock");
else else
ret = SSL_SUCCESS; ret = SSL_SUCCESS;
} }
return ret; return ret;
} }
CYASSL_BN_CTX* CyaSSL_BN_CTX_new(void) CYASSL_BN_CTX* CyaSSL_BN_CTX_new(void)
@@ -10273,7 +10273,7 @@ int CyaSSL_mask_bits(CYASSL_BIGNUM* bn, int n)
/* SSL_SUCCESS on ok */ /* SSL_SUCCESS on ok */
int CyaSSL_BN_rand(CYASSL_BIGNUM* bn, int bits, int top, int bottom) int CyaSSL_BN_rand(CYASSL_BIGNUM* bn, int bits, int top, int bottom)
{ {
int ret = 0; int ret = 0;
int len = bits / 8; int len = bits / 8;
RNG* rng = NULL; RNG* rng = NULL;
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
@@ -10292,39 +10292,39 @@ int CyaSSL_BN_rand(CYASSL_BIGNUM* bn, int bits, int top, int bottom)
len++; len++;
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
buff = (byte*)XMALLOC(1024, NULL, DYNAMIC_TYPE_TMP_BUFFER); buff = (byte*)XMALLOC(1024, NULL, DYNAMIC_TYPE_TMP_BUFFER);
tmpRNG = (RNG*) XMALLOC(sizeof(RNG), NULL, DYNAMIC_TYPE_TMP_BUFFER); tmpRNG = (RNG*) XMALLOC(sizeof(RNG), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (buff == NULL || tmpRNG == NULL) { if (buff == NULL || tmpRNG == NULL) {
XFREE(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(tmpRNG, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(tmpRNG, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret; return ret;
} }
#endif #endif
if (bn == NULL || bn->internal == NULL) if (bn == NULL || bn->internal == NULL)
CYASSL_MSG("Bad function arguments"); CYASSL_MSG("Bad function arguments");
else if (InitRng(tmpRNG) == 0) else if (InitRng(tmpRNG) == 0)
rng = tmpRNG; rng = tmpRNG;
else if (initGlobalRNG) else if (initGlobalRNG)
rng = &globalRNG; rng = &globalRNG;
if (rng) { if (rng) {
if (RNG_GenerateBlock(rng, buff, len) != 0) if (RNG_GenerateBlock(rng, buff, len) != 0)
CYASSL_MSG("Bad RNG_GenerateBlock"); CYASSL_MSG("Bad RNG_GenerateBlock");
else { else {
buff[0] |= 0x80 | 0x40; buff[0] |= 0x80 | 0x40;
buff[len-1] |= 0x01; buff[len-1] |= 0x01;
if (mp_read_unsigned_bin((mp_int*)bn->internal,buff,len) != MP_OKAY) if (mp_read_unsigned_bin((mp_int*)bn->internal,buff,len) != MP_OKAY)
CYASSL_MSG("mp read bin failed"); CYASSL_MSG("mp read bin failed");
else else
ret = SSL_SUCCESS; ret = SSL_SUCCESS;
} }
} }
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
XFREE(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(tmpRNG, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(tmpRNG, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif #endif
return ret; return ret;
@@ -10348,39 +10348,39 @@ int CyaSSL_BN_hex2bn(CYASSL_BIGNUM** bn, const char* str)
int ret = 0; int ret = 0;
word32 decSz = 1024; word32 decSz = 1024;
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
byte* decoded = NULL; byte* decoded = NULL;
#else #else
byte decoded[1024]; byte decoded[1024];
#endif #endif
CYASSL_MSG("CyaSSL_BN_hex2bn"); CYASSL_MSG("CyaSSL_BN_hex2bn");
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
decoded = (byte*)XMALLOC(decSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); decoded = (byte*)XMALLOC(decSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (decoded == NULL) if (decoded == NULL)
return ret; return ret;
#endif #endif
if (str == NULL) if (str == NULL)
CYASSL_MSG("Bad function argument"); CYASSL_MSG("Bad function argument");
else if (Base16_Decode((byte*)str, (int)XSTRLEN(str), decoded, &decSz) < 0) else if (Base16_Decode((byte*)str, (int)XSTRLEN(str), decoded, &decSz) < 0)
CYASSL_MSG("Bad Base16_Decode error"); CYASSL_MSG("Bad Base16_Decode error");
else if (bn == NULL) else if (bn == NULL)
ret = decSz; ret = decSz;
else { else {
if (*bn == NULL) if (*bn == NULL)
*bn = CyaSSL_BN_new(); *bn = CyaSSL_BN_new();
if (*bn == NULL) if (*bn == NULL)
CYASSL_MSG("BN new failed"); CYASSL_MSG("BN new failed");
else if (CyaSSL_BN_bin2bn(decoded, decSz, *bn) == NULL) else if (CyaSSL_BN_bin2bn(decoded, decSz, *bn) == NULL)
CYASSL_MSG("Bad bin2bn error"); CYASSL_MSG("Bad bin2bn error");
else else
ret = SSL_SUCCESS; ret = SSL_SUCCESS;
} }
#ifdef CYASSL_SMALL_STACK #ifdef CYASSL_SMALL_STACK
XFREE(decoded, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(decoded, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif #endif
return ret; return ret;