diff --git a/IDE/MDK-ARM/MDK-ARM/wolfSSL/shell.c b/IDE/MDK-ARM/MDK-ARM/wolfSSL/shell.c index 39d97db73..0b02ab437 100644 --- a/IDE/MDK-ARM/MDK-ARM/wolfSSL/shell.c +++ b/IDE/MDK-ARM/MDK-ARM/wolfSSL/shell.c @@ -491,7 +491,7 @@ static void command_invoke(void *args) func = (void(*)(void *))((func_args *)args)->argv[0] ; #ifdef HAVE_KEIL_RTX - LockMutex((wolfSSL_Mutex *)&command_mutex) ; + wc_LockMutex((wolfSSL_Mutex *)&command_mutex) ; #endif iteration = for_iteration ; for(i=0; i< iteration; i++) { @@ -509,7 +509,7 @@ static void command_invoke(void *args) if(iteration > 1) for_iteration = 1 ; #ifdef HAVE_KEIL_RTX - UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; + wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; os_tsk_delete_self() ; #endif } @@ -548,7 +548,7 @@ void shell_main(void) { #if defined(HAVE_KEIL_RTX) - InitMutex(&command_mutex) ; + wc_InitMutex(&command_mutex) ; #endif printf("Starting Shell\n") ; while(1) { @@ -558,14 +558,14 @@ void shell_main(void) { args.argv[0] = (char *) commandTable[i].func ; if(bf_flg == FORGROUND) { #ifdef HAVE_KEIL_RTX - UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; + wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; os_tsk_create_user_ex( (void(*)(void *))&command_invoke, 7, command_stack, COMMAND_STACK_SIZE, &args) ; #else command_invoke(&args) ; #endif #ifdef HAVE_KEIL_RTX - LockMutex((wolfSSL_Mutex *)&command_mutex) ; + wc_LockMutex((wolfSSL_Mutex *)&command_mutex) ; #endif } else { #if (!defined(NO_SIMPLE_SERVER) && \ diff --git a/IDE/MDK5-ARM/Projects/wolfSSL-Full/shell.c b/IDE/MDK5-ARM/Projects/wolfSSL-Full/shell.c index b24693767..ee00e4dc6 100644 --- a/IDE/MDK5-ARM/Projects/wolfSSL-Full/shell.c +++ b/IDE/MDK5-ARM/Projects/wolfSSL-Full/shell.c @@ -562,7 +562,7 @@ static void command_invoke(void const *args) func = (void(*)(void const *))((func_args *)args)->argv[0] ; #if defined(HAVE_KEIL_RTX) - LockMutex((wolfSSL_Mutex *)&command_mutex) ; + wc_LockMutex((wolfSSL_Mutex *)&command_mutex) ; #endif iteration = for_iteration ; for(i=0; i< iteration; i++) { @@ -582,7 +582,7 @@ static void command_invoke(void const *args) for_iteration = 1 ; osDelay(20000) ; #ifdef HAVE_KEIL_RTX - UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; + wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; #ifdef WOLFSSL_CMSIS_RTOS osThreadTerminate(osThreadGetId()) ; #else @@ -635,7 +635,7 @@ void shell_main(void *arg) { /* Dummy for avoiding warning: BackGround is defined but not used. */ #if defined(HAVE_KEIL_RTX) - InitMutex(&command_mutex) ; + wc_InitMutex(&command_mutex) ; #endif help_comm(NULL) ; @@ -647,13 +647,13 @@ void shell_main(void *arg) { args.argv[0] = (char *) commandTable[i].func ; if(bf_flg == FORGROUND) { #if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS) - UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; + wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; os_tsk_create_user_ex( (void(*)(void *))&command_invoke, 7, command_stack, COMMAND_STACK_SIZE, &args) ; os_tsk_pass (); #else #if defined(WOLFSSL_CMSIS_RTOS) - UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; + wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ; cmd = osThreadCreate (osThread (command_invoke) , &args); if(cmd == NULL) { printf("Cannon create command thread\n") ; @@ -664,7 +664,7 @@ void shell_main(void *arg) { #endif #endif #ifdef HAVE_KEIL_RTX - LockMutex((wolfSSL_Mutex *)&command_mutex) ; + wc_LockMutex((wolfSSL_Mutex *)&command_mutex) ; #endif } else { #if (!defined(NO_SIMPLE_SERVER) && \ diff --git a/src/crl.c b/src/crl.c index 18cb6f71b..fcc925af7 100644 --- a/src/crl.c +++ b/src/crl.c @@ -65,7 +65,7 @@ int InitCRL(WOLFSSL_CRL* crl, WOLFSSL_CERT_MANAGER* cm) return BAD_COND_E; } #endif - if (InitMutex(&crl->crlLock) != 0) { + if (wc_InitMutex(&crl->crlLock) != 0) { WOLFSSL_MSG("Init Mutex failed"); return BAD_MUTEX_E; } @@ -144,7 +144,7 @@ void FreeCRL(WOLFSSL_CRL* crl, int dynamic) } pthread_cond_destroy(&crl->cond); #endif - FreeMutex(&crl->crlLock); + wc_FreeMutex(&crl->crlLock); if (dynamic) /* free self */ XFREE(crl, crl->heap, DYNAMIC_TYPE_CRL); } @@ -159,8 +159,8 @@ int CheckCertCRL(WOLFSSL_CRL* crl, DecodedCert* cert) WOLFSSL_ENTER("CheckCertCRL"); - if (LockMutex(&crl->crlLock) != 0) { - WOLFSSL_MSG("LockMutex failed"); + if (wc_LockMutex(&crl->crlLock) != 0) { + WOLFSSL_MSG("wc_LockMutex failed"); return BAD_MUTEX_E; } @@ -203,7 +203,7 @@ int CheckCertCRL(WOLFSSL_CRL* crl, DecodedCert* cert) } } - UnLockMutex(&crl->crlLock); + wc_UnLockMutex(&crl->crlLock); if (foundEntry == 0) { WOLFSSL_MSG("Couldn't find CRL for status check"); @@ -248,15 +248,15 @@ static int AddCRL(WOLFSSL_CRL* crl, DecodedCRL* dcrl) return -1; } - if (LockMutex(&crl->crlLock) != 0) { - WOLFSSL_MSG("LockMutex failed"); + if (wc_LockMutex(&crl->crlLock) != 0) { + WOLFSSL_MSG("wc_LockMutex failed"); FreeCRL_Entry(crle, crl->heap); XFREE(crle, crl->heap, DYNAMIC_TYPE_CRL_ENTRY); return BAD_MUTEX_E; } crle->next = crl->crlList; crl->crlList = crle; - UnLockMutex(&crl->crlLock); + wc_UnLockMutex(&crl->crlLock); return 0; } @@ -337,15 +337,15 @@ static int SignalSetup(WOLFSSL_CRL* crl, int status) int ret; /* signal to calling thread we're setup */ - if (LockMutex(&crl->crlLock) != 0) { - WOLFSSL_MSG("LockMutex crlLock failed"); + if (wc_LockMutex(&crl->crlLock) != 0) { + WOLFSSL_MSG("wc_LockMutex crlLock failed"); return BAD_MUTEX_E; } crl->setup = status; ret = pthread_cond_signal(&crl->cond); - UnLockMutex(&crl->crlLock); + wc_UnLockMutex(&crl->crlLock); if (ret != 0) return BAD_COND_E; @@ -403,8 +403,8 @@ static int SwapLists(WOLFSSL_CRL* crl) } } - if (LockMutex(&crl->crlLock) != 0) { - WOLFSSL_MSG("LockMutex failed"); + if (wc_LockMutex(&crl->crlLock) != 0) { + WOLFSSL_MSG("wc_LockMutex failed"); FreeCRL(tmp, 0); #ifdef WOLFSSL_SMALL_STACK XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -418,7 +418,7 @@ static int SwapLists(WOLFSSL_CRL* crl) tmp->crlList = crl->crlList; crl->crlList = newList; - UnLockMutex(&crl->crlLock); + wc_UnLockMutex(&crl->crlLock); FreeCRL(tmp, 0); @@ -747,8 +747,8 @@ static int StartMonitorCRL(WOLFSSL_CRL* crl) } /* wait for setup to complete */ - if (LockMutex(&crl->crlLock) != 0) { - WOLFSSL_MSG("LockMutex crlLock error"); + if (wc_LockMutex(&crl->crlLock) != 0) { + WOLFSSL_MSG("wc_LockMutex crlLock error"); return BAD_MUTEX_E; } @@ -762,7 +762,7 @@ static int StartMonitorCRL(WOLFSSL_CRL* crl) if (crl->setup < 0) ret = crl->setup; /* store setup error */ - UnLockMutex(&crl->crlLock); + wc_UnLockMutex(&crl->crlLock); if (ret < 0) { WOLFSSL_MSG("DoMonitor setup failure"); diff --git a/src/internal.c b/src/internal.c index ae8d40bd3..22d3ee35e 100755 --- a/src/internal.c +++ b/src/internal.c @@ -313,12 +313,12 @@ static word32 GetEntropy(unsigned char* out, word32 num_bytes) if ((rngMutex = (wolfSSL_Mutex*)XMALLOC(sizeof(wolfSSL_Mutex), 0, DYNAMIC_TYPE_TLSX)) == NULL) return DRBG_OUT_OF_MEMORY; - InitMutex(rngMutex); + wc_InitMutex(rngMutex); } - ret |= LockMutex(rngMutex); + ret |= wc_LockMutex(rngMutex); ret |= wc_RNG_GenerateBlock(rng, out, num_bytes); - ret |= UnLockMutex(rngMutex); + ret |= wc_UnLockMutex(rngMutex); if (ret != 0) return DRBG_ENTROPY_FAIL; @@ -1337,7 +1337,7 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap) ctx->timeout = WOLFSSL_SESSION_TIMEOUT; ctx->minDowngrade = TLSv1_MINOR; /* current default */ - if (InitMutex(&ctx->countMutex) < 0) { + if (wc_InitMutex(&ctx->countMutex) < 0) { WOLFSSL_MSG("Mutex error on CTX init"); ctx->err = CTX_INIT_MUTEX_E; return BAD_MUTEX_E; @@ -1501,7 +1501,7 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx) if (ctx->heap != (void*)WOLFSSL_HEAP_TEST) { #endif WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)(ctx->heap); - FreeMutex(&((WOLFSSL_HEAP*)(hint->memory))->memory_mutex); + wc_FreeMutex(&((WOLFSSL_HEAP*)(hint->memory))->memory_mutex); #ifdef WOLFSSL_HEAP_TEST } #endif @@ -1514,7 +1514,7 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx) { int doFree = 0; - if (LockMutex(&ctx->countMutex) != 0) { + if (wc_LockMutex(&ctx->countMutex) != 0) { WOLFSSL_MSG("Couldn't lock count mutex"); /* check error state, if mutex error code then mutex init failed but @@ -1528,12 +1528,12 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx) ctx->refCount--; if (ctx->refCount == 0) doFree = 1; - UnLockMutex(&ctx->countMutex); + wc_UnLockMutex(&ctx->countMutex); if (doFree) { WOLFSSL_MSG("CTX ref count down to 0, doing full free"); SSL_CtxResourceFree(ctx); - FreeMutex(&ctx->countMutex); + wc_FreeMutex(&ctx->countMutex); XFREE(ctx, ctx->heap, DYNAMIC_TYPE_CTX); } else { @@ -3120,12 +3120,12 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx) } /* increment CTX reference count */ - if (LockMutex(&ctx->countMutex) != 0) { + if (wc_LockMutex(&ctx->countMutex) != 0) { WOLFSSL_MSG("Couldn't lock CTX count mutex"); return BAD_MUTEX_E; } ctx->refCount++; - UnLockMutex(&ctx->countMutex); + wc_UnLockMutex(&ctx->countMutex); ssl->ctx = ctx; /* only for passing to calls, options could change */ ssl->version = ctx->method->version; @@ -3274,7 +3274,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx) ctx_hint = ((WOLFSSL_HEAP_HINT*)(ctx->heap)); /* lock and check IO count / handshake count */ - if (LockMutex(&(ctx_hint->memory->memory_mutex)) != 0) { + if (wc_LockMutex(&(ctx_hint->memory->memory_mutex)) != 0) { WOLFSSL_MSG("Bad memory_mutex lock"); XFREE(ssl->heap, ctx->heap, DYNAMIC_TYPE_SSL); ssl->heap = NULL; /* free and set to NULL for IO counter */ @@ -3283,7 +3283,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx) if (ctx_hint->memory->maxHa > 0 && ctx_hint->memory->maxHa <= ctx_hint->memory->curHa) { WOLFSSL_MSG("At max number of handshakes for static memory"); - UnLockMutex(&(ctx_hint->memory->memory_mutex)); + wc_UnLockMutex(&(ctx_hint->memory->memory_mutex)); XFREE(ssl->heap, ctx->heap, DYNAMIC_TYPE_SSL); ssl->heap = NULL; /* free and set to NULL for IO counter */ return MEMORY_E; @@ -3292,7 +3292,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx) if (ctx_hint->memory->maxIO > 0 && ctx_hint->memory->maxIO <= ctx_hint->memory->curIO) { WOLFSSL_MSG("At max number of IO allowed for static memory"); - UnLockMutex(&(ctx_hint->memory->memory_mutex)); + wc_UnLockMutex(&(ctx_hint->memory->memory_mutex)); XFREE(ssl->heap, ctx->heap, DYNAMIC_TYPE_SSL); ssl->heap = NULL; /* free and set to NULL for IO counter */ return MEMORY_E; @@ -3301,7 +3301,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx) ctx_hint->memory->curHa++; ssl_hint->memory = ctx_hint->memory; ssl_hint->haFlag = 1; - UnLockMutex(&(ctx_hint->memory->memory_mutex)); + wc_UnLockMutex(&(ctx_hint->memory->memory_mutex)); /* check if tracking stats */ if (ctx_hint->memory->flag & WOLFMEM_TRACK_STATS) { @@ -3315,24 +3315,24 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx) /* check if using fixed IO buffers */ if (ctx_hint->memory->flag & WOLFMEM_IO_POOL_FIXED) { - if (LockMutex(&(ctx_hint->memory->memory_mutex)) != 0) { + if (wc_LockMutex(&(ctx_hint->memory->memory_mutex)) != 0) { WOLFSSL_MSG("Bad memory_mutex lock"); return BAD_MUTEX_E; } if (SetFixedIO(ctx_hint->memory, &(ssl_hint->inBuf)) != 1) { - UnLockMutex(&(ctx_hint->memory->memory_mutex)); + wc_UnLockMutex(&(ctx_hint->memory->memory_mutex)); return MEMORY_E; } if (SetFixedIO(ctx_hint->memory, &(ssl_hint->outBuf)) != 1) { - UnLockMutex(&(ctx_hint->memory->memory_mutex)); + wc_UnLockMutex(&(ctx_hint->memory->memory_mutex)); return MEMORY_E; } if (ssl_hint->outBuf == NULL || ssl_hint->inBuf == NULL) { WOLFSSL_MSG("Not enough memory to create fixed IO buffers"); - UnLockMutex(&(ctx_hint->memory->memory_mutex)); + wc_UnLockMutex(&(ctx_hint->memory->memory_mutex)); return MEMORY_E; } - UnLockMutex(&(ctx_hint->memory->memory_mutex)); + wc_UnLockMutex(&(ctx_hint->memory->memory_mutex)); } #ifdef WOLFSSL_HEAP_TEST } @@ -3727,7 +3727,7 @@ void SSL_ResourceFree(WOLFSSL* ssl) WOLFSSL_HEAP* ctx_heap; ctx_heap = ssl_hint->memory; - if (LockMutex(&(ctx_heap->memory_mutex)) != 0) { + if (wc_LockMutex(&(ctx_heap->memory_mutex)) != 0) { WOLFSSL_MSG("Bad memory_mutex lock"); } ctx_heap->curIO--; @@ -3740,7 +3740,7 @@ void SSL_ResourceFree(WOLFSSL* ssl) if (ssl_hint->haFlag) { /* check if handshake count has been decreased*/ ctx_heap->curHa--; } - UnLockMutex(&(ctx_heap->memory_mutex)); + wc_UnLockMutex(&(ctx_heap->memory_mutex)); /* check if tracking stats */ if (ctx_heap->flag & WOLFMEM_TRACK_STATS) { @@ -3913,12 +3913,12 @@ void FreeHandshakeResources(WOLFSSL* ssl) WOLFSSL_HEAP* ctx_heap; ctx_heap = ssl_hint->memory; - if (LockMutex(&(ctx_heap->memory_mutex)) != 0) { + if (wc_LockMutex(&(ctx_heap->memory_mutex)) != 0) { WOLFSSL_MSG("Bad memory_mutex lock"); } ctx_heap->curHa--; ssl_hint->haFlag = 0; /* set to zero since handshake has been dec */ - UnLockMutex(&(ctx_heap->memory_mutex)); + wc_UnLockMutex(&(ctx_heap->memory_mutex)); #ifdef WOLFSSL_HEAP_TEST } #endif @@ -10574,11 +10574,11 @@ int SendCertificateStatus(WOLFSSL* ssl) if (ret != 0) { XFREE(request, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST); } - else if (!ssl->buffers.weOwnCert && 0 == LockMutex( + else if (!ssl->buffers.weOwnCert && 0 == wc_LockMutex( &ssl->ctx->cm->ocsp_stapling->ocspLock)) { if (!ssl->ctx->certOcspRequest) ssl->ctx->certOcspRequest = request; - UnLockMutex(&ssl->ctx->cm->ocsp_stapling->ocspLock); + wc_UnLockMutex(&ssl->ctx->cm->ocsp_stapling->ocspLock); } } @@ -10671,12 +10671,12 @@ int SendCertificateStatus(WOLFSSL* ssl) if (ret != 0) { XFREE(request, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST); } - else if (!ssl->buffers.weOwnCert && 0 == LockMutex( + else if (!ssl->buffers.weOwnCert && 0 == wc_LockMutex( &ssl->ctx->cm->ocsp_stapling->ocspLock)) { if (!ssl->ctx->certOcspRequest) ssl->ctx->certOcspRequest = request; - UnLockMutex(&ssl->ctx->cm->ocsp_stapling->ocspLock); + wc_UnLockMutex(&ssl->ctx->cm->ocsp_stapling->ocspLock); } } @@ -10751,12 +10751,12 @@ int SendCertificateStatus(WOLFSSL* ssl) break; } else if (!ssl->buffers.weOwnCertChain && 0 == - LockMutex( + wc_LockMutex( &ssl->ctx->cm->ocsp_stapling->ocspLock)) { if (!ssl->ctx->chainOcspRequest[i]) ssl->ctx->chainOcspRequest[i] = request; - UnLockMutex( + wc_UnLockMutex( &ssl->ctx->cm->ocsp_stapling->ocspLock); } diff --git a/src/ocsp.c b/src/ocsp.c index 80dc2c072..e8de3d512 100644 --- a/src/ocsp.c +++ b/src/ocsp.c @@ -49,7 +49,7 @@ int InitOCSP(WOLFSSL_OCSP* ocsp, WOLFSSL_CERT_MANAGER* cm) ForceZero(ocsp, sizeof(WOLFSSL_OCSP)); - if (InitMutex(&ocsp->ocspLock) != 0) + if (wc_InitMutex(&ocsp->ocspLock) != 0) return BAD_MUTEX_E; ocsp->cm = cm; @@ -102,7 +102,7 @@ void FreeOCSP(WOLFSSL_OCSP* ocsp, int dynamic) XFREE(entry, ocsp->cm->heap, DYNAMIC_TYPE_OCSP_ENTRY); } - FreeMutex(&ocsp->ocspLock); + wc_FreeMutex(&ocsp->ocspLock); if (dynamic) XFREE(ocsp, ocsp->cm->heap, DYNAMIC_TYPE_OCSP); @@ -167,7 +167,7 @@ static int GetOcspEntry(WOLFSSL_OCSP* ocsp, OcspRequest* request, *entry = NULL; - if (LockMutex(&ocsp->ocspLock) != 0) { + if (wc_LockMutex(&ocsp->ocspLock) != 0) { WOLFSSL_LEAVE("CheckCertOCSP", BAD_MUTEX_E); return BAD_MUTEX_E; } @@ -189,7 +189,7 @@ static int GetOcspEntry(WOLFSSL_OCSP* ocsp, OcspRequest* request, } } - UnLockMutex(&ocsp->ocspLock); + wc_UnLockMutex(&ocsp->ocspLock); return *entry ? 0 : MEMORY_ERROR; } @@ -204,7 +204,7 @@ static int GetOcspStatus(WOLFSSL_OCSP* ocsp, OcspRequest* request, *status = NULL; - if (LockMutex(&ocsp->ocspLock) != 0) { + if (wc_LockMutex(&ocsp->ocspLock) != 0) { WOLFSSL_LEAVE("CheckCertOCSP", BAD_MUTEX_E); return BAD_MUTEX_E; } @@ -239,7 +239,7 @@ static int GetOcspStatus(WOLFSSL_OCSP* ocsp, OcspRequest* request, } } - UnLockMutex(&ocsp->ocspLock); + wc_UnLockMutex(&ocsp->ocspLock); return ret; } @@ -346,7 +346,7 @@ int CheckOcspRequest(WOLFSSL_OCSP* ocsp, OcspRequest* ocspRequest, ret = xstat2err(ocspResponse->status->status); - if (LockMutex(&ocsp->ocspLock) != 0) + if (wc_LockMutex(&ocsp->ocspLock) != 0) ret = BAD_MUTEX_E; else { if (status != NULL) { @@ -383,7 +383,7 @@ int CheckOcspRequest(WOLFSSL_OCSP* ocsp, OcspRequest* ocspRequest, } } - UnLockMutex(&ocsp->ocspLock); + wc_UnLockMutex(&ocsp->ocspLock); } } else diff --git a/src/sniffer.c b/src/sniffer.c index 9fcfc37f9..d6185c200 100644 --- a/src/sniffer.c +++ b/src/sniffer.c @@ -411,9 +411,9 @@ static word32 MissedDataSessions = 0; /* # of sessions with missed data */ static void UpdateMissedDataSessions(void) { - LockMutex(&RecoveryMutex); + wc_LockMutex(&RecoveryMutex); MissedDataSessions += 1; - UnLockMutex(&RecoveryMutex); + wc_UnLockMutex(&RecoveryMutex); } @@ -421,9 +421,9 @@ static void UpdateMissedDataSessions(void) void ssl_InitSniffer(void) { wolfSSL_Init(); - InitMutex(&ServerListMutex); - InitMutex(&SessionMutex); - InitMutex(&RecoveryMutex); + wc_InitMutex(&ServerListMutex); + wc_InitMutex(&SessionMutex); + wc_InitMutex(&RecoveryMutex); } @@ -461,10 +461,10 @@ static void FreeSnifferServer(SnifferServer* srv) { if (srv) { #ifdef HAVE_SNI - LockMutex(&srv->namedKeysMutex); + wc_LockMutex(&srv->namedKeysMutex); FreeNamedKeyList(srv->namedKeys); - UnLockMutex(&srv->namedKeysMutex); - FreeMutex(&srv->namedKeysMutex); + wc_UnLockMutex(&srv->namedKeysMutex); + wc_FreeMutex(&srv->namedKeysMutex); #endif SSL_CTX_free(srv->ctx); } @@ -526,8 +526,8 @@ void ssl_FreeSniffer(void) SnifferSession* removeSession; int i; - LockMutex(&ServerListMutex); - LockMutex(&SessionMutex); + wc_LockMutex(&ServerListMutex); + wc_LockMutex(&SessionMutex); srv = ServerList; while (srv) { @@ -545,12 +545,12 @@ void ssl_FreeSniffer(void) } } - UnLockMutex(&SessionMutex); - UnLockMutex(&ServerListMutex); + wc_UnLockMutex(&SessionMutex); + wc_UnLockMutex(&ServerListMutex); - FreeMutex(&RecoveryMutex); - FreeMutex(&SessionMutex); - FreeMutex(&ServerListMutex); + wc_FreeMutex(&RecoveryMutex); + wc_FreeMutex(&SessionMutex); + wc_FreeMutex(&ServerListMutex); if (TraceFile) { TraceOn = 0; @@ -656,7 +656,7 @@ static void InitSnifferServer(SnifferServer* sniffer) sniffer->port = 0; #ifdef HAVE_SNI sniffer->namedKeys = 0; - InitMutex(&sniffer->namedKeysMutex); + wc_InitMutex(&sniffer->namedKeysMutex); #endif sniffer->next = 0; } @@ -1040,7 +1040,7 @@ static int IsServerRegistered(word32 addr) int ret = 0; /* false */ SnifferServer* sniffer; - LockMutex(&ServerListMutex); + wc_LockMutex(&ServerListMutex); sniffer = ServerList; while (sniffer) { @@ -1051,7 +1051,7 @@ static int IsServerRegistered(word32 addr) sniffer = sniffer->next; } - UnLockMutex(&ServerListMutex); + wc_UnLockMutex(&ServerListMutex); return ret; } @@ -1064,7 +1064,7 @@ static int IsPortRegistered(word32 port) int ret = 0; /* false */ SnifferServer* sniffer; - LockMutex(&ServerListMutex); + wc_LockMutex(&ServerListMutex); sniffer = ServerList; while (sniffer) { @@ -1075,7 +1075,7 @@ static int IsPortRegistered(word32 port) sniffer = sniffer->next; } - UnLockMutex(&ServerListMutex); + wc_UnLockMutex(&ServerListMutex); return ret; } @@ -1086,7 +1086,7 @@ static SnifferServer* GetSnifferServer(IpInfo* ipInfo, TcpInfo* tcpInfo) { SnifferServer* sniffer; - LockMutex(&ServerListMutex); + wc_LockMutex(&ServerListMutex); sniffer = ServerList; while (sniffer) { @@ -1097,7 +1097,7 @@ static SnifferServer* GetSnifferServer(IpInfo* ipInfo, TcpInfo* tcpInfo) sniffer = sniffer->next; } - UnLockMutex(&ServerListMutex); + wc_UnLockMutex(&ServerListMutex); return sniffer; } @@ -1122,7 +1122,7 @@ static SnifferSession* GetSnifferSession(IpInfo* ipInfo, TcpInfo* tcpInfo) assert(row <= HASH_SIZE); - LockMutex(&SessionMutex); + wc_LockMutex(&SessionMutex); session = SessionTable[row]; while (session) { @@ -1141,7 +1141,7 @@ static SnifferSession* GetSnifferSession(IpInfo* ipInfo, TcpInfo* tcpInfo) if (session) session->lastUsed= currTime; /* keep session alive, remove stale will */ /* leave alone */ - UnLockMutex(&SessionMutex); + wc_UnLockMutex(&SessionMutex); /* determine side */ if (session) { @@ -1315,10 +1315,10 @@ static int SetNamedPrivateKey(const char* name, const char* address, int port, } #ifdef HAVE_SNI else { - LockMutex(&sniffer->namedKeysMutex); + wc_LockMutex(&sniffer->namedKeysMutex); namedKey->next = sniffer->namedKeys; sniffer->namedKeys = namedKey; - UnLockMutex(&sniffer->namedKeysMutex); + wc_UnLockMutex(&sniffer->namedKeysMutex); } #endif @@ -1345,10 +1345,10 @@ int ssl_SetNamedPrivateKey(const char* name, TraceHeader(); TraceSetNamedServer(name, address, port, keyFile); - LockMutex(&ServerListMutex); + wc_LockMutex(&ServerListMutex); ret = SetNamedPrivateKey(name, address, port, keyFile, typeKey, password, error); - UnLockMutex(&ServerListMutex); + wc_UnLockMutex(&ServerListMutex); if (ret == 0) Trace(NEW_SERVER_STR); @@ -1369,10 +1369,10 @@ int ssl_SetPrivateKey(const char* address, int port, const char* keyFile, TraceHeader(); TraceSetServer(address, port, keyFile); - LockMutex(&ServerListMutex); + wc_LockMutex(&ServerListMutex); ret = SetNamedPrivateKey(NULL, address, port, keyFile, typeKey, password, error); - UnLockMutex(&ServerListMutex); + wc_UnLockMutex(&ServerListMutex); if (ret == 0) Trace(NEW_SERVER_STR); @@ -1824,7 +1824,7 @@ static int ProcessClientHello(const byte* input, int* sslBytes, if (nameSz >= sizeof(name)) nameSz = sizeof(name) - 1; name[nameSz] = 0; - LockMutex(&session->context->namedKeysMutex); + wc_LockMutex(&session->context->namedKeysMutex); namedKey = session->context->namedKeys; while (namedKey != NULL) { if (nameSz == namedKey->nameSz && @@ -1832,7 +1832,7 @@ static int ProcessClientHello(const byte* input, int* sslBytes, if (wolfSSL_use_PrivateKey_buffer(session->sslServer, namedKey->key, namedKey->keySz, SSL_FILETYPE_ASN1) != SSL_SUCCESS) { - UnLockMutex(&session->context->namedKeysMutex); + wc_UnLockMutex(&session->context->namedKeysMutex); SetError(CLIENT_HELLO_LATE_KEY_STR, error, session, FATAL_ERROR_STATE); return -1; @@ -1842,7 +1842,7 @@ static int ProcessClientHello(const byte* input, int* sslBytes, else namedKey = namedKey->next; } - UnLockMutex(&session->context->namedKeysMutex); + wc_UnLockMutex(&session->context->namedKeysMutex); } } #endif @@ -2296,7 +2296,7 @@ static void RemoveSession(SnifferSession* session, IpInfo* ipInfo, Trace(REMOVE_SESSION_STR); if (!haveLock) - LockMutex(&SessionMutex); + wc_LockMutex(&SessionMutex); current = SessionTable[row]; @@ -2315,7 +2315,7 @@ static void RemoveSession(SnifferSession* session, IpInfo* ipInfo, } if (!haveLock) - UnLockMutex(&SessionMutex); + wc_UnLockMutex(&SessionMutex); } @@ -2406,7 +2406,7 @@ static SnifferSession* CreateSession(IpInfo* ipInfo, TcpInfo* tcpInfo, row = SessionHash(ipInfo, tcpInfo); /* add it to the session table */ - LockMutex(&SessionMutex); + wc_LockMutex(&SessionMutex); session->next = SessionTable[row]; SessionTable[row] = session; @@ -2418,7 +2418,7 @@ static SnifferSession* CreateSession(IpInfo* ipInfo, TcpInfo* tcpInfo, RemoveStaleSessions(); } - UnLockMutex(&SessionMutex); + wc_UnLockMutex(&SessionMutex); /* determine headed side */ if (ipInfo->dst == session->context->server && @@ -3562,9 +3562,9 @@ int ssl_GetSessionStats(unsigned int* active, unsigned int* total, int ret; if (missedData) { - LockMutex(&RecoveryMutex); + wc_LockMutex(&RecoveryMutex); *missedData = MissedDataSessions; - UnLockMutex(&RecoveryMutex); + wc_UnLockMutex(&RecoveryMutex); } if (reassemblyMem) { @@ -3572,7 +3572,7 @@ int ssl_GetSessionStats(unsigned int* active, unsigned int* total, int i; *reassemblyMem = 0; - LockMutex(&SessionMutex); + wc_LockMutex(&SessionMutex); for (i = 0; i < HASH_SIZE; i++) { session = SessionTable[i]; while (session) { @@ -3581,7 +3581,7 @@ int ssl_GetSessionStats(unsigned int* active, unsigned int* total, session = session->next; } } - UnLockMutex(&SessionMutex); + wc_UnLockMutex(&SessionMutex); } ret = wolfSSL_get_session_stats(active, total, peak, maxSessions); diff --git a/src/ssl.c b/src/ssl.c index b874dde04..8c1dab759 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -2270,14 +2270,14 @@ WOLFSSL_CERT_MANAGER* wolfSSL_CertManagerNew_ex(void* heap) if (cm) { XMEMSET(cm, 0, sizeof(WOLFSSL_CERT_MANAGER)); - if (InitMutex(&cm->caLock) != 0) { + if (wc_InitMutex(&cm->caLock) != 0) { WOLFSSL_MSG("Bad mutex init"); wolfSSL_CertManagerFree(cm); return NULL; } #ifdef WOLFSSL_TRUST_PEER_CERT - if (InitMutex(&cm->tpLock) != 0) { + if (wc_InitMutex(&cm->tpLock) != 0) { WOLFSSL_MSG("Bad mutex init"); wolfSSL_CertManagerFree(cm); return NULL; @@ -2323,11 +2323,11 @@ void wolfSSL_CertManagerFree(WOLFSSL_CERT_MANAGER* cm) #endif #endif FreeSignerTable(cm->caTable, CA_TABLE_SIZE, cm->heap); - FreeMutex(&cm->caLock); + wc_FreeMutex(&cm->caLock); #ifdef WOLFSSL_TRUST_PEER_CERT FreeTrustedPeerTable(cm->tpTable, TP_TABLE_SIZE, cm->heap); - FreeMutex(&cm->tpLock); + wc_FreeMutex(&cm->tpLock); #endif XFREE(cm, cm->heap, DYNAMIC_TYPE_CERT_MANAGER); @@ -2344,12 +2344,12 @@ int wolfSSL_CertManagerUnloadCAs(WOLFSSL_CERT_MANAGER* cm) if (cm == NULL) return BAD_FUNC_ARG; - if (LockMutex(&cm->caLock) != 0) + if (wc_LockMutex(&cm->caLock) != 0) return BAD_MUTEX_E; FreeSignerTable(cm->caTable, CA_TABLE_SIZE, NULL); - UnLockMutex(&cm->caLock); + wc_UnLockMutex(&cm->caLock); return SSL_SUCCESS; @@ -2364,12 +2364,12 @@ int wolfSSL_CertManagerUnload_trust_peers(WOLFSSL_CERT_MANAGER* cm) if (cm == NULL) return BAD_FUNC_ARG; - if (LockMutex(&cm->tpLock) != 0) + if (wc_LockMutex(&cm->tpLock) != 0) return BAD_MUTEX_E; FreeTrustedPeerTable(cm->tpTable, TP_TABLE_SIZE, NULL); - UnLockMutex(&cm->tpLock); + wc_UnLockMutex(&cm->tpLock); return SSL_SUCCESS; @@ -2777,7 +2777,7 @@ int AlreadySigner(WOLFSSL_CERT_MANAGER* cm, byte* hash) int ret = 0; word32 row = HashSigner(hash); - if (LockMutex(&cm->caLock) != 0) + if (wc_LockMutex(&cm->caLock) != 0) return ret; signers = cm->caTable[row]; while (signers) { @@ -2793,7 +2793,7 @@ int AlreadySigner(WOLFSSL_CERT_MANAGER* cm, byte* hash) } signers = signers->next; } - UnLockMutex(&cm->caLock); + wc_UnLockMutex(&cm->caLock); return ret; } @@ -2813,7 +2813,7 @@ int AlreadyTrustedPeer(WOLFSSL_CERT_MANAGER* cm, byte* hash) int ret = 0; word32 row = TrustedPeerHashSigner(hash); - if (LockMutex(&cm->tpLock) != 0) + if (wc_LockMutex(&cm->tpLock) != 0) return ret; tp = cm->tpTable[row]; while (tp) { @@ -2829,7 +2829,7 @@ int AlreadyTrustedPeer(WOLFSSL_CERT_MANAGER* cm, byte* hash) } tp = tp->next; } - UnLockMutex(&cm->tpLock); + wc_UnLockMutex(&cm->tpLock); return ret; } @@ -2850,7 +2850,7 @@ TrustedPeerCert* GetTrustedPeer(void* vp, byte* hash, int type) row = TrustedPeerHashSigner(hash); - if (LockMutex(&cm->tpLock) != 0) + if (wc_LockMutex(&cm->tpLock) != 0) return ret; tp = cm->tpTable[row]; @@ -2867,7 +2867,7 @@ TrustedPeerCert* GetTrustedPeer(void* vp, byte* hash, int type) break; default: WOLFSSL_MSG("Unknown search type"); - UnLockMutex(&cm->tpLock); + wc_UnLockMutex(&cm->tpLock); return NULL; } if (XMEMCMP(hash, subjectHash, SIGNER_DIGEST_SIZE) == 0) { @@ -2876,7 +2876,7 @@ TrustedPeerCert* GetTrustedPeer(void* vp, byte* hash, int type) } tp = tp->next; } - UnLockMutex(&cm->tpLock); + wc_UnLockMutex(&cm->tpLock); return ret; } @@ -2916,7 +2916,7 @@ Signer* GetCA(void* vp, byte* hash) if (cm == NULL) return NULL; - if (LockMutex(&cm->caLock) != 0) + if (wc_LockMutex(&cm->caLock) != 0) return ret; signers = cm->caTable[row]; @@ -2933,7 +2933,7 @@ Signer* GetCA(void* vp, byte* hash) } signers = signers->next; } - UnLockMutex(&cm->caLock); + wc_UnLockMutex(&cm->caLock); return ret; } @@ -2951,7 +2951,7 @@ Signer* GetCAByName(void* vp, byte* hash) if (cm == NULL) return NULL; - if (LockMutex(&cm->caLock) != 0) + if (wc_LockMutex(&cm->caLock) != 0) return ret; for (row = 0; row < CA_TABLE_SIZE && ret == NULL; row++) { @@ -2964,7 +2964,7 @@ Signer* GetCAByName(void* vp, byte* hash) signers = signers->next; } } - UnLockMutex(&cm->caLock); + wc_UnLockMutex(&cm->caLock); return ret; } @@ -3072,10 +3072,10 @@ int AddTrustedPeer(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int verify) row = TrustedPeerHashSigner(peerCert->subjectNameHash); #endif - if (LockMutex(&cm->tpLock) == 0) { + if (wc_LockMutex(&cm->tpLock) == 0) { peerCert->next = cm->tpTable[row]; cm->tpTable[row] = peerCert; /* takes ownership */ - UnLockMutex(&cm->tpLock); + wc_UnLockMutex(&cm->tpLock); } else { WOLFSSL_MSG(" Trusted Peer Cert Mutex Lock failed"); @@ -3218,10 +3218,10 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify) row = HashSigner(signer->subjectNameHash); #endif - if (LockMutex(&cm->caLock) == 0) { + if (wc_LockMutex(&cm->caLock) == 0) { signer->next = cm->caTable[row]; cm->caTable[row] = signer; /* takes ownership */ - UnLockMutex(&cm->caLock); + wc_UnLockMutex(&cm->caLock); if (cm->caCacheCallback) cm->caCacheCallback(der->buffer, (int)der->length, type); } @@ -3331,24 +3331,24 @@ int wolfSSL_Init(void) return WC_INIT_E; } #ifndef NO_SESSION_CACHE - if (InitMutex(&session_mutex) != 0) { + if (wc_InitMutex(&session_mutex) != 0) { WOLFSSL_MSG("Bad Init Mutex session"); return BAD_MUTEX_E; } #endif - if (InitMutex(&count_mutex) != 0) { + if (wc_InitMutex(&count_mutex) != 0) { WOLFSSL_MSG("Bad Init Mutex count"); return BAD_MUTEX_E; } } - if (LockMutex(&count_mutex) != 0) { + if (wc_LockMutex(&count_mutex) != 0) { WOLFSSL_MSG("Bad Lock Mutex count"); return BAD_MUTEX_E; } initRefCount++; - UnLockMutex(&count_mutex); + wc_UnLockMutex(&count_mutex); return SSL_SUCCESS; } @@ -5956,7 +5956,7 @@ int wolfSSL_memsave_session_cache(void* mem, int sz) cache_header.sessionSz = (int)sizeof(WOLFSSL_SESSION); XMEMCPY(mem, &cache_header, sizeof(cache_header)); - if (LockMutex(&session_mutex) != 0) { + if (wc_LockMutex(&session_mutex) != 0) { WOLFSSL_MSG("Session cache mutex lock failed"); return BAD_MUTEX_E; } @@ -5970,7 +5970,7 @@ int wolfSSL_memsave_session_cache(void* mem, int sz) XMEMCPY(clRow++, ClientCache + i, sizeof(ClientRow)); #endif - UnLockMutex(&session_mutex); + wc_UnLockMutex(&session_mutex); WOLFSSL_LEAVE("wolfSSL_memsave_session_cache", SSL_SUCCESS); @@ -6005,7 +6005,7 @@ int wolfSSL_memrestore_session_cache(const void* mem, int sz) return CACHE_MATCH_ERROR; } - if (LockMutex(&session_mutex) != 0) { + if (wc_LockMutex(&session_mutex) != 0) { WOLFSSL_MSG("Session cache mutex lock failed"); return BAD_MUTEX_E; } @@ -6019,7 +6019,7 @@ int wolfSSL_memrestore_session_cache(const void* mem, int sz) XMEMCPY(ClientCache + i, clRow++, sizeof(ClientRow)); #endif - UnLockMutex(&session_mutex); + wc_UnLockMutex(&session_mutex); WOLFSSL_LEAVE("wolfSSL_memrestore_session_cache", SSL_SUCCESS); @@ -6058,7 +6058,7 @@ int wolfSSL_save_session_cache(const char *fname) return FWRITE_ERROR; } - if (LockMutex(&session_mutex) != 0) { + if (wc_LockMutex(&session_mutex) != 0) { WOLFSSL_MSG("Session cache mutex lock failed"); XFCLOSE(file); return BAD_MUTEX_E; @@ -6086,7 +6086,7 @@ int wolfSSL_save_session_cache(const char *fname) } #endif /* NO_CLIENT_CACHE */ - UnLockMutex(&session_mutex); + wc_UnLockMutex(&session_mutex); XFCLOSE(file); WOLFSSL_LEAVE("wolfSSL_save_session_cache", rc); @@ -6129,7 +6129,7 @@ int wolfSSL_restore_session_cache(const char *fname) return CACHE_MATCH_ERROR; } - if (LockMutex(&session_mutex) != 0) { + if (wc_LockMutex(&session_mutex) != 0) { WOLFSSL_MSG("Session cache mutex lock failed"); XFCLOSE(file); return BAD_MUTEX_E; @@ -6160,7 +6160,7 @@ int wolfSSL_restore_session_cache(const char *fname) #endif /* NO_CLIENT_CACHE */ - UnLockMutex(&session_mutex); + wc_UnLockMutex(&session_mutex); XFCLOSE(file); WOLFSSL_LEAVE("wolfSSL_restore_session_cache", rc); @@ -6497,8 +6497,8 @@ int CM_SaveCertCache(WOLFSSL_CERT_MANAGER* cm, const char* fname) return SSL_BAD_FILE; } - if (LockMutex(&cm->caLock) != 0) { - WOLFSSL_MSG("LockMutex on caLock failed"); + if (wc_LockMutex(&cm->caLock) != 0) { + WOLFSSL_MSG("wc_LockMutex on caLock failed"); XFCLOSE(file); return BAD_MUTEX_E; } @@ -6520,7 +6520,7 @@ int CM_SaveCertCache(WOLFSSL_CERT_MANAGER* cm, const char* fname) XFREE(mem, cm->heap, DYNAMIC_TYPE_TMP_BUFFER); } - UnLockMutex(&cm->caLock); + wc_UnLockMutex(&cm->caLock); XFCLOSE(file); return rc; @@ -6588,8 +6588,8 @@ int CM_MemSaveCertCache(WOLFSSL_CERT_MANAGER* cm, void* mem, int sz, int* used) WOLFSSL_ENTER("CM_MemSaveCertCache"); - if (LockMutex(&cm->caLock) != 0) { - WOLFSSL_MSG("LockMutex on caLock failed"); + if (wc_LockMutex(&cm->caLock) != 0) { + WOLFSSL_MSG("wc_LockMutex on caLock failed"); return BAD_MUTEX_E; } @@ -6597,7 +6597,7 @@ int CM_MemSaveCertCache(WOLFSSL_CERT_MANAGER* cm, void* mem, int sz, int* used) if (ret == SSL_SUCCESS) *used = GetCertCacheMemSize(cm); - UnLockMutex(&cm->caLock); + wc_UnLockMutex(&cm->caLock); return ret; } @@ -6627,8 +6627,8 @@ int CM_MemRestoreCertCache(WOLFSSL_CERT_MANAGER* cm, const void* mem, int sz) return CACHE_MATCH_ERROR; } - if (LockMutex(&cm->caLock) != 0) { - WOLFSSL_MSG("LockMutex on caLock failed"); + if (wc_LockMutex(&cm->caLock) != 0) { + WOLFSSL_MSG("wc_LockMutex on caLock failed"); return BAD_MUTEX_E; } @@ -6644,7 +6644,7 @@ int CM_MemRestoreCertCache(WOLFSSL_CERT_MANAGER* cm, const void* mem, int sz) current += added; } - UnLockMutex(&cm->caLock); + wc_UnLockMutex(&cm->caLock); return ret; } @@ -6657,14 +6657,14 @@ int CM_GetCertCacheMemSize(WOLFSSL_CERT_MANAGER* cm) WOLFSSL_ENTER("CM_GetCertCacheMemSize"); - if (LockMutex(&cm->caLock) != 0) { - WOLFSSL_MSG("LockMutex on caLock failed"); + if (wc_LockMutex(&cm->caLock) != 0) { + WOLFSSL_MSG("wc_LockMutex on caLock failed"); return BAD_MUTEX_E; } sz = GetCertCacheMemSize(cm); - UnLockMutex(&cm->caLock); + wc_UnLockMutex(&cm->caLock); return sz; } @@ -7514,7 +7514,7 @@ int wolfSSL_Cleanup(void) if (initRefCount == 0) return ret; /* possibly no init yet, but not failure either way */ - if (LockMutex(&count_mutex) != 0) { + if (wc_LockMutex(&count_mutex) != 0) { WOLFSSL_MSG("Bad Lock Mutex count"); return BAD_MUTEX_E; } @@ -7523,16 +7523,16 @@ int wolfSSL_Cleanup(void) if (initRefCount < 0) initRefCount = 0; - UnLockMutex(&count_mutex); + wc_UnLockMutex(&count_mutex); if (!release) return ret; #ifndef NO_SESSION_CACHE - if (FreeMutex(&session_mutex) != 0) + if (wc_FreeMutex(&session_mutex) != 0) ret = BAD_MUTEX_E; #endif - if (FreeMutex(&count_mutex) != 0) + if (wc_FreeMutex(&count_mutex) != 0) ret = BAD_MUTEX_E; #if defined(HAVE_ECC) && defined(FP_ECC) @@ -7620,7 +7620,7 @@ WOLFSSL_SESSION* GetSessionClient(WOLFSSL* ssl, const byte* id, int len) return NULL; } - if (LockMutex(&session_mutex) != 0) { + if (wc_LockMutex(&session_mutex) != 0) { WOLFSSL_MSG("Lock session mutex failed"); return NULL; } @@ -7657,7 +7657,7 @@ WOLFSSL_SESSION* GetSessionClient(WOLFSSL* ssl, const byte* id, int len) } } - UnLockMutex(&session_mutex); + wc_UnLockMutex(&session_mutex); return ret; } @@ -7699,7 +7699,7 @@ WOLFSSL_SESSION* GetSession(WOLFSSL* ssl, byte* masterSecret, return NULL; } - if (LockMutex(&session_mutex) != 0) + if (wc_LockMutex(&session_mutex) != 0) return 0; /* start from most recently used */ @@ -7744,7 +7744,7 @@ WOLFSSL_SESSION* GetSession(WOLFSSL* ssl, byte* masterSecret, } } - UnLockMutex(&session_mutex); + wc_UnLockMutex(&session_mutex); return ret; } @@ -7774,7 +7774,7 @@ static int GetDeepCopySession(WOLFSSL* ssl, WOLFSSL_SESSION* copyFrom) } #endif - if (LockMutex(&session_mutex) != 0) + if (wc_LockMutex(&session_mutex) != 0) return BAD_MUTEX_E; #ifdef HAVE_SESSION_TICKET @@ -7791,7 +7791,7 @@ static int GetDeepCopySession(WOLFSSL* ssl, WOLFSSL_SESSION* copyFrom) copyInto->isDynamic = 0; #endif - if (UnLockMutex(&session_mutex) != 0) { + if (wc_UnLockMutex(&session_mutex) != 0) { return BAD_MUTEX_E; } @@ -7803,7 +7803,7 @@ static int GetDeepCopySession(WOLFSSL* ssl, WOLFSSL_SESSION* copyFrom) if (!tmpBuff) return MEMORY_ERROR; - if (LockMutex(&session_mutex) != 0) { + if (wc_LockMutex(&session_mutex) != 0) { XFREE(tmpBuff, ssl->heap, DYNAMIC_TYPE_SESSION_TICK); return BAD_MUTEX_E; } @@ -7825,7 +7825,7 @@ static int GetDeepCopySession(WOLFSSL* ssl, WOLFSSL_SESSION* copyFrom) copyInto->ticket = copyInto->staticTicket; } - if (UnLockMutex(&session_mutex) != 0) { + if (wc_UnLockMutex(&session_mutex) != 0) { if (ret == SSL_SUCCESS) ret = BAD_MUTEX_E; } @@ -7907,7 +7907,7 @@ int AddSession(WOLFSSL* ssl) } #endif - if (LockMutex(&session_mutex) != 0) { + if (wc_LockMutex(&session_mutex) != 0) { #ifdef HAVE_SESSION_TICKET XFREE(tmpBuff, ssl->heap, DYNAMIC_TYPE_SESSION_TICK); #endif @@ -8033,7 +8033,7 @@ int AddSession(WOLFSSL* ssl) } #endif /* defined(WOLFSSL_SESSION_STATS) && defined(WOLFSSL_PEAK_SESSIONS) */ - if (UnLockMutex(&session_mutex) != 0) + if (wc_UnLockMutex(&session_mutex) != 0) return BAD_MUTEX_E; return error; @@ -8059,7 +8059,7 @@ int wolfSSL_GetSessionAtIndex(int idx, WOLFSSL_SESSION* session) row = idx >> SESSIDX_ROW_SHIFT; col = idx & SESSIDX_IDX_MASK; - if (LockMutex(&session_mutex) != 0) { + if (wc_LockMutex(&session_mutex) != 0) { return BAD_MUTEX_E; } @@ -8070,7 +8070,7 @@ int wolfSSL_GetSessionAtIndex(int idx, WOLFSSL_SESSION* session) result = SSL_SUCCESS; } - if (UnLockMutex(&session_mutex) != 0) + if (wc_UnLockMutex(&session_mutex) != 0) result = BAD_MUTEX_E; WOLFSSL_LEAVE("wolfSSL_GetSessionAtIndex", result); @@ -8174,13 +8174,13 @@ int wolfSSL_get_session_stats(word32* active, word32* total, word32* peak, if (active == NULL && total == NULL && peak == NULL) return BAD_FUNC_ARG; - if (LockMutex(&session_mutex) != 0) { + if (wc_LockMutex(&session_mutex) != 0) { return BAD_MUTEX_E; } result = get_locked_session_stats(active, total, peak); - if (UnLockMutex(&session_mutex) != 0) + if (wc_UnLockMutex(&session_mutex) != 0) result = BAD_MUTEX_E; WOLFSSL_LEAVE("wolfSSL_get_session_stats", result); @@ -17959,7 +17959,7 @@ void* wolfSSL_GetRsaDecCtx(WOLFSSL* ssl) #ifdef OPENSSL_EXTRA /*Lighttp compatibility*/ -#if defined(HAVE_LIGHTY) || defined(WOLFSSL_MYSQL_COMPATIBLE) +#if defined(HAVE_LIGHTY) || defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) unsigned char *wolfSSL_SHA1(const unsigned char *d, size_t n, unsigned char *md) { @@ -18149,7 +18149,7 @@ void* wolfSSL_GetRsaDecCtx(WOLFSSL* ssl) return NULL; } -#endif /* HAVE_LIGHTY || WOLFSSL_MYSQL_COMPATIBLE */ +#endif /* HAVE_LIGHTY || WOLFSSL_MYSQL_COMPATIBLE || HAVE_STUNNEL */ #endif @@ -18556,7 +18556,7 @@ int wolfSSL_get_state(const WOLFSSL* ssl) } -void* wolfSSL_sk_X509_NAME_value(STACK_OF(WOLFSSL_X509_NAME)* sk, int i) +void* wolfSSL_sk_X509_NAME_value(const STACK_OF(WOLFSSL_X509_NAME)* sk, int i) { (void)sk; (void)i; diff --git a/src/tls.c b/src/tls.c index a6ad8dc2e..cb21af35c 100644 --- a/src/tls.c +++ b/src/tls.c @@ -4206,12 +4206,12 @@ static word32 GetEntropy(unsigned char* out, word32 num_bytes) if ((rngMutex = (wolfSSL_Mutex*)XMALLOC(sizeof(wolfSSL_Mutex), NULL, DYNAMIC_TYPE_TLSX)) == NULL) return DRBG_OUT_OF_MEMORY; - InitMutex(rngMutex); + wc_InitMutex(rngMutex); } - ret |= LockMutex(rngMutex); + ret |= wc_LockMutex(rngMutex); ret |= wc_RNG_GenerateBlock(rng, out, num_bytes); - ret |= UnLockMutex(rngMutex); + ret |= wc_UnLockMutex(rngMutex); if (ret != 0) return DRBG_ENTROPY_FAIL; diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index bb660cefd..2bcab3d6b 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -1574,7 +1574,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock) #warning "Allocate non-Cache buffers" #endif - InitMutex(&Mutex_AesSEC); + wc_InitMutex(&Mutex_AesSEC); } if (!((keylen == 16) || (keylen == 24) || (keylen == 32))) @@ -2165,7 +2165,7 @@ int wc_InitAes_h(Aes* aes, void* h) if ((pi == NULL) || (po == NULL)) return BAD_FUNC_ARG; /*wrong pointer*/ - LockMutex(&Mutex_AesSEC); + wc_LockMutex(&Mutex_AesSEC); /* Set descriptor for SEC */ secDesc->length1 = 0x0; @@ -2241,7 +2241,7 @@ int wc_InitAes_h(Aes* aes, void* h) po += size; } - UnLockMutex(&Mutex_AesSEC); + wc_UnLockMutex(&Mutex_AesSEC); return 0; } diff --git a/wolfcrypt/src/des3.c b/wolfcrypt/src/des3.c index 2f9bd34d0..3f2147d88 100644 --- a/wolfcrypt/src/des3.c +++ b/wolfcrypt/src/des3.c @@ -396,7 +396,7 @@ static void wc_Des_Cbc(byte* out, const byte* in, word32 sz, int size ; volatile int v ; - LockMutex(&Mutex_DesSEC) ; + wc_LockMutex(&Mutex_DesSEC) ; secDesc->length1 = 0x0; secDesc->pointer1 = NULL; @@ -464,7 +464,7 @@ static void wc_Des_Cbc(byte* out, const byte* in, word32 sz, out += size ; } - UnLockMutex(&Mutex_DesSEC) ; + wc_UnLockMutex(&Mutex_DesSEC) ; } @@ -532,7 +532,7 @@ int wc_Des_SetKey(Des* des, const byte* key, const byte* iv, int dir) #warning "Allocate non-Cache buffers" #endif - InitMutex(&Mutex_DesSEC) ; + wc_InitMutex(&Mutex_DesSEC) ; } XMEMCPY(des->key, key, DES_KEYLEN); @@ -562,7 +562,7 @@ int wc_Des3_SetKey(Des3* des3, const byte* key, const byte* iv, int dir) #warning "Allocate non-Cache buffers" #endif - InitMutex(&Mutex_DesSEC) ; + wc_InitMutex(&Mutex_DesSEC) ; } XMEMCPY(des3->key[0], key, DES3_KEYLEN); diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index c7337610e..71c25ecfa 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -5489,10 +5489,10 @@ int ecc_mul2add(ecc_point* A, mp_int* kA, #ifndef HAVE_THREAD_LS if (initMutex == 0) { - InitMutex(&ecc_fp_lock); + wc_InitMutex(&ecc_fp_lock); initMutex = 1; } - if (LockMutex(&ecc_fp_lock) != 0) + if (wc_LockMutex(&ecc_fp_lock) != 0) return BAD_MUTEX_E; #endif /* HAVE_THREAD_LS */ @@ -5580,7 +5580,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA, } #ifndef HAVE_THREAD_LS - UnLockMutex(&ecc_fp_lock); + wc_UnLockMutex(&ecc_fp_lock); #endif /* HAVE_THREAD_LS */ #ifndef USE_FAST_MATH mp_clear(&mu); @@ -5629,11 +5629,11 @@ int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, #ifndef HAVE_THREAD_LS if (initMutex == 0) { - InitMutex(&ecc_fp_lock); + wc_InitMutex(&ecc_fp_lock); initMutex = 1; } - if (LockMutex(&ecc_fp_lock) != 0) + if (wc_LockMutex(&ecc_fp_lock) != 0) return BAD_MUTEX_E; #endif /* HAVE_THREAD_LS */ @@ -5686,7 +5686,7 @@ int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, } #ifndef HAVE_THREAD_LS - UnLockMutex(&ecc_fp_lock); + wc_UnLockMutex(&ecc_fp_lock); #endif /* HAVE_THREAD_LS */ #ifndef USE_FAST_MATH mp_clear(&mu); @@ -5720,18 +5720,18 @@ void wc_ecc_fp_free(void) { #ifndef HAVE_THREAD_LS if (initMutex == 0) { - InitMutex(&ecc_fp_lock); + wc_InitMutex(&ecc_fp_lock); initMutex = 1; } - if (LockMutex(&ecc_fp_lock) == 0) { + if (wc_LockMutex(&ecc_fp_lock) == 0) { #endif /* HAVE_THREAD_LS */ wc_ecc_fp_free_cache(); #ifndef HAVE_THREAD_LS - UnLockMutex(&ecc_fp_lock); - FreeMutex(&ecc_fp_lock); + wc_UnLockMutex(&ecc_fp_lock); + wc_FreeMutex(&ecc_fp_lock); initMutex = 0; } #endif /* HAVE_THREAD_LS */ diff --git a/wolfcrypt/src/memory.c b/wolfcrypt/src/memory.c index f9e24b5bd..470b09cf9 100644 --- a/wolfcrypt/src/memory.c +++ b/wolfcrypt/src/memory.c @@ -210,7 +210,7 @@ int wolfSSL_init_memory_heap(WOLFSSL_HEAP* heap) XMEMCPY(heap->sizeList, wc_MemSz, sizeof(wc_MemSz)); XMEMCPY(heap->distList, wc_Dist, sizeof(wc_Dist)); - if (InitMutex(&(heap->memory_mutex)) != 0) { + if (wc_InitMutex(&(heap->memory_mutex)) != 0) { WOLFSSL_MSG("Error creating heap memory mutex"); return BAD_MUTEX_E; } @@ -524,7 +524,7 @@ void* wolfSSL_Malloc(size_t size, void* heap, int type) WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)heap; WOLFSSL_HEAP* mem = hint->memory; - if (LockMutex(&(mem->memory_mutex)) != 0) { + if (wc_LockMutex(&(mem->memory_mutex)) != 0) { WOLFSSL_MSG("Bad memory_mutex lock"); return NULL; } @@ -591,7 +591,7 @@ void* wolfSSL_Malloc(size_t size, void* heap, int type) WOLFSSL_MSG("ERROR ran out of static memory"); } - UnLockMutex(&(mem->memory_mutex)); + wc_UnLockMutex(&(mem->memory_mutex)); } #ifdef WOLFSSL_MALLOC_CHECK @@ -651,7 +651,7 @@ void wolfSSL_Free(void *ptr, void* heap, int type) /* get memory struct and add it to available list */ pt = (wc_Memory*)((byte*)ptr - sizeof(wc_Memory) - padSz); - if (LockMutex(&(mem->memory_mutex)) != 0) { + if (wc_LockMutex(&(mem->memory_mutex)) != 0) { WOLFSSL_MSG("Bad memory_mutex lock"); return; } @@ -703,7 +703,7 @@ void wolfSSL_Free(void *ptr, void* heap, int type) stats->totalFr++; } } - UnLockMutex(&(mem->memory_mutex)); + wc_UnLockMutex(&(mem->memory_mutex)); } } @@ -745,7 +745,7 @@ void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type) WOLFSSL_HEAP* mem = hint->memory; word32 padSz = -(int)sizeof(wc_Memory) & (WOLFSSL_STATIC_ALIGN - 1); - if (LockMutex(&(mem->memory_mutex)) != 0) { + if (wc_LockMutex(&(mem->memory_mutex)) != 0) { WOLFSSL_MSG("Bad memory_mutex lock"); return NULL; } @@ -786,19 +786,19 @@ void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type) mem->alloc += 1; /* free memory that was previously being used */ - UnLockMutex(&(mem->memory_mutex)); + wc_UnLockMutex(&(mem->memory_mutex)); wolfSSL_Free(ptr, heap, type #ifdef WOLFSSL_DEBUG_MEMORY , func, line #endif ); - if (LockMutex(&(mem->memory_mutex)) != 0) { + if (wc_LockMutex(&(mem->memory_mutex)) != 0) { WOLFSSL_MSG("Bad memory_mutex lock"); return NULL; } } } - UnLockMutex(&(mem->memory_mutex)); + wc_UnLockMutex(&(mem->memory_mutex)); } #ifdef WOLFSSL_MALLOC_CHECK diff --git a/wolfcrypt/src/port/ti/ti-ccm.c b/wolfcrypt/src/port/ti/ti-ccm.c index 42b20930a..abf4d602d 100644 --- a/wolfcrypt/src/port/ti/ti-ccm.c +++ b/wolfcrypt/src/port/ti/ti-ccm.c @@ -64,7 +64,7 @@ int wolfSSL_TI_CCMInit(void) WAIT(ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0)) ; #ifndef SINGLE_THREADED - if(InitMutex(&TI_CCM_Mutex))return false ; + if(wc_InitMutex(&TI_CCM_Mutex))return false ; #endif return true ; @@ -72,11 +72,11 @@ int wolfSSL_TI_CCMInit(void) #ifndef SINGLE_THREADED void wolfSSL_TI_lockCCM(void) { - LockMutex(&TI_CCM_Mutex) ; + wc_LockMutex(&TI_CCM_Mutex) ; } void wolfSSL_TI_unlockCCM(void) { - UnLockMutex(&TI_CCM_Mutex) ; + wc_UnLockMutex(&TI_CCM_Mutex) ; } #endif diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 61c2e8455..64198c0e9 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -896,13 +896,13 @@ int wc_InitNetRandom(const char* configFile, wnr_hmac_key hmac_cb, int timeout) return 0; } - if (InitMutex(&wnr_mutex) != 0) { + if (wc_InitMutex(&wnr_mutex) != 0) { WOLFSSL_MSG("Bad Init Mutex wnr_mutex"); return BAD_MUTEX_E; } wnr_mutex_init = 1; - if (LockMutex(&wnr_mutex) != 0) { + if (wc_LockMutex(&wnr_mutex) != 0) { WOLFSSL_MSG("Bad Lock Mutex wnr_mutex"); return BAD_MUTEX_E; } @@ -942,7 +942,7 @@ int wc_InitNetRandom(const char* configFile, wnr_hmac_key hmac_cb, int timeout) return RNG_FAILURE_E; } - UnLockMutex(&wnr_mutex); + wc_UnLockMutex(&wnr_mutex); return 0; } @@ -955,7 +955,7 @@ int wc_FreeNetRandom(void) { if (wnr_mutex_init > 0) { - if (LockMutex(&wnr_mutex) != 0) { + if (wc_LockMutex(&wnr_mutex) != 0) { WOLFSSL_MSG("Bad Lock Mutex wnr_mutex"); return BAD_MUTEX_E; } @@ -966,9 +966,9 @@ int wc_FreeNetRandom(void) } wnr_poll_destroy(); - UnLockMutex(&wnr_mutex); + wc_UnLockMutex(&wnr_mutex); - FreeMutex(&wnr_mutex); + wc_FreeMutex(&wnr_mutex); wnr_mutex_init = 0; } @@ -1539,7 +1539,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) return RNG_FAILURE_E; } - if (LockMutex(&wnr_mutex) != 0) { + if (wc_LockMutex(&wnr_mutex) != 0) { WOLFSSL_MSG("Bad Lock Mutex wnr_mutex\n"); return BAD_MUTEX_E; } @@ -1548,7 +1548,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) WNR_ERROR_NONE) return RNG_FAILURE_E; - UnLockMutex(&wnr_mutex); + wc_UnLockMutex(&wnr_mutex); return 0; } diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 86b1cf20b..f087caed7 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -79,6 +79,16 @@ int wolfCrypt_Init() return ret; } +wolfSSL_Mutex* wc_InitAndAllocMutex() +{ + wolfSSL_Mutex* m = XMALLOC(sizeof(wolfSSL_Mutex), NULL, + DYNAMIC_TYPE_MUTEX); + if(m && wc_InitMutex(m)) + return m; + XFREE(m, NULL, DYNAMIC_TYPE_MUTEX); + m = NULL; + return m; +} #if WOLFSSL_CRYPT_HW_MUTEX /* Mutex for protection of cryptography hardware */ @@ -88,7 +98,7 @@ static int wcCryptHwMutexInit = 0; int wolfSSL_CryptHwMutexInit(void) { int ret = 0; if(wcCryptHwMutexInit == 0) { - ret = InitMutex(&wcCryptHwMutex); + ret = wc_InitMutex(&wcCryptHwMutex); if(ret == 0) { wcCryptHwMutexInit = 1; } @@ -103,16 +113,16 @@ int wolfSSL_CryptHwMutexLock(void) { wolfSSL_CryptHwMutexInit(); if(wcCryptHwMutexInit) { - ret = LockMutex(&wcCryptHwMutex); + ret = wc_LockMutex(&wcCryptHwMutex); } return ret; } int wolfSSL_CryptHwMutexUnLock(void) { int ret = BAD_MUTEX_E; - + if(wcCryptHwMutexInit) { - ret = UnLockMutex(&wcCryptHwMutex); + ret = wc_UnLockMutex(&wcCryptHwMutex); } return ret; } @@ -121,28 +131,27 @@ int wolfSSL_CryptHwMutexUnLock(void) { #ifdef SINGLE_THREADED -int InitMutex(wolfSSL_Mutex* m) +int wc_InitMutex(wolfSSL_Mutex* m) +{ + (void)m; + return 0; +} + +int wc_FreeMutex(wolfSSL_Mutex *m) { (void)m; return 0; } -int FreeMutex(wolfSSL_Mutex *m) +int wc_LockMutex(wolfSSL_Mutex *m) { (void)m; return 0; } -int LockMutex(wolfSSL_Mutex *m) -{ - (void)m; - return 0; -} - - -int UnLockMutex(wolfSSL_Mutex *m) +int wc_UnLockMutex(wolfSSL_Mutex *m) { (void)m; return 0; @@ -153,7 +162,7 @@ int UnLockMutex(wolfSSL_Mutex *m) #if defined(FREERTOS) || defined(FREERTOS_TCP) || \ defined(FREESCALE_FREE_RTOS) - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { int iReturn; @@ -166,20 +175,21 @@ int UnLockMutex(wolfSSL_Mutex *m) return iReturn; } - int FreeMutex(wolfSSL_Mutex* m) + + int wc_FreeMutex(wolfSSL_Mutex* m) { vSemaphoreDelete( *m ); return 0; } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { /* Assume an infinite block, or should there be zero block? */ xSemaphoreTake( *m, portMAX_DELAY ); return 0; } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { xSemaphoreGive( *m ); return 0; @@ -187,7 +197,7 @@ int UnLockMutex(wolfSSL_Mutex *m) #elif defined(WOLFSSL_SAFERTOS) - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { vSemaphoreCreateBinary(m->mutexBuffer, m->mutex); if (m->mutex == NULL) @@ -196,20 +206,20 @@ int UnLockMutex(wolfSSL_Mutex *m) return 0; } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { (void)m; return 0; } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { /* Assume an infinite block */ xSemaphoreTake(m->mutex, portMAX_DELAY); return 0; } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { xSemaphoreGive(m->mutex); return 0; @@ -218,28 +228,28 @@ int UnLockMutex(wolfSSL_Mutex *m) #elif defined(USE_WINDOWS_API) - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { InitializeCriticalSection(m); return 0; } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { DeleteCriticalSection(m); return 0; } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { EnterCriticalSection(m); return 0; } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { LeaveCriticalSection(m); return 0; @@ -247,7 +257,7 @@ int UnLockMutex(wolfSSL_Mutex *m) #elif defined(WOLFSSL_PTHREADS) - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { if (pthread_mutex_init(m, 0) == 0) return 0; @@ -256,7 +266,7 @@ int UnLockMutex(wolfSSL_Mutex *m) } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { if (pthread_mutex_destroy(m) == 0) return 0; @@ -265,7 +275,7 @@ int UnLockMutex(wolfSSL_Mutex *m) } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { if (pthread_mutex_lock(m) == 0) return 0; @@ -274,7 +284,7 @@ int UnLockMutex(wolfSSL_Mutex *m) } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { if (pthread_mutex_unlock(m) == 0) return 0; @@ -284,7 +294,7 @@ int UnLockMutex(wolfSSL_Mutex *m) #elif defined(THREADX) - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { if (tx_mutex_create(m, "wolfSSL Mutex", TX_NO_INHERIT) == 0) return 0; @@ -293,7 +303,7 @@ int UnLockMutex(wolfSSL_Mutex *m) } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { if (tx_mutex_delete(m) == 0) return 0; @@ -302,7 +312,7 @@ int UnLockMutex(wolfSSL_Mutex *m) } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { if (tx_mutex_get(m, TX_WAIT_FOREVER) == 0) return 0; @@ -311,7 +321,7 @@ int UnLockMutex(wolfSSL_Mutex *m) } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { if (tx_mutex_put(m) == 0) return 0; @@ -321,7 +331,7 @@ int UnLockMutex(wolfSSL_Mutex *m) #elif defined(MICRIUM) - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) if (NetSecure_OS_MutexCreate(m) == 0) @@ -334,10 +344,10 @@ int UnLockMutex(wolfSSL_Mutex *m) } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) - if (NetSecure_OS_FreeMutex(m) == 0) + if (NetSecure_OS_wc_FreeMutex(m) == 0) return 0; else return BAD_MUTEX_E; @@ -347,10 +357,10 @@ int UnLockMutex(wolfSSL_Mutex *m) } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) - if (NetSecure_OS_LockMutex(m) == 0) + if (NetSecure_OS_wc_LockMutex(m) == 0) return 0; else return BAD_MUTEX_E; @@ -360,10 +370,10 @@ int UnLockMutex(wolfSSL_Mutex *m) } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) - if (NetSecure_OS_UnLockMutex(m) == 0) + if (NetSecure_OS_wc_UnLockMutex(m) == 0) return 0; else return BAD_MUTEX_E; @@ -375,7 +385,7 @@ int UnLockMutex(wolfSSL_Mutex *m) #elif defined(EBSNET) - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { if (rtp_sig_mutex_alloc(m, "wolfSSL Mutex") == -1) return BAD_MUTEX_E; @@ -383,13 +393,13 @@ int UnLockMutex(wolfSSL_Mutex *m) return 0; } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { rtp_sig_mutex_free(*m); return 0; } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { if (rtp_sig_mutex_claim_timed(*m, RTIP_INF) == 0) return 0; @@ -397,7 +407,7 @@ int UnLockMutex(wolfSSL_Mutex *m) return BAD_MUTEX_E; } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { rtp_sig_mutex_release(*m); return 0; @@ -405,7 +415,7 @@ int UnLockMutex(wolfSSL_Mutex *m) #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { if (_mutex_init(m, NULL) == MQX_EOK) return 0; @@ -413,7 +423,7 @@ int UnLockMutex(wolfSSL_Mutex *m) return BAD_MUTEX_E; } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { if (_mutex_destroy(m) == MQX_EOK) return 0; @@ -421,7 +431,7 @@ int UnLockMutex(wolfSSL_Mutex *m) return BAD_MUTEX_E; } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { if (_mutex_lock(m) == MQX_EOK) return 0; @@ -429,7 +439,7 @@ int UnLockMutex(wolfSSL_Mutex *m) return BAD_MUTEX_E; } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { if (_mutex_unlock(m) == MQX_EOK) return 0; @@ -439,7 +449,7 @@ int UnLockMutex(wolfSSL_Mutex *m) #elif defined (WOLFSSL_TIRTOS) #include - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { Semaphore_Params params; Error_Block eb; @@ -454,21 +464,21 @@ int UnLockMutex(wolfSSL_Mutex *m) } else return 0; } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { Semaphore_delete(m); return 0; } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { Semaphore_pend(*m, BIOS_WAIT_FOREVER); return 0; } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { Semaphore_post(*m); @@ -478,7 +488,7 @@ int UnLockMutex(wolfSSL_Mutex *m) #elif defined(WOLFSSL_uITRON4) #include "stddef.h" #include "kernel.h" - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { int iReturn; m->sem.sematr = TA_TFIFO ; @@ -495,19 +505,19 @@ int UnLockMutex(wolfSSL_Mutex *m) return iReturn; } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { del_sem( m->id ); return 0; } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { wai_sem(m->id); return 0; } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { sig_sem(m->id); return 0; @@ -568,7 +578,7 @@ int UnLockMutex(wolfSSL_Mutex *m) #elif defined(WOLFSSL_uTKERNEL2) #include "tk/tkernel.h" - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { int iReturn; m->sem.sematr = TA_TFIFO ; @@ -584,19 +594,19 @@ int UnLockMutex(wolfSSL_Mutex *m) return iReturn; } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { tk_del_sem( m->id ); return 0; } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { tk_wai_sem(m->id, 1, TMO_FEVR); return 0; } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { tk_sig_sem(m->id, 1); return 0; @@ -657,7 +667,7 @@ int UnLockMutex(wolfSSL_Mutex *m) } } #elif defined (WOLFSSL_FROSTED) - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { *m = mutex_init(); if (*m) @@ -666,19 +676,19 @@ int UnLockMutex(wolfSSL_Mutex *m) return -1; } - int FreeMutex(wolfSSL_Mutex* m) + int wc_FreeMutex(wolfSSL_Mutex* m) { mutex_destroy(*m); return(0) ; } - int LockMutex(wolfSSL_Mutex* m) + int wc_LockMutex(wolfSSL_Mutex* m) { mutex_lock(*m); return 0; } - int UnLockMutex(wolfSSL_Mutex* m) + int wc_UnLockMutex(wolfSSL_Mutex* m) { mutex_unlock(*m); return 0; @@ -700,7 +710,7 @@ int UnLockMutex(wolfSSL_Mutex *m) static osMutexId CMSIS_mutexID[CMSIS_NMUTEX] = {0} ; - int InitMutex(wolfSSL_Mutex* m) + int wc_InitMutex(wolfSSL_Mutex* m) { int i ; for (i=0; ilock); + ret = wc_InitMutex(&queue->lock); #endif return ret; } @@ -94,7 +94,7 @@ int wolfEventQueue_Push(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event) } #ifndef SINGLE_THREADED - if ((ret = LockMutex(&queue->lock)) != 0) { + if ((ret = wc_LockMutex(&queue->lock)) != 0) { return ret; } #endif @@ -115,7 +115,7 @@ int wolfEventQueue_Push(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event) ret = 0; #ifndef SINGLE_THREADED - UnLockMutex(&queue->lock); + wc_UnLockMutex(&queue->lock); #endif return ret; @@ -131,7 +131,7 @@ int wolfEventQueue_Pop(WOLF_EVENT_QUEUE* queue, WOLF_EVENT** event) #ifndef SINGLE_THREADED /* In single threaded mode "event_queue.lock" doesn't exist */ - if ((ret = LockMutex(&queue->lock)) != 0) { + if ((ret = wc_LockMutex(&queue->lock)) != 0) { return ret; } #endif @@ -141,7 +141,7 @@ int wolfEventQueue_Pop(WOLF_EVENT_QUEUE* queue, WOLF_EVENT** event) ret = wolfEventQueue_Remove(queue, *event); #ifndef SINGLE_THREADED - UnLockMutex(&queue->lock); + wc_UnLockMutex(&queue->lock); #endif return ret; @@ -191,7 +191,7 @@ int wolfEventQueue_Poll(WOLF_EVENT_QUEUE* queue, void* context_filter, #ifndef SINGLE_THREADED /* In single threaded mode "event_queue.lock" doesn't exist */ - if ((ret = LockMutex(&queue->lock)) != 0) { + if ((ret = wc_LockMutex(&queue->lock)) != 0) { return ret; } #endif @@ -227,7 +227,7 @@ int wolfEventQueue_Poll(WOLF_EVENT_QUEUE* queue, void* context_filter, } #ifndef SINGLE_THREADED - UnLockMutex(&queue->lock); + wc_UnLockMutex(&queue->lock); #endif /* return number of properly populated events */ @@ -248,7 +248,7 @@ int wolfEventQueue_Count(WOLF_EVENT_QUEUE* queue) #ifndef SINGLE_THREADED /* In single threaded mode "event_queue.lock" doesn't exist */ - if ((ret = LockMutex(&queue->lock)) != 0) { + if ((ret = wc_LockMutex(&queue->lock)) != 0) { return ret; } #endif @@ -256,7 +256,7 @@ int wolfEventQueue_Count(WOLF_EVENT_QUEUE* queue) ret = queue->count; #ifndef SINGLE_THREADED - UnLockMutex(&queue->lock); + wc_UnLockMutex(&queue->lock); #endif return ret; @@ -266,7 +266,7 @@ void wolfEventQueue_Free(WOLF_EVENT_QUEUE* queue) { if (queue) { #ifndef SINGLE_THREADED - FreeMutex(&queue->lock); + wc_FreeMutex(&queue->lock); #endif } } diff --git a/wolfssl/openssl/crypto.h b/wolfssl/openssl/crypto.h index 97a4be17a..7032c24df 100644 --- a/wolfssl/openssl/crypto.h +++ b/wolfssl/openssl/crypto.h @@ -32,6 +32,15 @@ typedef void (CRYPTO_free_func)(void*parent, void*ptr, CRYPTO_EX_DATA *ad, int i long argl, void* argp); #define CRYPTO_THREADID_set_callback wolfSSL_THREADID_set_callback #define CRYPTO_THREADID_set_numeric wolfSSL_THREADID_set_numeric + +#define CRYPTO_lock wc_LockMutex +#define CRYPTO_r_lock wc_LockMutex +#define CRYPTO_unlock wc_UnLockMutex + +#define CRYPTO_THREAD_lock wc_LockMutex +#define CRYPTO_THREAD_r_lock wc_LockMutex +#define CRYPTO_THREAD_unlock wc_UnLockMutex + #endif /* HAVE_STUNNEL */ #endif /* header */ diff --git a/wolfssl/openssl/dh.h b/wolfssl/openssl/dh.h index ac95afa55..50054097e 100644 --- a/wolfssl/openssl/dh.h +++ b/wolfssl/openssl/dh.h @@ -14,12 +14,13 @@ struct WOLFSSL_DH { WOLFSSL_BIGNUM* p; WOLFSSL_BIGNUM* g; + WOLFSSL_BIGNUM* q; WOLFSSL_BIGNUM* pub_key; /* openssh deference g^x */ WOLFSSL_BIGNUM* priv_key; /* openssh deference x */ void* internal; /* our DH */ char inSet; /* internal set from external ? */ char exSet; /* external set from internal ? */ - /*added for lighttpd openssl compatibility, go back and add a getter in + /*added for lighttpd openssl compatibility, go back and add a getter in * lighttpd src code. */ int length; @@ -36,7 +37,7 @@ WOLFSSL_API int wolfSSL_DH_compute_key(unsigned char* key, WOLFSSL_BIGNUM* pub, typedef WOLFSSL_DH DH; -#define DH_new wolfSSL_DH_new +#define DH_new wolfSSL_DH_new #define DH_free wolfSSL_DH_free #define DH_size wolfSSL_DH_size @@ -45,7 +46,7 @@ typedef WOLFSSL_DH DH; #ifdef __cplusplus - } /* extern "C" */ + } /* extern "C" */ #endif #ifdef HAVE_STUNNEL diff --git a/wolfssl/openssl/ssl.h b/wolfssl/openssl/ssl.h index c4672ef0b..15e473402 100644 --- a/wolfssl/openssl/ssl.h +++ b/wolfssl/openssl/ssl.h @@ -259,6 +259,12 @@ typedef WOLFSSL_X509_STORE_CTX X509_STORE_CTX; #define CRYPTO_set_dynlock_destroy_callback wolfSSL_set_dynlock_destroy_callback #define CRYPTO_num_locks wolfSSL_num_locks + +# define CRYPTO_LOCK 1 +# define CRYPTO_UNLOCK 2 +# define CRYPTO_READ 4 +# define CRYPTO_WRITE 8 + #define X509_STORE_CTX_get_current_cert wolfSSL_X509_STORE_CTX_get_current_cert #define X509_STORE_CTX_get_error wolfSSL_X509_STORE_CTX_get_error #define X509_STORE_CTX_get_error_depth wolfSSL_X509_STORE_CTX_get_error_depth @@ -411,7 +417,7 @@ typedef WOLFSSL_X509_STORE_CTX X509_STORE_CTX; /* Lighthttp compatibility */ -#if defined(HAVE_LIGHTY) || defined(WOLFSSL_MYSQL_COMPATIBLE) +#if defined(HAVE_LIGHTY) || defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) typedef WOLFSSL_X509_NAME_ENTRY X509_NAME_ENTRY; #define SSL_CB_HANDSHAKE_START 0x10 diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index a65fafa3f..5e0c50d12 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -1789,7 +1789,7 @@ struct WOLFSSL_X509_NAME_ENTRY { int size; }; -#if defined(HAVE_LIGHTY) || defined(WOLFSSL_MYSQL_COMPATIBLE) +#if defined(HAVE_LIGHTY) || defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) WOLFSSL_API void wolfSSL_X509_NAME_free(WOLFSSL_X509_NAME *name); WOLFSSL_API char wolfSSL_CTX_use_certificate(WOLFSSL_CTX *ctx, WOLFSSL_X509 *x); WOLFSSL_API int wolfSSL_CTX_use_PrivateKey(WOLFSSL_CTX *ctx, WOLFSSL_EVP_PKEY *pkey); @@ -1810,7 +1810,7 @@ WOLFSSL_API unsigned char *wolfSSL_SHA1(const unsigned char *d, size_t n, unsign WOLFSSL_API int wolfSSL_X509_check_private_key(WOLFSSL_X509*, WOLFSSL_EVP_PKEY*); WOLFSSL_API STACK_OF(WOLFSSL_X509_NAME) *wolfSSL_dup_CA_list( STACK_OF(WOLFSSL_X509_NAME) *sk ); -/* end lighttpd*/ +/* end lighttpd, mysql, have_stunnel*/ #endif #endif @@ -1875,7 +1875,7 @@ WOLFSSL_API int wolfSSL_version(WOLFSSL*); WOLFSSL_API int wolfSSL_get_state(const WOLFSSL*); -WOLFSSL_API void* wolfSSL_sk_X509_NAME_value(STACK_OF(WOLFSSL_X509_NAME)*, int); +WOLFSSL_API void* wolfSSL_sk_X509_NAME_value(const STACK_OF(WOLFSSL_X509_NAME)*, int); WOLFSSL_API void* wolfSSL_sk_X509_value(STACK_OF(WOLFSSL_X509)*, int); diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 7612546c0..8a2022808 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -337,7 +337,8 @@ DYNAMIC_TYPE_DTLS_FRAG = 55, DYNAMIC_TYPE_DTLS_BUFFER = 56, DYNAMIC_TYPE_SESSION_TICK = 57, - DYNAMIC_TYPE_PKCS = 58 + DYNAMIC_TYPE_PKCS = 58, + DYNAMIC_TYPE_MUTEX = 59 }; /* max error buffer string size */ diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 16872303c..b170b6b3a 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -90,7 +90,7 @@ typedef int wolfSSL_Mutex; #else /* MULTI_THREADED */ /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */ - #if defined(FREERTOS) + #if defined(FREERTOS) typedef xSemaphoreHandle wolfSSL_Mutex; #elif defined(FREERTOS_TCP) #include "FreeRTOS.h" @@ -169,10 +169,11 @@ #endif /* WOLFSSL_CRYPT_HW_MUTEX */ /* Mutex functions */ -WOLFSSL_LOCAL int InitMutex(wolfSSL_Mutex*); -WOLFSSL_LOCAL int FreeMutex(wolfSSL_Mutex*); -WOLFSSL_LOCAL int LockMutex(wolfSSL_Mutex*); -WOLFSSL_LOCAL int UnLockMutex(wolfSSL_Mutex*); +WOLFSSL_API int wc_InitMutex(wolfSSL_Mutex*); +WOLFSSL_API wolfSSL_Mutex* wc_InitAndAllocMutex(void); +WOLFSSL_API int wc_FreeMutex(wolfSSL_Mutex*); +WOLFSSL_API int wc_LockMutex(wolfSSL_Mutex*); +WOLFSSL_API int wc_UnLockMutex(wolfSSL_Mutex*); /* main crypto initialization function */ WOLFSSL_API int wolfCrypt_Init(void);