diff --git a/cyassl/ssl.h b/cyassl/ssl.h index 2963e9bc8..0b4d4e479 100644 --- a/cyassl/ssl.h +++ b/cyassl/ssl.h @@ -58,6 +58,8 @@ #define CYASSL_BIO WOLFSSL_BIO #define CYASSL_CIPHER WOLFSSL_CIPHER #define CYASSL_MD4_CTX WOLFSSL_MD4_CTX +#define CYASSL_MFL_2_9 WOLFSSL_MFL_2_9 +#define CYASSL_MFL_2_13 WOLFSSL_MFL_2_13 #define CYASSL_EVP_PKEY WOLFSSL_EVP_PKEY #define CYASSL_X509_CRL WOLFSSL_X509_CRL #define CYASSL_ASN1_TIME WOLFSSL_ASN1_TIME @@ -82,7 +84,7 @@ /* cyassl/test.h */ #ifdef CyaSSL_TEST_H - #define CYASSL_THREAD WOLFSSL_THREAD + #define CYASSL_THREAD WOLFSSL_THREAD #endif /* src/ssl.c */ @@ -179,11 +181,11 @@ #define CyaSSL_CTX_use_NTRUPrivateKey_file wolfSSL_CTX_use_NTRUPrivateKey_file #define CyaSSL_use_certificate_chain_buffer wolfSSL_use_certificate_chain_buffer #define CyaSSL_CTX_der_load_verify_locations \ - wolfSSL_CTX_der_load_verify_locations + wolfSSL_CTX_der_load_verify_locations #define CyaSSL_CTX_use_certificate_chain_file \ - wolfSSL_CTX_use_certificate_chain_file + wolfSSL_CTX_use_certificate_chain_file #define CyaSSL_CTX_use_certificate_chain_buffer \ - wolfSSL_CTX_use_certificate_chain_buffer + wolfSSL_CTX_use_certificate_chain_buffer /* Context and Session Setup*/ #define CyaSSL_new wolfSSL_new @@ -264,9 +266,9 @@ #define CyaSSL_CTX_SetDecryptVerifyCb wolfSSL_CTX_SetDecryptVerifyCb #define CyaSSL_CTX_use_psk_identity_hint wolfSSL_CTX_use_psk_identity_hint /**/ #define CyaSSL_CTX_set_psk_client_callback \ - wolfSSL_CTX_set_psk_client_callback /**/ + wolfSSL_CTX_set_psk_client_callback /**/ #define CyaSSL_CTX_set_psk_server_callback \ - wolfSSL_CTX_set_psk_server_callback /**/ + wolfSSL_CTX_set_psk_server_callback /**/ /* Error Handling and Debugging*/ #define CyaSSL_get_error wolfSSL_get_error diff --git a/src/ssl.c b/src/ssl.c index 9cb10566f..cef38d9f4 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -2000,39 +2000,39 @@ int PemToDer(const unsigned char* buff, long longSz, int type, int dynamicType = 0; int sz = (int)longSz; - switch (type) { - case CA_TYPE: /* same as below */ - case CERT_TYPE: header= BEGIN_CERT; footer= END_CERT; break; - case CRL_TYPE: header= BEGIN_X509_CRL; footer= END_X509_CRL; break; - case DH_PARAM_TYPE: header= BEGIN_DH_PARAM; footer= END_DH_PARAM; break; - case CERTREQ_TYPE: header= BEGIN_CERT_REQ; footer= END_CERT_REQ; break; - default: header= BEGIN_RSA_PRIV; footer= END_RSA_PRIV; break; - } - - switch (type) { - case CA_TYPE: dynamicType = DYNAMIC_TYPE_CA; break; - case CERT_TYPE: dynamicType = DYNAMIC_TYPE_CERT; break; - case CRL_TYPE: dynamicType = DYNAMIC_TYPE_CRL; break; - default: dynamicType = DYNAMIC_TYPE_KEY; break; - } + switch (type) { + case CA_TYPE: /* same as below */ + case CERT_TYPE: header= BEGIN_CERT; footer= END_CERT; break; + case CRL_TYPE: header= BEGIN_X509_CRL; footer= END_X509_CRL; break; + case DH_PARAM_TYPE: header= BEGIN_DH_PARAM; footer= END_DH_PARAM; break; + case CERTREQ_TYPE: header= BEGIN_CERT_REQ; footer= END_CERT_REQ; break; + default: header= BEGIN_RSA_PRIV; footer= END_RSA_PRIV; break; + } + + switch (type) { + case CA_TYPE: dynamicType = DYNAMIC_TYPE_CA; break; + case CERT_TYPE: dynamicType = DYNAMIC_TYPE_CERT; break; + case CRL_TYPE: dynamicType = DYNAMIC_TYPE_CRL; break; + default: dynamicType = DYNAMIC_TYPE_KEY; break; + } /* find header */ - for (;;) { - headerEnd = XSTRNSTR((char*)buff, header, sz); - - if (headerEnd || type != PRIVATEKEY_TYPE) { - break; - } else if (header == BEGIN_RSA_PRIV) { - header = BEGIN_PRIV_KEY; footer = END_PRIV_KEY; - } else if (header == BEGIN_PRIV_KEY) { - header = BEGIN_ENC_PRIV_KEY; footer = END_ENC_PRIV_KEY; - } else if (header == BEGIN_ENC_PRIV_KEY) { - header = BEGIN_EC_PRIV; footer = END_EC_PRIV; - } else if (header == BEGIN_EC_PRIV) { - header = BEGIN_DSA_PRIV; footer = END_DSA_PRIV; - } else - break; - } + for (;;) { + headerEnd = XSTRNSTR((char*)buff, header, sz); + + if (headerEnd || type != PRIVATEKEY_TYPE) { + break; + } else if (header == BEGIN_RSA_PRIV) { + header = BEGIN_PRIV_KEY; footer = END_PRIV_KEY; + } else if (header == BEGIN_PRIV_KEY) { + header = BEGIN_ENC_PRIV_KEY; footer = END_ENC_PRIV_KEY; + } else if (header == BEGIN_ENC_PRIV_KEY) { + header = BEGIN_EC_PRIV; footer = END_EC_PRIV; + } else if (header == BEGIN_EC_PRIV) { + header = BEGIN_DSA_PRIV; footer = END_DSA_PRIV; + } else + break; + } if (!headerEnd) { WOLFSSL_MSG("Couldn't find PEM header"); @@ -2049,59 +2049,59 @@ int PemToDer(const unsigned char* buff, long longSz, int type, else return SSL_BAD_FILE; - if (type == PRIVATEKEY_TYPE) { - if (eccKey) - *eccKey = header == BEGIN_EC_PRIV; - } + if (type == PRIVATEKEY_TYPE) { + if (eccKey) + *eccKey = header == BEGIN_EC_PRIV; + } #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) - { - /* remove encrypted header if there */ - char encHeader[] = "Proc-Type"; - char* line = XSTRNSTR(headerEnd, encHeader, PEM_LINE_LEN); - if (line) { - char* newline; - char* finish; - char* start = XSTRNSTR(line, "DES", PEM_LINE_LEN); + { + /* remove encrypted header if there */ + char encHeader[] = "Proc-Type"; + char* line = XSTRNSTR(headerEnd, encHeader, PEM_LINE_LEN); + if (line) { + char* newline; + char* finish; + char* start = XSTRNSTR(line, "DES", PEM_LINE_LEN); - if (!start) - start = XSTRNSTR(line, "AES", PEM_LINE_LEN); + if (!start) + start = XSTRNSTR(line, "AES", PEM_LINE_LEN); - if (!start) return SSL_BAD_FILE; - if (!info) return SSL_BAD_FILE; + if (!start) return SSL_BAD_FILE; + if (!info) return SSL_BAD_FILE; - finish = XSTRNSTR(start, ",", PEM_LINE_LEN); + finish = XSTRNSTR(start, ",", PEM_LINE_LEN); - if (start && finish && (start < finish)) { - newline = XSTRNSTR(finish, "\r", PEM_LINE_LEN); + if (start && finish && (start < finish)) { + newline = XSTRNSTR(finish, "\r", PEM_LINE_LEN); - XMEMCPY(info->name, start, finish - start); - info->name[finish - start] = 0; - XMEMCPY(info->iv, finish + 1, sizeof(info->iv)); + XMEMCPY(info->name, start, finish - start); + info->name[finish - start] = 0; + XMEMCPY(info->iv, finish + 1, sizeof(info->iv)); - if (!newline) newline = XSTRNSTR(finish, "\n", PEM_LINE_LEN); - if (newline && (newline > finish)) { - info->ivSz = (word32)(newline - (finish + 1)); - info->set = 1; - } - else - return SSL_BAD_FILE; - } - else - return SSL_BAD_FILE; + if (!newline) newline = XSTRNSTR(finish, "\n", PEM_LINE_LEN); + if (newline && (newline > finish)) { + info->ivSz = (word32)(newline - (finish + 1)); + info->set = 1; + } + else + return SSL_BAD_FILE; + } + else + return SSL_BAD_FILE; - /* eat blank line */ - while (*newline == '\r' || *newline == '\n') - newline++; - headerEnd = newline; - } - } + /* eat blank line */ + while (*newline == '\r' || *newline == '\n') + newline++; + headerEnd = newline; + } + } #endif /* OPENSSL_EXTRA || HAVE_WEBSERVER */ /* find footer */ footerEnd = XSTRNSTR((char*)buff, footer, sz); if (!footerEnd) - return SSL_BAD_FILE; + return SSL_BAD_FILE; consumedEnd = footerEnd + XSTRLEN(footer); @@ -2121,11 +2121,11 @@ int PemToDer(const unsigned char* buff, long longSz, int type, /* set up der buffer */ neededSz = (long)(footerEnd - headerEnd); if (neededSz > sz || neededSz < 0) - return SSL_BAD_FILE; + return SSL_BAD_FILE; - der->buffer = (byte*)XMALLOC(neededSz, heap, dynamicType); + der->buffer = (byte*)XMALLOC(neededSz, heap, dynamicType); if (!der->buffer) - return MEMORY_ERROR; + return MEMORY_ERROR; der->length = (word32)neededSz; @@ -2145,28 +2145,28 @@ int PemToDer(const unsigned char* buff, long longSz, int type, #if (defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)) && !defined(NO_PWDBASED) if (header == BEGIN_ENC_PRIV_KEY) { int passwordSz; - #ifdef WOLFSSL_SMALL_STACK - char* password = NULL; - #else + #ifdef WOLFSSL_SMALL_STACK + char* password = NULL; + #else char password[80]; - #endif + #endif if (!info || !info->ctx || !info->ctx->passwd_cb) return SSL_BAD_FILE; /* no callback error */ - #ifdef WOLFSSL_SMALL_STACK - password = (char*)XMALLOC(80, NULL, DYNAMIC_TYPE_TMP_BUFFER); - if (password == NULL) - return MEMORY_E; - #endif - passwordSz = info->ctx->passwd_cb(password, sizeof(password), 0, + #ifdef WOLFSSL_SMALL_STACK + password = (char*)XMALLOC(80, NULL, DYNAMIC_TYPE_TMP_BUFFER); + if (password == NULL) + return MEMORY_E; + #endif + passwordSz = info->ctx->passwd_cb(password, sizeof(password), 0, info->ctx->userdata); /* convert and adjust length */ - ret = ToTraditionalEnc(der->buffer, der->length, password, passwordSz); + ret = ToTraditionalEnc(der->buffer, der->length, password, passwordSz); - #ifdef WOLFSSL_SMALL_STACK - XFREE(password, NULL, DYNAMIC_TYPE_TMP_BUFFER); - #endif + #ifdef WOLFSSL_SMALL_STACK + XFREE(password, NULL, DYNAMIC_TYPE_TMP_BUFFER); + #endif if (ret < 0) return ret; @@ -5513,7 +5513,7 @@ static INLINE word32 HashSession(const byte* sessionID, word32 len, int* error) #ifndef NO_MD5 *error = wc_Md5Hash(sessionID, len, digest); #elif !defined(NO_SHA) - *error = ShaHash(sessionID, len, digest); + *error = wc_ShaHash(sessionID, len, digest); #elif !defined(NO_SHA256) *error = Sha256Hash(sessionID, len, digest); #else diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index a3c3a0922..28337f310 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -129,17 +129,17 @@ */ struct tm { - int tm_sec; /* seconds after the minute [0-60] */ - int tm_min; /* minutes after the hour [0-59] */ - int tm_hour; /* hours since midnight [0-23] */ - int tm_mday; /* day of the month [1-31] */ - int tm_mon; /* months since January [0-11] */ - int tm_year; /* years since 1900 */ - int tm_wday; /* days since Sunday [0-6] */ - int tm_yday; /* days since January 1 [0-365] */ - int tm_isdst; /* Daylight Savings Time flag */ - long tm_gmtoff; /* offset from CUT in seconds */ - char *tm_zone; /* timezone abbreviation */ + int tm_sec; /* seconds after the minute [0-60] */ + int tm_min; /* minutes after the hour [0-59] */ + int tm_hour; /* hours since midnight [0-23] */ + int tm_mday; /* day of the month [1-31] */ + int tm_mon; /* months since January [0-11] */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday [0-6] */ + int tm_yday; /* days since January 1 [0-365] */ + int tm_isdst; /* Daylight Savings Time flag */ + long tm_gmtoff; /* offset from CUT in seconds */ + char *tm_zone; /* timezone abbreviation */ }; typedef long time_t; diff --git a/wolfcrypt/src/memory.c b/wolfcrypt/src/memory.c index 408264203..41b01769f 100644 --- a/wolfcrypt/src/memory.c +++ b/wolfcrypt/src/memory.c @@ -55,7 +55,7 @@ int wolfSSL_SetAllocators(wolfSSL_Malloc_cb mf, if (mf) malloc_function = mf; - else + else res = BAD_FUNC_ARG; if (ff) @@ -85,7 +85,7 @@ void* wolfSSL_Malloc(size_t size) if (res == NULL) puts("wolfSSL_malloc failed"); #endif - + return res; } @@ -130,7 +130,7 @@ static THREAD_LS_T byte pool_in[17*1024]; static THREAD_LS_T byte pool_out[17*1024]; -void* wc_MALLOC(size_t n, void* heap, int type) +void* XMALLOC(size_t n, void* heap, int type) { (void)heap; @@ -151,7 +151,7 @@ void* wc_MALLOC(size_t n, void* heap, int type) return malloc(n); } -void* wc_REALLOC(void *p, size_t n, void* heap, int type) +void* XREALLOC(void *p, size_t n, void* heap, int type) { (void)heap; @@ -173,8 +173,8 @@ void* wc_REALLOC(void *p, size_t n, void* heap, int type) } -/* unit api calls, let's make sure visisble with CYASSL_API */ -WOLFSSL_API void wc_FREE(void *p, void* heap, int type) +/* unit api calls, let's make sure visible with CYASSL_API */ +WOLFSSL_API void XFREE(void *p, void* heap, int type) { (void)heap; diff --git a/wolfssl/wolfcrypt/memory.h b/wolfssl/wolfcrypt/memory.h index 8b7dcd86b..c0f61794e 100644 --- a/wolfssl/wolfcrypt/memory.h +++ b/wolfssl/wolfcrypt/memory.h @@ -36,25 +36,25 @@ #define CyaSSL_SetAllocators wolfSSL_SetAllocators /* Public in case user app wants to use XMALLOC/XFREE */ - #define CyaSSL_Malloc wolfSSL_Malloc - #define CyaSSL_Free wolfSSL_Free - #define CyaSSL_Realloc wolfSSL_Realloc + #define CyaSSL_Malloc wolfSSL_Malloc + #define CyaSSL_Free wolfSSL_Free + #define CyaSSL_Realloc wolfSSL_Realloc - typedef void *(*wolfSSL_Malloc_cb)(size_t size); - typedef void (*wolfSSL_Free_cb)(void *ptr); - typedef void *(*wolfSSL_Realloc_cb)(void *ptr, size_t size); - - - /* Public set function */ - WOLFSSL_API int wolfSSL_SetAllocators(wolfSSL_Malloc_cb malloc_function, - wolfSSL_Free_cb free_function, - wolfSSL_Realloc_cb realloc_function); - - /* Public in case user app wants to use XMALLOC/XFREE */ - WOLFSSL_API void* wolfSSL_Malloc(size_t size); - WOLFSSL_API void wolfSSL_Free(void *ptr); - WOLFSSL_API void* wolfSSL_Realloc(void *ptr, size_t size); + typedef void *(*wolfSSL_Malloc_cb)(size_t size); + typedef void (*wolfSSL_Free_cb)(void *ptr); + typedef void *(*wolfSSL_Realloc_cb)(void *ptr, size_t size); + + + /* Public set function */ + WOLFSSL_API int wolfSSL_SetAllocators(wolfSSL_Malloc_cb malloc_function, + wolfSSL_Free_cb free_function, + wolfSSL_Realloc_cb realloc_function); + + /* Public in case user app wants to use XMALLOC/XFREE */ + WOLFSSL_API void* wolfSSL_Malloc(size_t size); + WOLFSSL_API void wolfSSL_Free(void *ptr); + WOLFSSL_API void* wolfSSL_Realloc(void *ptr, size_t size); #else #include /* when using fips map wolfSSL to CyaSSL*/ @@ -64,9 +64,9 @@ #define wolfSSL_SetAllocators CyaSSL_SetAllocators /* Public in case user app wants to use XMALLOC/XFREE */ - #define wolfSSL_Malloc CyaSSL_Malloc - #define wolfSSL_Free CyaSSL_Free - #define wolfSSL_Realloc CyaSSL_Realloc + #define wolfSSL_Malloc CyaSSL_Malloc + #define wolfSSL_Free CyaSSL_Free + #define wolfSSL_Realloc CyaSSL_Realloc #endif #endif /* WOLFSSL_MEMORY_H */