From cd008aac6aab20df7ce7b9b26eaa2e5a8f729015 Mon Sep 17 00:00:00 2001 From: Tesfa Mael Date: Thu, 31 Mar 2022 11:49:46 -0700 Subject: [PATCH] Add support for VxWorks 6.x Use rand_r and define SEM_ID_NULL Fix redefinition of typedef 'SOCKADDR' --- wolfcrypt/src/random.c | 55 ++++++++++++++++++++++++------------ wolfssl/test.h | 6 +++- wolfssl/wolfcrypt/settings.h | 2 -- wolfssl/wolfcrypt/wc_port.h | 5 ++++ wolfssl/wolfio.h | 5 ++++ 5 files changed, 52 insertions(+), 21 deletions(-) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 7d9734a63..637858396 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -2206,30 +2206,49 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) return 0; } #elif defined(WOLFSSL_VXWORKS) + #ifdef WOLFSSL_VXWORKS_6_x + #include "stdlib.h" + #warning "potential for not enough entropy, currently being used for testing" + int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) + { + int i; + unsigned int seed = (unsigned int)XTIME(0); + (void)os; - #include - - int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) { - STATUS status; - - #ifdef VXWORKS_SIM - /* cannot generate true entropy with VxWorks simulator */ - #warning "not enough entropy, simulator for testing only" - int i = 0; - - for (i = 0; i < 1000; i++) { - randomAddTimeStamp(); + for (i = 0; i < sz; i++ ) { + output[i] = rand_r(&seed) % 256; + if ((i % 8) == 7) { + seed = (unsigned int)XTIME(0); + rand_r(&seed); + } } - #endif - status = randBytes (output, sz); - if (status == ERROR) { - return RNG_FAILURE_E; + return 0; } + #else + #include - return 0; - } + int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) { + STATUS status; + #ifdef VXWORKS_SIM + /* cannot generate true entropy with VxWorks simulator */ + #warning "not enough entropy, simulator for testing only" + int i = 0; + + for (i = 0; i < 1000; i++) { + randomAddTimeStamp(); + } + #endif + + status = randBytes (output, sz); + if (status == ERROR) { + return RNG_FAILURE_E; + } + + return 0; + } + #endif #elif defined(WOLFSSL_NRF51) || defined(WOLFSSL_NRF5x) #include "app_error.h" #include "nrf_drv_rng.h" diff --git a/wolfssl/test.h b/wolfssl/test.h index 5aa8cf8ee..f5db32209 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -104,7 +104,11 @@ #include #include #include - #include + #ifdef WOLFSSL_VXWORKS_6_x + #include + #else + #include + #endif #include #include #define SOCKET_T int diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index 6f34f905a..bf08639b4 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -565,8 +565,6 @@ /* #define WOLFSSL_PTHREADS */ #define WOLFSSL_HAVE_MIN #define WOLFSSL_HAVE_MAX - #define USE_FAST_MATH - #define TFM_TIMING_RESISTANT #define NO_MAIN_DRIVER #define NO_DEV_RANDOM #define NO_WRITEV diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index f6a7180e1..847d1433e 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -100,6 +100,11 @@ #include "fsl_os_abstraction.h" #elif defined(WOLFSSL_VXWORKS) #include + #ifdef WOLFSSL_VXWORKS_6_x + #ifndef SEM_ID_NULL + #define SEM_ID_NULL ((SEM_ID)NULL) + #endif + #endif #elif defined(WOLFSSL_uITRON4) #include "stddef.h" #include "kernel.h" diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index a7db0774c..965590086 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -312,6 +312,9 @@ #define RECV_FUNCTION(a,b,c,d) FreeRTOS_recv((Socket_t)(a),(void*)(b), (size_t)(c), (BaseType_t)(d)) #define SEND_FUNCTION(a,b,c,d) FreeRTOS_send((Socket_t)(a),(void*)(b), (size_t)(c), (BaseType_t)(d)) #elif defined(WOLFSSL_VXWORKS) + /*socket.h already has "typedef struct sockaddr SOCKADDR;" + so don't redefine it in wolfSSL */ + #define HAVE_SOCKADDR_DEFINED #define SEND_FUNCTION send #define RECV_FUNCTION recv #elif defined(WOLFSSL_NUCLEUS_1_2) @@ -364,7 +367,9 @@ /* Socket Addr Support */ #ifdef HAVE_SOCKADDR + #ifndef HAVE_SOCKADDR_DEFINED typedef struct sockaddr SOCKADDR; + #endif typedef struct sockaddr_storage SOCKADDR_S; typedef struct sockaddr_in SOCKADDR_IN; #ifdef WOLFSSL_IPV6