diff --git a/ctaocrypt/src/error.c b/ctaocrypt/src/error.c index ca2e490ba..e6b4eaf3b 100644 --- a/ctaocrypt/src/error.c +++ b/ctaocrypt/src/error.c @@ -66,6 +66,10 @@ void CTaoCryptErrorString(int error, char* buffer) XSTRNCPY(buffer, "random device read would block error", max); break; + case BAD_MUTEX_E : + XSTRNCPY(buffer, "Bad mutex, operation failed", max); + break; + case MP_INIT_E : XSTRNCPY(buffer, "mp_init error state", max); break; diff --git a/ctaocrypt/src/port.c b/ctaocrypt/src/port.c new file mode 100644 index 000000000..92328408f --- /dev/null +++ b/ctaocrypt/src/port.c @@ -0,0 +1,381 @@ +/* port.c + * + * Copyright (C) 2006-2013 wolfSSL Inc. + * + * This file is part of CyaSSL. + * + * CyaSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * CyaSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include +#include +#include + + +#ifdef _MSC_VER + /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */ + #pragma warning(disable: 4996) +#endif + + + +#ifdef SINGLE_THREADED + +int InitMutex(CyaSSL_Mutex* m) +{ + (void)m; + return 0; +} + + +int FreeMutex(CyaSSL_Mutex *m) +{ + (void)m; + return 0; +} + + +int LockMutex(CyaSSL_Mutex *m) +{ + (void)m; + return 0; +} + + +int UnLockMutex(CyaSSL_Mutex *m) +{ + (void)m; + return 0; +} + +#else /* MULTI_THREAD */ + + #if defined(FREERTOS) + + int InitMutex(CyaSSL_Mutex* m) + { + int iReturn; + + *m = ( CyaSSL_Mutex ) xSemaphoreCreateMutex(); + if( *m != NULL ) + iReturn = 0; + else + iReturn = BAD_MUTEX_E; + + return iReturn; + } + + int FreeMutex(CyaSSL_Mutex* m) + { + vSemaphoreDelete( *m ); + return 0; + } + + int LockMutex(CyaSSL_Mutex* m) + { + /* Assume an infinite block, or should there be zero block? */ + xSemaphoreTake( *m, portMAX_DELAY ); + return 0; + } + + int UnLockMutex(CyaSSL_Mutex* m) + { + xSemaphoreGive( *m ); + return 0; + } + + #elif defined(CYASSL_SAFERTOS) + + int InitMutex(CyaSSL_Mutex* m) + { + vSemaphoreCreateBinary(m->mutexBuffer, m->mutex); + if (m->mutex == NULL) + return BAD_MUTEX_E; + + return 0; + } + + int FreeMutex(CyaSSL_Mutex* m) + { + (void)m; + return 0; + } + + int LockMutex(CyaSSL_Mutex* m) + { + /* Assume an infinite block */ + xSemaphoreTake(m->mutex, portMAX_DELAY); + return 0; + } + + int UnLockMutex(CyaSSL_Mutex* m) + { + xSemaphoreGive(m->mutex); + return 0; + } + + + #elif defined(USE_WINDOWS_API) + + int InitMutex(CyaSSL_Mutex* m) + { + InitializeCriticalSection(m); + return 0; + } + + + int FreeMutex(CyaSSL_Mutex* m) + { + DeleteCriticalSection(m); + return 0; + } + + + int LockMutex(CyaSSL_Mutex* m) + { + EnterCriticalSection(m); + return 0; + } + + + int UnLockMutex(CyaSSL_Mutex* m) + { + LeaveCriticalSection(m); + return 0; + } + + #elif defined(CYASSL_PTHREADS) + + int InitMutex(CyaSSL_Mutex* m) + { + if (pthread_mutex_init(m, 0) == 0) + return 0; + else + return BAD_MUTEX_E; + } + + + int FreeMutex(CyaSSL_Mutex* m) + { + if (pthread_mutex_destroy(m) == 0) + return 0; + else + return BAD_MUTEX_E; + } + + + int LockMutex(CyaSSL_Mutex* m) + { + if (pthread_mutex_lock(m) == 0) + return 0; + else + return BAD_MUTEX_E; + } + + + int UnLockMutex(CyaSSL_Mutex* m) + { + if (pthread_mutex_unlock(m) == 0) + return 0; + else + return BAD_MUTEX_E; + } + + #elif defined(THREADX) + + int InitMutex(CyaSSL_Mutex* m) + { + if (tx_mutex_create(m, "CyaSSL Mutex", TX_NO_INHERIT) == 0) + return 0; + else + return BAD_MUTEX_E; + } + + + int FreeMutex(CyaSSL_Mutex* m) + { + if (tx_mutex_delete(m) == 0) + return 0; + else + return BAD_MUTEX_E; + } + + + int LockMutex(CyaSSL_Mutex* m) + { + if (tx_mutex_get(m, TX_WAIT_FOREVER) == 0) + return 0; + else + return BAD_MUTEX_E; + } + + + int UnLockMutex(CyaSSL_Mutex* m) + { + if (tx_mutex_put(m) == 0) + return 0; + else + return BAD_MUTEX_E; + } + + #elif defined(MICRIUM) + + int InitMutex(CyaSSL_Mutex* m) + { + #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) + if (NetSecure_OS_MutexCreate(m) == 0) + return 0; + else + return BAD_MUTEX_E; + #else + return 0; + #endif + } + + + int FreeMutex(CyaSSL_Mutex* m) + { + #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) + if (NetSecure_OS_FreeMutex(m) == 0) + return 0; + else + return BAD_MUTEX_E; + #else + return 0; + #endif + } + + + int LockMutex(CyaSSL_Mutex* m) + { + #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) + if (NetSecure_OS_LockMutex(m) == 0) + return 0; + else + return BAD_MUTEX_E; + #else + return 0; + #endif + } + + + int UnLockMutex(CyaSSL_Mutex* m) + { + #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) + if (NetSecure_OS_UnLockMutex(m) == 0) + return 0; + else + return BAD_MUTEX_E; + #else + return 0; + #endif + + } + + #elif defined(EBSNET) + + int InitMutex(CyaSSL_Mutex* m) + { + if (rtp_sig_mutex_alloc(m, "CyaSSL Mutex") == -1) + return BAD_MUTEX_E; + else + return 0; + } + + int FreeMutex(CyaSSL_Mutex* m) + { + rtp_sig_mutex_free(*m); + return 0; + } + + int LockMutex(CyaSSL_Mutex* m) + { + if (rtp_sig_mutex_claim_timed(*m, RTIP_INF) == 0) + return 0; + else + return BAD_MUTEX_E; + } + + int UnLockMutex(CyaSSL_Mutex* m) + { + rtp_sig_mutex_release(*m); + return 0; + } + + #elif defined(FREESCALE_MQX) + + int InitMutex(CyaSSL_Mutex* m) + { + if (_mutex_init(m, NULL) == MQX_EOK) + return 0; + else + return BAD_MUTEX_E; + } + + int FreeMutex(CyaSSL_Mutex* m) + { + if (_mutex_destroy(m) == MQX_EOK) + return 0; + else + return BAD_MUTEX_E; + } + + int LockMutex(CyaSSL_Mutex* m) + { + if (_mutex_lock(m) == MQX_EOK) + return 0; + else + return BAD_MUTEX_E; + } + + int UnLockMutex(CyaSSL_Mutex* m) + { + if (_mutex_unlock(m) == MQX_EOK) + return 0; + else + return BAD_MUTEX_E; + } + + #elif defined(CYASSL_MDK_ARM) + + int InitMutex(CyaSSL_Mutex* m) + { + os_mut_init (m); + return 0; + } + + int FreeMutex(CyaSSL_Mutex* m) + { + return(0) ; + } + + int LockMutex(CyaSSL_Mutex* m) + { + os_mut_wait (m, 0xffff); + return(0) ; + } + + int UnLockMutex(CyaSSL_Mutex* m) + { + os_mut_release (m); + return 0; + } + #endif /* USE_WINDOWS_API */ +#endif /* SINGLE_THREADED */ + diff --git a/cyassl/ctaocrypt/error.h b/cyassl/ctaocrypt/error.h index 617fa215b..7bb7960c3 100644 --- a/cyassl/ctaocrypt/error.h +++ b/cyassl/ctaocrypt/error.h @@ -39,6 +39,7 @@ enum { WINCRYPT_E = -103, /* windows crypt init error */ CRYPTGEN_E = -104, /* windows crypt generation error */ RAN_BLOCK_E = -105, /* reading random device would block */ + BAD_MUTEX_E = -106, /* Bad mutex operation */ MP_INIT_E = -110, /* mp_init error state */ MP_READ_E = -111, /* mp_read error state */ diff --git a/cyassl/ctaocrypt/port.h b/cyassl/ctaocrypt/port.h new file mode 100644 index 000000000..37ac4fccf --- /dev/null +++ b/cyassl/ctaocrypt/port.h @@ -0,0 +1,108 @@ +/* port.h + * + * Copyright (C) 2006-2013 wolfSSL Inc. + * + * This file is part of CyaSSL. + * + * CyaSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * CyaSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +#ifndef CTAO_CRYPT_PORT_H +#define CTAO_CRYPT_PORT_H + + +#ifdef __cplusplus + extern "C" { +#endif + + +#ifdef USE_WINDOWS_API + #ifdef CYASSL_GAME_BUILD + #include "system/xtl.h" + #else + #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN) + /* On WinCE winsock2.h must be included before windows.h */ + #include + #endif + #include + #endif +#elif defined(THREADX) + #ifndef SINGLE_THREADED + #include "tx_api.h" + #endif +#elif defined(MICRIUM) + /* do nothing, just don't pick Unix */ +#elif defined(FREERTOS) || defined(CYASSL_SAFERTOS) + /* do nothing */ +#elif defined(EBSNET) + /* do nothing */ +#elif defined(FREESCALE_MQX) + /* do nothing */ +#elif defined(CYASSL_MDK_ARM) + #include +#else + #ifndef SINGLE_THREADED + #define CYASSL_PTHREADS + #include + #endif + #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS) + #include /* for close of BIO */ + #endif +#endif + + +#ifdef SINGLE_THREADED + typedef int CyaSSL_Mutex; +#else /* MULTI_THREADED */ + /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */ + #ifdef FREERTOS + typedef xSemaphoreHandle CyaSSL_Mutex; + #elif defined(CYASSL_SAFERTOS) + typedef struct CyaSSL_Mutex { + signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES]; + xSemaphoreHandle mutex; + } CyaSSL_Mutex; + #elif defined(USE_WINDOWS_API) + typedef CRITICAL_SECTION CyaSSL_Mutex; + #elif defined(CYASSL_PTHREADS) + typedef pthread_mutex_t CyaSSL_Mutex; + #elif defined(THREADX) + typedef TX_MUTEX CyaSSL_Mutex; + #elif defined(MICRIUM) + typedef OS_MUTEX CyaSSL_Mutex; + #elif defined(EBSNET) + typedef RTP_MUTEX CyaSSL_Mutex; + #elif defined(FREESCALE_MQX) + typedef MUTEX_STRUCT CyaSSL_Mutex; + #elif defined(CYASSL_MDK_ARM) + typedef OS_MUT CyaSSL_Mutex; + #else + #error Need a mutex type in multithreaded mode + #endif /* USE_WINDOWS_API */ +#endif /* SINGLE_THREADED */ + +CYASSL_LOCAL int InitMutex(CyaSSL_Mutex*); +CYASSL_LOCAL int FreeMutex(CyaSSL_Mutex*); +CYASSL_LOCAL int LockMutex(CyaSSL_Mutex*); +CYASSL_LOCAL int UnLockMutex(CyaSSL_Mutex*); + + +#ifdef __cplusplus + } /* extern "C" */ +#endif + +#endif /* CTAO_CRYPT_PORT_H */ + diff --git a/cyassl/ctaocrypt/types.h b/cyassl/ctaocrypt/types.h index 1f714932a..4f694c654 100644 --- a/cyassl/ctaocrypt/types.h +++ b/cyassl/ctaocrypt/types.h @@ -24,6 +24,7 @@ #define CTAO_CRYPT_TYPES_H #include +#include #ifdef __cplusplus extern "C" { diff --git a/cyassl/error.h b/cyassl/error.h index 5526e0761..e32df7b6e 100644 --- a/cyassl/error.h +++ b/cyassl/error.h @@ -88,7 +88,6 @@ enum CyaSSL_ErrorCodes { ECC_MAKEKEY_ERROR = -253, /* Bad Make ECC Key */ ECC_EXPORT_ERROR = -254, /* Bad ECC Export Key */ ECC_SHARED_ERROR = -255, /* Bad ECC Shared Secret */ - BAD_MUTEX_ERROR = -256, /* Bad mutex */ NOT_CA_ERROR = -257, /* Not a CA cert error */ BAD_PATH_ERROR = -258, /* Bad path for opendir */ BAD_CERT_MANAGER_ERROR = -259, /* Bad Cert Manager */ diff --git a/cyassl/internal.h b/cyassl/internal.h index ac7e086ac..35bea43bb 100644 --- a/cyassl/internal.h +++ b/cyassl/internal.h @@ -949,41 +949,6 @@ struct CYASSL_CIPHER { }; -#ifdef SINGLE_THREADED - typedef int CyaSSL_Mutex; -#else /* MULTI_THREADED */ - /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */ - #ifdef FREERTOS - typedef xSemaphoreHandle CyaSSL_Mutex; - #elif defined(CYASSL_SAFERTOS) - typedef struct CyaSSL_Mutex { - signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES]; - xSemaphoreHandle mutex; - } CyaSSL_Mutex; - #elif defined(USE_WINDOWS_API) - typedef CRITICAL_SECTION CyaSSL_Mutex; - #elif defined(CYASSL_PTHREADS) - typedef pthread_mutex_t CyaSSL_Mutex; - #elif defined(THREADX) - typedef TX_MUTEX CyaSSL_Mutex; - #elif defined(MICRIUM) - typedef OS_MUTEX CyaSSL_Mutex; - #elif defined(EBSNET) - typedef RTP_MUTEX CyaSSL_Mutex; - #elif defined(FREESCALE_MQX) - typedef MUTEX_STRUCT CyaSSL_Mutex; - #elif defined(CYASSL_MDK_ARM) - typedef OS_MUT CyaSSL_Mutex; - #else - #error Need a mutex type in multithreaded mode - #endif /* USE_WINDOWS_API */ -#endif /* SINGLE_THREADED */ - -CYASSL_LOCAL int InitMutex(CyaSSL_Mutex*); -CYASSL_LOCAL int FreeMutex(CyaSSL_Mutex*); -CYASSL_LOCAL int LockMutex(CyaSSL_Mutex*); -CYASSL_LOCAL int UnLockMutex(CyaSSL_Mutex*); - typedef struct OCSP_Entry OCSP_Entry; #ifdef SHA_DIGEST_SIZE diff --git a/src/crl.c b/src/crl.c index 5fba84fdb..1c75ed81e 100644 --- a/src/crl.c +++ b/src/crl.c @@ -48,7 +48,7 @@ int InitCRL(CYASSL_CRL* crl, CYASSL_CERT_MANAGER* cm) crl->tid = 0; #endif if (InitMutex(&crl->crlLock) != 0) - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; return 0; } @@ -134,7 +134,7 @@ int CheckCertCRL(CYASSL_CRL* crl, DecodedCert* cert) if (LockMutex(&crl->crlLock) != 0) { CYASSL_MSG("LockMutex failed"); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } crle = crl->crlList; @@ -217,7 +217,7 @@ static int AddCRL(CYASSL_CRL* crl, DecodedCRL* dcrl) CYASSL_MSG("LockMutex failed"); FreeCRL_Entry(crle); XFREE(crle, NULL, DYNAMIC_TYPE_CRL_ENTRY); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } crle->next = crl->crlList; crl->crlList = crle; diff --git a/src/include.am b/src/include.am index 9bfc2315c..d187ab0d6 100644 --- a/src/include.am +++ b/src/include.am @@ -13,6 +13,7 @@ src_libcyassl_la_SOURCES = \ ctaocrypt/src/random.c \ ctaocrypt/src/sha256.c \ ctaocrypt/src/logging.c \ + ctaocrypt/src/port.c \ ctaocrypt/src/error.c src_libcyassl_la_LDFLAGS = ${AM_LDFLAGS} -no-undefined -version-info ${CYASSL_LIBRARY_VERSION} src_libcyassl_la_LIBADD = $(LIBM) diff --git a/src/internal.c b/src/internal.c index 414343740..3cb41db14 100644 --- a/src/internal.c +++ b/src/internal.c @@ -447,7 +447,7 @@ int InitSSL_Ctx(CYASSL_CTX* ctx, CYASSL_METHOD* method) if (InitMutex(&ctx->countMutex) < 0) { CYASSL_MSG("Mutex error on CTX init"); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } #ifndef NO_CERTS if (ctx->cm == NULL) { @@ -1524,7 +1524,7 @@ int InitSSL(CYASSL* ssl, CYASSL_CTX* ctx) /* increment CTX reference count */ if (LockMutex(&ctx->countMutex) != 0) { CYASSL_MSG("Couldn't lock CTX count mutex"); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } ctx->refCount++; UnLockMutex(&ctx->countMutex); @@ -5942,10 +5942,6 @@ void SetErrorString(int error, char* str) XSTRNCPY(str, "ECC DHE shared failure", max); break; - case BAD_MUTEX_ERROR: - XSTRNCPY(str, "Bad mutex, operation failed", max); - break; - case NOT_CA_ERROR: XSTRNCPY(str, "Not a CA by basic constraint error", max); break; @@ -10399,346 +10395,3 @@ static void PickHashSigAlgo(CYASSL* ssl, #endif /* NO_CYASSL_SERVER */ -#ifdef SINGLE_THREADED - -int InitMutex(CyaSSL_Mutex* m) -{ - (void)m; - return 0; -} - - -int FreeMutex(CyaSSL_Mutex *m) -{ - (void)m; - return 0; -} - - -int LockMutex(CyaSSL_Mutex *m) -{ - (void)m; - return 0; -} - - -int UnLockMutex(CyaSSL_Mutex *m) -{ - (void)m; - return 0; -} - -#else /* MULTI_THREAD */ - - #if defined(FREERTOS) - - int InitMutex(CyaSSL_Mutex* m) - { - int iReturn; - - *m = ( CyaSSL_Mutex ) xSemaphoreCreateMutex(); - if( *m != NULL ) - iReturn = 0; - else - iReturn = BAD_MUTEX_ERROR; - - return iReturn; - } - - int FreeMutex(CyaSSL_Mutex* m) - { - vSemaphoreDelete( *m ); - return 0; - } - - int LockMutex(CyaSSL_Mutex* m) - { - /* Assume an infinite block, or should there be zero block? */ - xSemaphoreTake( *m, portMAX_DELAY ); - return 0; - } - - int UnLockMutex(CyaSSL_Mutex* m) - { - xSemaphoreGive( *m ); - return 0; - } - - #elif defined(CYASSL_SAFERTOS) - - int InitMutex(CyaSSL_Mutex* m) - { - vSemaphoreCreateBinary(m->mutexBuffer, m->mutex); - if (m->mutex == NULL) - return BAD_MUTEX_ERROR; - - return 0; - } - - int FreeMutex(CyaSSL_Mutex* m) - { - (void)m; - return 0; - } - - int LockMutex(CyaSSL_Mutex* m) - { - /* Assume an infinite block */ - xSemaphoreTake(m->mutex, portMAX_DELAY); - return 0; - } - - int UnLockMutex(CyaSSL_Mutex* m) - { - xSemaphoreGive(m->mutex); - return 0; - } - - - #elif defined(USE_WINDOWS_API) - - int InitMutex(CyaSSL_Mutex* m) - { - InitializeCriticalSection(m); - return 0; - } - - - int FreeMutex(CyaSSL_Mutex* m) - { - DeleteCriticalSection(m); - return 0; - } - - - int LockMutex(CyaSSL_Mutex* m) - { - EnterCriticalSection(m); - return 0; - } - - - int UnLockMutex(CyaSSL_Mutex* m) - { - LeaveCriticalSection(m); - return 0; - } - - #elif defined(CYASSL_PTHREADS) - - int InitMutex(CyaSSL_Mutex* m) - { - if (pthread_mutex_init(m, 0) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - } - - - int FreeMutex(CyaSSL_Mutex* m) - { - if (pthread_mutex_destroy(m) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - } - - - int LockMutex(CyaSSL_Mutex* m) - { - if (pthread_mutex_lock(m) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - } - - - int UnLockMutex(CyaSSL_Mutex* m) - { - if (pthread_mutex_unlock(m) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - } - - #elif defined(THREADX) - - int InitMutex(CyaSSL_Mutex* m) - { - if (tx_mutex_create(m, "CyaSSL Mutex", TX_NO_INHERIT) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - } - - - int FreeMutex(CyaSSL_Mutex* m) - { - if (tx_mutex_delete(m) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - } - - - int LockMutex(CyaSSL_Mutex* m) - { - if (tx_mutex_get(m, TX_WAIT_FOREVER) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - } - - - int UnLockMutex(CyaSSL_Mutex* m) - { - if (tx_mutex_put(m) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - } - - #elif defined(MICRIUM) - - int InitMutex(CyaSSL_Mutex* m) - { - #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) - if (NetSecure_OS_MutexCreate(m) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - #else - return 0; - #endif - } - - - int FreeMutex(CyaSSL_Mutex* m) - { - #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) - if (NetSecure_OS_FreeMutex(m) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - #else - return 0; - #endif - } - - - int LockMutex(CyaSSL_Mutex* m) - { - #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) - if (NetSecure_OS_LockMutex(m) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - #else - return 0; - #endif - } - - - int UnLockMutex(CyaSSL_Mutex* m) - { - #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) - if (NetSecure_OS_UnLockMutex(m) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - #else - return 0; - #endif - - } - - #elif defined(EBSNET) - - int InitMutex(CyaSSL_Mutex* m) - { - if (rtp_sig_mutex_alloc(m, "CyaSSL Mutex") == -1) - return BAD_MUTEX_ERROR; - else - return 0; - } - - int FreeMutex(CyaSSL_Mutex* m) - { - rtp_sig_mutex_free(*m); - return 0; - } - - int LockMutex(CyaSSL_Mutex* m) - { - if (rtp_sig_mutex_claim_timed(*m, RTIP_INF) == 0) - return 0; - else - return BAD_MUTEX_ERROR; - } - - int UnLockMutex(CyaSSL_Mutex* m) - { - rtp_sig_mutex_release(*m); - return 0; - } - - #elif defined(FREESCALE_MQX) - - int InitMutex(CyaSSL_Mutex* m) - { - if (_mutex_init(m, NULL) == MQX_EOK) - return 0; - else - return BAD_MUTEX_ERROR; - } - - int FreeMutex(CyaSSL_Mutex* m) - { - if (_mutex_destroy(m) == MQX_EOK) - return 0; - else - return BAD_MUTEX_ERROR; - } - - int LockMutex(CyaSSL_Mutex* m) - { - if (_mutex_lock(m) == MQX_EOK) - return 0; - else - return BAD_MUTEX_ERROR; - } - - int UnLockMutex(CyaSSL_Mutex* m) - { - if (_mutex_unlock(m) == MQX_EOK) - return 0; - else - return BAD_MUTEX_ERROR; - } - - #elif defined(CYASSL_MDK_ARM) - - int InitMutex(CyaSSL_Mutex* m) - { - os_mut_init (m); - return 0; - } - - int FreeMutex(CyaSSL_Mutex* m) - { - return(0) ; - } - - int LockMutex(CyaSSL_Mutex* m) - { - os_mut_wait (m, 0xffff); - return(0) ; - } - - int UnLockMutex(CyaSSL_Mutex* m) - { - os_mut_release (m); - return 0; - } - #endif /* USE_WINDOWS_API */ -#endif /* SINGLE_THREADED */ diff --git a/src/ssl.c b/src/ssl.c index 253112e60..ad7dad04b 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -1034,7 +1034,7 @@ int CyaSSL_CertManagerUnloadCAs(CYASSL_CERT_MANAGER* cm) return BAD_FUNC_ARG; if (LockMutex(&cm->caLock) != 0) - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; FreeSignerTable(cm->caTable, CA_TABLE_SIZE, NULL); @@ -1351,7 +1351,7 @@ int AddCA(CYASSL_CERT_MANAGER* cm, buffer der, int type, int verify) } else { CYASSL_MSG(" CA Mutex Lock failed"); - ret = BAD_MUTEX_ERROR; + ret = BAD_MUTEX_E; FreeSigner(signer, cm->heap); } } @@ -1452,15 +1452,15 @@ int CyaSSL_Init(void) if (initRefCount == 0) { #ifndef NO_SESSION_CACHE if (InitMutex(&session_mutex) != 0) - ret = BAD_MUTEX_ERROR; + ret = BAD_MUTEX_E; #endif if (InitMutex(&count_mutex) != 0) - ret = BAD_MUTEX_ERROR; + ret = BAD_MUTEX_E; } if (ret == SSL_SUCCESS) { if (LockMutex(&count_mutex) != 0) { CYASSL_MSG("Bad Lock Mutex count"); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } initRefCount++; UnLockMutex(&count_mutex); @@ -3140,7 +3140,7 @@ int CyaSSL_memsave_session_cache(void* mem, int sz) if (LockMutex(&session_mutex) != 0) { CYASSL_MSG("Session cache mutex lock failed"); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } for (i = 0; i < cache_header.rows; ++i) @@ -3189,7 +3189,7 @@ int CyaSSL_memrestore_session_cache(const void* mem, int sz) if (LockMutex(&session_mutex) != 0) { CYASSL_MSG("Session cache mutex lock failed"); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } for (i = 0; i < cache_header.rows; ++i) @@ -3243,7 +3243,7 @@ int CyaSSL_save_session_cache(const char *fname) if (LockMutex(&session_mutex) != 0) { CYASSL_MSG("Session cache mutex lock failed"); XFCLOSE(file); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } /* session cache */ @@ -3314,7 +3314,7 @@ int CyaSSL_restore_session_cache(const char *fname) if (LockMutex(&session_mutex) != 0) { CYASSL_MSG("Session cache mutex lock failed"); XFCLOSE(file); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } /* session cache */ @@ -3661,7 +3661,7 @@ int CM_SaveCertCache(CYASSL_CERT_MANAGER* cm, const char* fname) if (LockMutex(&cm->caLock) != 0) { CYASSL_MSG("LockMutex on caLock failed"); XFCLOSE(file); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } memSz = GetCertCacheMemSize(cm); @@ -3751,7 +3751,7 @@ int CM_MemSaveCertCache(CYASSL_CERT_MANAGER* cm, void* mem, int sz, int* used) if (LockMutex(&cm->caLock) != 0) { CYASSL_MSG("LockMutex on caLock failed"); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } ret = DoMemSaveCertCache(cm, mem, sz); @@ -3790,7 +3790,7 @@ int CM_MemRestoreCertCache(CYASSL_CERT_MANAGER* cm, const void* mem, int sz) if (LockMutex(&cm->caLock) != 0) { CYASSL_MSG("LockMutex on caLock failed"); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } FreeSignerTable(cm->caTable, CA_TABLE_SIZE, cm->heap); @@ -3820,7 +3820,7 @@ int CM_GetCertCacheMemSize(CYASSL_CERT_MANAGER* cm) if (LockMutex(&cm->caLock) != 0) { CYASSL_MSG("LockMutex on caLock failed"); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } sz = GetCertCacheMemSize(cm); @@ -4463,7 +4463,7 @@ int CyaSSL_Cleanup(void) if (LockMutex(&count_mutex) != 0) { CYASSL_MSG("Bad Lock Mutex count"); - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } release = initRefCount-- == 1; @@ -4477,10 +4477,10 @@ int CyaSSL_Cleanup(void) #ifndef NO_SESSION_CACHE if (FreeMutex(&session_mutex) != 0) - ret = BAD_MUTEX_ERROR; + ret = BAD_MUTEX_E; #endif if (FreeMutex(&count_mutex) != 0) - ret = BAD_MUTEX_ERROR; + ret = BAD_MUTEX_E; return ret; } @@ -4729,7 +4729,7 @@ int AddSession(CYASSL* ssl) row = HashSession(ssl->arrays->sessionID, ID_LEN) % SESSION_ROWS; if (LockMutex(&session_mutex) != 0) - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; idx = SessionCache[row].nextIdx++; #ifdef SESSION_INDEX @@ -4784,7 +4784,7 @@ int AddSession(CYASSL* ssl) #endif /* NO_CLIENT_CACHE */ if (UnLockMutex(&session_mutex) != 0) - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; return 0; } @@ -4810,7 +4810,7 @@ int CyaSSL_GetSessionAtIndex(int idx, CYASSL_SESSION* session) col = idx & SESSIDX_IDX_MASK; if (LockMutex(&session_mutex) != 0) { - return BAD_MUTEX_ERROR; + return BAD_MUTEX_E; } if (row < SESSION_ROWS && @@ -4821,7 +4821,7 @@ int CyaSSL_GetSessionAtIndex(int idx, CYASSL_SESSION* session) } if (UnLockMutex(&session_mutex) != 0) - result = BAD_MUTEX_ERROR; + result = BAD_MUTEX_E; CYASSL_LEAVE("CyaSSL_GetSessionAtIndex", result); return result;