initial Nucleus port with PB changes

This commit is contained in:
Chris Conlon
2017-04-07 14:08:09 -06:00
parent f7c5b27bfc
commit eeb50099d9
9 changed files with 194 additions and 0 deletions

View File

@ -6067,6 +6067,16 @@ ProtocolVersion MakeDTLSv1_2(void)
return (word32)(uTaskerSystemTick / TICK_RESOLUTION); return (word32)(uTaskerSystemTick / TICK_RESOLUTION);
} }
#elif defined(WOLFSSL_NUCLEUS)
#define NU_TICKS_PER_SECOND 100
word32 LowResTimer(void)
{
/* returns number of 10ms ticks, so 100 ticks/sec */
return NU_Retrieve_Clock() / NU_TICKS_PER_SECOND;
}
#else #else
/* Posix style time */ /* Posix style time */
#ifndef USER_TIME #ifndef USER_TIME

View File

@ -142,6 +142,7 @@ int wc_RNG_GenerateByte(WC_RNG* rng, byte* b)
#elif defined(WOLFSSL_ROWLEY_ARM) #elif defined(WOLFSSL_ROWLEY_ARM)
#elif defined(WOLFSSL_EMBOS) #elif defined(WOLFSSL_EMBOS)
#elif defined(MICRIUM) #elif defined(MICRIUM)
#elif defined(WOLFSSL_NUCLEUS)
#else #else
/* include headers that may be needed to get good seed */ /* include headers that may be needed to get good seed */
#include <fcntl.h> #include <fcntl.h>
@ -1613,6 +1614,20 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
return 0; return 0;
} }
#elif defined(WOLFSSL_PB)
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
word32 i;
for (i = 0; i < sz; i++)
output[i] = UTL_Rand();
(void)os;
return 0;
}
#elif defined(WOLFSSL_NUCLEUS) #elif defined(WOLFSSL_NUCLEUS)
#include "nucleus.h" #include "nucleus.h"
#include "kernel/plus_common.h" #include "kernel/plus_common.h"

View File

@ -287,6 +287,14 @@ static WC_INLINE void AddLength(wc_Sha* sha, word32 len)
#define f3(x,y,z) (((x)&(y))|((z)&((x)|(y)))) #define f3(x,y,z) (((x)&(y))|((z)&((x)|(y))))
#define f4(x,y,z) ((x)^(y)^(z)) #define f4(x,y,z) ((x)^(y)^(z))
#ifdef WOLFSSL_NUCLEUS
/* nucleus.h also defines R1-R4 */
#undef R1
#undef R2
#undef R3
#undef R4
#endif
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v,w,x,y,z,i) (z)+= f1((w),(x),(y)) + blk0((i)) + 0x5A827999+ \ #define R0(v,w,x,y,z,i) (z)+= f1((w),(x),(y)) + blk0((i)) + 0x5A827999+ \
rotlFixed((v),5); (w) = rotlFixed((w),30); rotlFixed((v),5); (w) = rotlFixed((w),30);

View File

@ -1255,6 +1255,44 @@ int wolfSSL_CryptHwMutexUnLock(void) {
return ret; return ret;
} }
#elif defined(WOLFSSL_NUCLEUS)
int wc_InitMutex(wolfSSL_Mutex* m)
{
/* Call the Nucleus function to create the semaphore */
if (NU_Create_Semaphore(m, "WOLFSSL_MTX", 1,
NU_PRIORITY) == NU_SUCCESS) {
return 0;
}
return BAD_MUTEX_E;
}
int wc_FreeMutex(wolfSSL_Mutex* m)
{
if (NU_Delete_Semaphore(m) == NU_SUCCESS)
return 0;
return BAD_MUTEX_E;
}
int wc_LockMutex(wolfSSL_Mutex* m)
{
/* passing suspend task option */
if (NU_Obtain_Semaphore(m, NU_SUSPEND) == NU_SUCCESS)
return 0;
return BAD_MUTEX_E;
}
int wc_UnLockMutex(wolfSSL_Mutex* m)
{
if (NU_Release_Semaphore(m) == NU_SUCCESS)
return 0;
return BAD_MUTEX_E;
}
#else #else
#warning No mutex handling defined #warning No mutex handling defined
@ -1487,6 +1525,66 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
} }
#endif #endif
/* custom memory wrappers */
#ifdef WOLFSSL_NUCLEUS
/* system memory pool */
extern NU_MEMORY_POOL System_Memory;
void* nucleus_malloc(unsigned long size, void* heap, int type)
{
STATUS status;
void* stack_ptr;
status = NU_Allocate_Memory(&System_Memory, &stack_ptr, size,
NU_NO_SUSPEND);
if (status == NU_SUCCESS) {
return 0;
} else {
return stack_ptr;
}
}
void* nucleus_realloc(void* ptr, unsigned long size, void* heap, int type)
{
STATUS status;
DM_HEADER* old_header;
word32 old_size, copy_size;
void* new_mem;
/* if ptr is NULL, behave like malloc */
new_mem = nucleus_malloc(size, NULL, 0);
if (new_mem == 0 || ptr == 0) {
return new_mem;
}
/* calculate old memory block size */
/* mem pointers stored in block headers (ref dm_defs.h) */
old_header = (DM_HEADER*) ((byte*)ptr - DM_OVERHEAD);
old_size = (byte*)old_header->dm_next_memory - (byte*)ptr;
/* copy old to new */
if (old_size < size) {
copy_size = old_size;
} else {
copy_size = size;
}
XMEMCPY(new_mem, ptr, copy_size);
/* free old */
nucleus_free(ptr, NULL, 0);
return new_mem;
}
void nucleus_free(void* ptr, void* heap, int type)
{
if (ptr != NULL)
NU_Deallocate_Memory(ptr);
}
#endif /* WOLFSSL_NUCLEUS */
#if defined(WOLFSSL_TI_CRYPT) || defined(WOLFSSL_TI_HASH) #if defined(WOLFSSL_TI_CRYPT) || defined(WOLFSSL_TI_HASH)
#include <wolfcrypt/src/port/ti/ti-ccm.c> /* initialize and Mutex for TI Crypt Engine */ #include <wolfcrypt/src/port/ti/ti-ccm.c> /* initialize and Mutex for TI Crypt Engine */
#include <wolfcrypt/src/port/ti/ti-hash.c> /* md5, sha1, sha224, sha256 */ #include <wolfcrypt/src/port/ti/ti-hash.c> /* md5, sha1, sha224, sha256 */

View File

@ -159,6 +159,8 @@
/* do nothing */ /* do nothing */
#elif defined(INTIME_RTOS) #elif defined(INTIME_RTOS)
#include <rt.h> #include <rt.h>
#elif defined(WOLFSSL_NUCLEUS)
/* do nothing */
#else #else
#ifndef SINGLE_THREADED #ifndef SINGLE_THREADED
#define WOLFSSL_PTHREADS #define WOLFSSL_PTHREADS

View File

@ -71,6 +71,11 @@ extern "C" {
/* C++ compilers don't like assigning void * to mp_digit * */ /* C++ compilers don't like assigning void * to mp_digit * */
#define OPT_CAST(x) (x *) #define OPT_CAST(x) (x *)
#elif defined(_SH3)
/* SuperH SH3 compiler doesn't like assigning voi* to mp_digit* */
#define OPT_CAST(x) (x *)
#else #else
/* C on the other hand doesn't care */ /* C on the other hand doesn't care */

View File

@ -162,6 +162,9 @@
/* Uncomment next line if building for using XILINX */ /* Uncomment next line if building for using XILINX */
/* #define WOLFSSL_XILINX */ /* #define WOLFSSL_XILINX */
/* Uncomment next line if building for Nucleus */
/* #define WOLFSSL_NUCLEUS */
#include <wolfssl/wolfcrypt/visibility.h> #include <wolfssl/wolfcrypt/visibility.h>
#ifdef WOLFSSL_USER_SETTINGS #ifdef WOLFSSL_USER_SETTINGS
@ -447,6 +450,26 @@
#include "wolfssl_chibios.h" #include "wolfssl_chibios.h"
#endif #endif
#ifdef WOLFSSL_NUCLEUS
#define NO_WRITEV
#define NO_WOLFSSL_DIR
#ifndef USER_TIME
#error User must define XTIME, see manual
#endif
#if !defined(XMALLOC_OVERRIDE) && !defined(XMALLOC_USER)
extern void* nucleus_malloc(unsigned long size, void* heap, int type);
extern void* nucleus_realloc(void* ptr, unsigned long size, void* heap,
int type);
extern void nucleus_free(void* ptr, void* heap, int type);
#define XMALLOC(s, h, type) nucleus_malloc
#define XREALLOC(p, n, h, t) nucleus_realloc
#define XFREE(p, h, type) nucleus_free
#endif
#endif
#ifdef WOLFSSL_NRF5x #ifdef WOLFSSL_NRF5x
#define SIZEOF_LONG 4 #define SIZEOF_LONG 4
#define SIZEOF_LONG_LONG 8 #define SIZEOF_LONG_LONG 8

View File

@ -97,6 +97,11 @@
#elif defined(INTIME_RTOS) #elif defined(INTIME_RTOS)
#include <rt.h> #include <rt.h>
#include <io.h> #include <io.h>
#elif defined(WOLFSSL_NUCLEUS)
/* NU_DEBUG needed struct access in nucleus_realloc */
#define NU_DEBUG
#include "plus/nucleus.h"
#include "nucleus.h"
#else #else
#ifndef SINGLE_THREADED #ifndef SINGLE_THREADED
#define WOLFSSL_PTHREADS #define WOLFSSL_PTHREADS
@ -168,6 +173,8 @@
typedef mutex_t * wolfSSL_Mutex; typedef mutex_t * wolfSSL_Mutex;
#elif defined(INTIME_RTOS) #elif defined(INTIME_RTOS)
typedef RTHANDLE wolfSSL_Mutex; typedef RTHANDLE wolfSSL_Mutex;
#elif defined(WOLFSSL_NUCLEUS)
typedef NU_SEMAPHORE wolfSSL_Mutex;
#else #else
#error Need a mutex type in multithreaded mode #error Need a mutex type in multithreaded mode
#endif /* USE_WINDOWS_API */ #endif /* USE_WINDOWS_API */
@ -273,6 +280,18 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
#define XSEEK_END FS_SEEK_END #define XSEEK_END FS_SEEK_END
#define XBADFILE NULL #define XBADFILE NULL
#define XFGETS(b,s,f) -2 /* Not ported yet */ #define XFGETS(b,s,f) -2 /* Not ported yet */
#elif defined(WOLFSSL_NUCLEUS)
#include "fal/inc/fal.h"
#define XFILE FILE*
#define XFOPEN fopen
#define XFSEEK fseek
#define XFTELL ftell
#define XREWIND rewind
#define XFREAD fread
#define XFWRITE fwrite
#define XFCLOSE fclose
#define XSEEK_END PSEEK_END
#define XBADFILE NULL
#else #else
/* stdio, default case */ /* stdio, default case */
#include <stdio.h> #include <stdio.h>

View File

@ -80,6 +80,9 @@
#elif defined(WOLFSSL_VXWORKS) #elif defined(WOLFSSL_VXWORKS)
#include <sockLib.h> #include <sockLib.h>
#include <errno.h> #include <errno.h>
#elif defined(WOLFSSL_NUCLEUS)
#include <externs.h>
#include <errno.h>
#elif defined(WOLFSSL_ATMEL) #elif defined(WOLFSSL_ATMEL)
#include "socket/include/socket.h" #include "socket/include/socket.h"
#elif defined(INTIME_RTOS) #elif defined(INTIME_RTOS)
@ -198,6 +201,14 @@
#define SOCKET_EPIPE FREERTOS_SOCKET_ERROR #define SOCKET_EPIPE FREERTOS_SOCKET_ERROR
#define SOCKET_ECONNREFUSED FREERTOS_SOCKET_ERROR #define SOCKET_ECONNREFUSED FREERTOS_SOCKET_ERROR
#define SOCKET_ECONNABORTED FREERTOS_SOCKET_ERROR #define SOCKET_ECONNABORTED FREERTOS_SOCKET_ERROR
#elif defined(WOLFSSL_NUCLEUS)
#define SOCKET_EWOULDBLOCK NU_WOULD_BLOCK
#define SOCKET_EAGAIN NU_WOULD_BLOCK
#define SOCKET_ECONNRESET NU_NOT_CONNECTED
#define SOCKET_EINTR NU_NOT_CONNECTED
#define SOCKET_EPIPE NU_NOT_CONNECTED
#define SOCKET_ECONNREFUSED NU_CONNECTION_REFUSED
#define SOCKET_ECONNABORTED NU_NOT_CONNECTED
#else #else
#define SOCKET_EWOULDBLOCK EWOULDBLOCK #define SOCKET_EWOULDBLOCK EWOULDBLOCK
#define SOCKET_EAGAIN EAGAIN #define SOCKET_EAGAIN EAGAIN
@ -244,6 +255,9 @@
#elif defined(WOLFSSL_VXWORKS) #elif defined(WOLFSSL_VXWORKS)
#define SEND_FUNCTION send #define SEND_FUNCTION send
#define RECV_FUNCTION recv #define RECV_FUNCTION recv
#elif defined(WOLFSSL_NUCLEUS)
#define SEND_FUNCTION NU_Send
#define RECV_FUNCTION NU_Recv
#else #else
#define SEND_FUNCTION send #define SEND_FUNCTION send
#define RECV_FUNCTION recv #define RECV_FUNCTION recv