Browse Source

Add support for VxWorks 6.x
Use rand_r and define SEM_ID_NULL
Fix redefinition of typedef 'SOCKADDR'

Tesfa Mael 2 years ago
parent
commit
cd008aac6a
5 changed files with 51 additions and 20 deletions
  1. 36 17
      wolfcrypt/src/random.c
  2. 5 1
      wolfssl/test.h
  3. 0 2
      wolfssl/wolfcrypt/settings.h
  4. 5 0
      wolfssl/wolfcrypt/wc_port.h
  5. 5 0
      wolfssl/wolfio.h

+ 36 - 17
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 <randomNumGen.h>
+            for (i = 0; i < sz; i++ ) {
+                output[i] = rand_r(&seed) % 256;
+                if ((i % 8) == 7) {
+                    seed = (unsigned int)XTIME(0);
+                    rand_r(&seed);
+                }
+            }
 
-    int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) {
-        STATUS        status;
+            return 0;
+        }
+    #else
+        #include <randomNumGen.h>
 
-        #ifdef VXWORKS_SIM
-            /* cannot generate true entropy with VxWorks simulator */
-            #warning "not enough entropy, simulator for testing only"
-            int i = 0;
+        int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) {
+            STATUS        status;
 
-            for (i = 0; i < 1000; i++) {
-                randomAddTimeStamp();
-            }
-        #endif
+            #ifdef VXWORKS_SIM
+                /* cannot generate true entropy with VxWorks simulator */
+                #warning "not enough entropy, simulator for testing only"
+                int i = 0;
 
-        status = randBytes (output, sz);
-        if (status == ERROR) {
-            return RNG_FAILURE_E;
-        }
+                for (i = 0; i < 1000; i++) {
+                    randomAddTimeStamp();
+                }
+            #endif
 
-        return 0;
-    }
+            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"

+ 5 - 1
wolfssl/test.h

@@ -104,7 +104,11 @@
     #include <sys/types.h>
     #include <netinet/in.h>
     #include <fcntl.h>
-    #include <sys/time.h>
+    #ifdef WOLFSSL_VXWORKS_6_x
+        #include <time.h>
+    #else
+        #include <sys/time.h>
+    #endif
     #include <netdb.h>
     #include <pthread.h>
     #define SOCKET_T int

+ 0 - 2
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

+ 5 - 0
wolfssl/wolfcrypt/wc_port.h

@@ -100,6 +100,11 @@
     #include "fsl_os_abstraction.h"
 #elif defined(WOLFSSL_VXWORKS)
     #include <semLib.h>
+    #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"

+ 5 - 0
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