From 7555cd06856d0313477bd87c541661b852284293 Mon Sep 17 00:00:00 2001 From: Kareem Date: Thu, 30 Jun 2022 16:11:16 -0700 Subject: [PATCH] Fix a couple of STM32 bugs, and add some missing mutex frees. --- IDE/STM32Cube/wolfssl_example.c | 4 ++-- src/pk.c | 8 ++++++++ wolfcrypt/src/random.c | 2 ++ wolfssl/wolfcrypt/types.h | 14 +++++++------- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/IDE/STM32Cube/wolfssl_example.c b/IDE/STM32Cube/wolfssl_example.c index 74f506a0a..c9411c12b 100644 --- a/IDE/STM32Cube/wolfssl_example.c +++ b/IDE/STM32Cube/wolfssl_example.c @@ -548,7 +548,7 @@ static int ServerMemRecv(info_t* info, char* buf, int sz) } osSemaphoreAcquire(info->server.mutex, osWaitForever); #else - if (osSignalWait(1, RECV_WAIT_TIMEOUT) == osEventTimeout) { + if (osSignalWait(1, RECV_WAIT_TIMEOUT).status == osEventTimeout) { printf("Server Recv: Timeout!\n"); return WOLFSSL_CBIO_ERR_TIMEOUT; } @@ -644,7 +644,7 @@ static int ClientMemRecv(info_t* info, char* buf, int sz) } osSemaphoreAcquire(info->client.mutex, osWaitForever); #else - if (osSignalWait(1, RECV_WAIT_TIMEOUT) == osEventTimeout) { + if (osSignalWait(1, RECV_WAIT_TIMEOUT).status == osEventTimeout) { printf("Client Recv: Timeout!\n"); return WOLFSSL_CBIO_ERR_TIMEOUT; } diff --git a/src/pk.c b/src/pk.c index 2bcb9e809..c0300c522 100644 --- a/src/pk.c +++ b/src/pk.c @@ -6129,6 +6129,10 @@ void wolfSSL_DH_free(WOLFSSL_DH* dh) return; } + #ifndef SINGLE_THREADED + wc_FreeMutex(&dh->refMutex); + #endif + if (dh->internal) { wc_FreeDhKey((DhKey*)dh->internal); XFREE(dh->internal, NULL, DYNAMIC_TYPE_DH); @@ -8295,6 +8299,10 @@ void wolfSSL_EC_KEY_free(WOLFSSL_EC_KEY *key) return; } + #ifndef SINGLE_THREADED + wc_FreeMutex(&key->refMutex); + #endif + if (key->internal != NULL) { wc_ecc_free((ecc_key*)key->internal); XFREE(key->internal, heap, DYNAMIC_TYPE_ECC); diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 03f5167cc..8933dd042 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -2051,6 +2051,8 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) } } + HAL_RNG_DeInit(&hrng); + wolfSSL_CryptHwMutexUnLock(); return 0; diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 73ce7a9ae..8ed9642b3 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -823,13 +823,13 @@ typedef struct w64wrapper { #endif #endif /* !NO_FILESYSTEM && !NO_STDIO_FILESYSTEM */ - #ifndef CTYPE_USER - #ifndef WOLFSSL_LINUXKM - #include - #endif - #if defined(HAVE_ECC) || defined(HAVE_OCSP) || \ - defined(WOLFSSL_KEY_GEN) || !defined(NO_DSA) || \ - defined(OPENSSL_EXTRA) + #ifndef CTYPE_USER + #ifndef WOLFSSL_LINUXKM + #include + #endif + #if defined(HAVE_ECC) || defined(HAVE_OCSP) || \ + defined(WOLFSSL_KEY_GEN) || !defined(NO_DSA) || \ + defined(OPENSSL_EXTRA) #define XTOUPPER(c) toupper((c)) #endif #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)