diff --git a/src/wolfio.c b/src/wolfio.c index 52e61a55e..70e0cd8e9 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -41,6 +41,11 @@ #include #include +#ifdef NUCLEUS_PLUS_2_3 +/* Holds last Nucleus networking error number */ +int Nucleus_Net_Errno; +#endif + #if defined(USE_WOLFSSL_IO) || defined(HAVE_HTTP_CLIENT) #ifndef USE_WINDOWS_API #if defined(WOLFSSL_LWIP) && !defined(WOLFSSL_APACHE_MYNEWT) @@ -176,6 +181,8 @@ static WC_INLINE int wolfSSL_LastError(int err) #elif defined(FUSION_RTOS) #include return FCL_GET_ERRNO; +#elif defined(NUCLEUS_PLUS_2_3) + return Nucleus_Net_Errno; #else return errno; #endif @@ -411,6 +418,110 @@ int EmbedSend(WOLFSSL* ssl, char *buf, int sz, void *ctx) #include +#if defined(NUCLEUS_PLUS_2_3) +STATIC INT32 nucyassl_recv(INT sd, CHAR *buf, UINT16 sz, INT16 flags) +{ + int recvd; + + /* Read data from socket */ + recvd = NU_Recv(sd, buf, sz, flags); + if (recvd < 0) { + if (recvd == NU_NOT_CONNECTED) { + recvd = 0; + } else { + Nucleus_Net_Errno = recvd; + recvd = WOLFSSL_FATAL_ERROR; + } + } else { + Nucleus_Net_Errno = 0; + } + + return (recvd); +} + + +STATIC int nucyassl_send(INT sd, CHAR *buf, UINT16 sz, INT16 flags) +{ + int sent; + + /* Write data to socket */ + sent = NU_Send(sd, buf, sz, flags); + + if (sent < 0) { + Nucleus_Net_Errno = sent; + sent = WOLFSSL_FATAL_ERROR; + } else { + Nucleus_Net_Errno = 0; + } + + return sent; +} + +#define SELECT_FUNCTION nucyassl_select + +int nucyassl_select(INT sd, UINT32 timeout) +{ + FD_SET readfs; + STATUS status; + + /* Init fs data for socket */ + NU_FD_Init(&readfs); + NU_FD_Set(sd, &readfs); + + /* Wait for data to arrive */ + status = NU_Select((sd + 1), &readfs, NU_NULL, NU_NULL, + (timeout * NU_TICKS_PER_SECOND)); + + if (status < 0) { + Nucleus_Net_Errno = status; + status = WOLFSSL_FATAL_ERROR; + } + + return status; +} + +#define sockaddr_storage addr_struct +#define sockaddr addr_struct + +STATIC INT32 nucyassl_recvfrom(INT sd, CHAR *buf, UINT16 sz, INT16 flags, + SOCKADDR *peer, XSOCKLENT *peersz) +{ + int recvd; + + memset(peer, 0, sizeof(struct addr_struct)); + + recvd = NU_Recv_From(sd, buf, sz, flags, (struct addr_struct *) peer, + (INT16*) peersz); + if (recvd < 0) { + Nucleus_Net_Errno = recvd; + recvd = WOLFSSL_FATAL_ERROR; + } else { + Nucleus_Net_Errno = 0; + } + + return recvd; + +} + +STATIC int nucyassl_sendto(INT sd, CHAR *buf, UINT16 sz, INT16 flags, + const SOCKADDR *peer, INT16 peersz) +{ + int sent; + + sent = NU_Send_To(sd, buf, sz, flags, (const struct addr_struct *) peer, + peersz); + + if (sent < 0) { + Nucleus_Net_Errno = sent; + sent = WOLFSSL_FATAL_ERROR; + } else { + Nucleus_Net_Errno = 0; + } + + return sent; +} +#endif /* NUCLEUS_PLUS_2_3 */ + #ifndef DTLS_SENDTO_FUNCTION #define DTLS_SENDTO_FUNCTION sendto #endif diff --git a/wolfcrypt/src/sha.c b/wolfcrypt/src/sha.c index 1892de4e4..a6f5122d9 100644 --- a/wolfcrypt/src/sha.c +++ b/wolfcrypt/src/sha.c @@ -441,7 +441,7 @@ static WC_INLINE void AddLength(wc_Sha* sha, word32 len) #define f3(x,y,z) (((x)&(y))|((z)&((x)|(y)))) #define f4(x,y,z) ((x)^(y)^(z)) - #ifdef WOLFSSL_NUCLEUS_1_2 + #if defined(WOLFSSL_NUCLEUS_1_2) || defined(NUCLEUS_PLUS_2_3) /* nucleus.h also defines R1-R4 */ #undef R1 #undef R2 diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index d1a88bd5d..50d59a7f5 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -3089,6 +3089,8 @@ WOLFSSL_API int wolfSSL_make_eap_keys(WOLFSSL* ssl, void* key, unsigned int len, #include #elif defined(ARDUINO) /* TODO board specific */ + #elif defined(NUCLEUS_PLUS_2_3) + #include "services/sys/uio.h" #elif !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_IAR_ARM) && \ !defined(WOLFSSL_PICOTCP) && !defined(WOLFSSL_ROWLEY_ARM) && \ !defined(WOLFSSL_EMBOS) && !defined(WOLFSSL_FROSTED) && \ diff --git a/wolfssl/wolfcrypt/fips_test.h b/wolfssl/wolfcrypt/fips_test.h index 452e651eb..487b3e2f6 100644 --- a/wolfssl/wolfcrypt/fips_test.h +++ b/wolfssl/wolfcrypt/fips_test.h @@ -114,6 +114,13 @@ WOLFSSL_API int wc_RunCast_fips(int type); WOLFSSL_API int wc_GetCastStatus_fips(int type); WOLFSSL_API int wc_RunAllCast_fips(void); +#ifdef NO_ATTRIBUTE_CONSTRUCTOR + /* NOTE: Must be called in OS initialization section outside user control + * and must prove during operational testing/code review with the lab that + * this is outside user-control if called by the OS */ + void fipsEntry(void); +#endif + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index a4302c700..7d966ab33 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -212,6 +212,9 @@ /* Uncomment next line if building for Nucleus 1.2 */ /* #define WOLFSSL_NUCLEUS_1_2 */ +/* Uncomment next line if building for Nucleus Plus 2.3 */ +/* #define NUCLEUS_PLUS_2_3 */ + /* Uncomment next line if building for using Apache mynewt */ /* #define WOLFSSL_APACHE_MYNEWT */ @@ -319,6 +322,10 @@ #elif defined(USE_HAL_DRIVER) && !defined(HAVE_CONFIG_H) /* STM Configuration File (generated by CubeMX) */ #include "wolfSSL.I-CUBE-wolfSSL_conf.h" +#elif defined(NUCLEUS_PLUS_2_3) + /* NOTE: cyassl_nucleus_defs.h is akin to user_settings.h */ + #include "nucleus.h" + #include "os/networking/ssl/lite/cyassl_nucleus_defs.h" #endif #include diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index e2a1c887e..a4a659c4d 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -168,6 +168,9 @@ #include "socket.h" #elif defined(NETOS) #include + #elif defined(NUCLEUS_PLUS_2_3) + #define SO_TYPE 17 /* Socket type */ + #define SO_RCVTIMEO 13 /* Recv Timeout */ #elif !defined(DEVKITPRO) && !defined(WOLFSSL_PICOTCP) \ && !defined(WOLFSSL_CONTIKI) && !defined(WOLFSSL_WICED) \ && !defined(WOLFSSL_GNRC) && !defined(WOLFSSL_RIOT_OS) @@ -270,6 +273,14 @@ #define SOCKET_EPIPE NU_NOT_CONNECTED #define SOCKET_ECONNREFUSED NU_CONNECTION_REFUSED #define SOCKET_ECONNABORTED NU_NOT_CONNECTED +#elif defined(NUCLEUS_PLUS_2_3) + #define SOCKET_EWOULDBLOCK NU_WOULD_BLOCK + #define SOCKET_EAGAIN NU_NO_DATA + #define SOCKET_ECONNRESET NU_RESET + #define SOCKET_EINTR 0 + #define SOCKET_EPIPE 0 + #define SOCKET_ECONNREFUSED NU_CONNECTION_REFUSED + #define SOCKET_ECONNABORTED NU_CONNECTION_REFUSED #elif defined(WOLFSSL_DEOS) /* `sockaddr_storage` is not defined in DEOS. This workaround will * work for IPV4, but not IPV6 @@ -354,6 +365,11 @@ #elif defined(WOLFSSL_NUCLEUS_1_2) #define SEND_FUNCTION NU_Send #define RECV_FUNCTION NU_Recv +#elif defined(NUCLEUS_PLUS_2_3) + #define SEND_FUNCTION nucyassl_send + #define RECV_FUNCTION nucyassl_recv + #define DTLS_RECVFROM_FUNCTION nucyassl_recvfrom + #define DTLS_SENDTO_FUNCTION nucyassl_sendto #elif defined(FUSION_RTOS) #define SEND_FUNCTION FNS_SEND #define RECV_FUNCTION FNS_RECV @@ -398,6 +414,9 @@ #ifndef XSOCKLENT #ifdef USE_WINDOWS_API #define XSOCKLENT int + #elif defined(NUCLEUS_PLUS_2_3) + typedef int socklen_t; + #define XSOCKLENT socklen_t #else #define XSOCKLENT socklen_t #endif @@ -485,6 +504,10 @@ WOLFSSL_API int BioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx); WOLFSSL_API int EmbedSend(WOLFSSL* ssl, char* buf, int sz, void* ctx); #ifdef WOLFSSL_DTLS + #ifdef NUCLEUS_PLUS_2_3 + #define SELECT_FUNCTION nucyassl_select + WOLFSSL_LOCAL int nucyassl_select(INT sd, UINT32 timeout); + #endif WOLFSSL_API int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx); WOLFSSL_API int EmbedSendTo(WOLFSSL* ssl, char *buf, int sz, void *ctx);