diff --git a/ctaocrypt/src/random.c b/ctaocrypt/src/random.c index aeb60b59f..33a282b02 100644 --- a/ctaocrypt/src/random.c +++ b/ctaocrypt/src/random.c @@ -41,7 +41,9 @@ #else #ifndef NO_DEV_RANDOM #include - #include + #ifndef EBSNET + #include + #endif #else /* include headers that may be needed to get good seed */ #endif @@ -101,7 +103,7 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz) } -#elif defined(THREADX) +#elif defined(THREADX) || defined(EBSNET) #include "rtprand.h" /* rtp_rand () */ #include "rtptime.h" /* rtp_get_system_msec() */ diff --git a/cyassl/ctaocrypt/settings.h b/cyassl/ctaocrypt/settings.h index 72f19ff25..a617400a0 100644 --- a/cyassl/ctaocrypt/settings.h +++ b/cyassl/ctaocrypt/settings.h @@ -51,6 +51,9 @@ /* Uncomment next line if using FreeRTOS Windows Simulator */ /* #define FREERTOS_WINSIM */ +/* Uncomment next line if using RTIP */ +/* #define EBSNET */ + /* Uncomment next line if using lwip */ /* #define CYASSL_LWIP */ @@ -106,6 +109,39 @@ #endif #endif +#ifdef EBSNET + #include "rtip.h" + + /* #define DEBUG_CYASSL */ + #define NO_CYASSL_DIR /* tbd */ + + #if (POLLOS) + #define SINGLE_THREADED + #endif + + #if (RTPLATFORM) + #if (!RTP_LITTLE_ENDIAN) + #define BIG_ENDIAN_ORDER + #endif + #else + #if (!KS_LITTLE_ENDIAN) + #define BIG_ENDIAN_ORDER + #endif + #endif + + #if (WINMSP3) + #undef SIZEOF_LONG + #define SIZEOF_LONG_LONG 8 + #else + #sslpro: settings.h - please implement SIZEOF_LONG and SIZEOF_LONG_LONG + #endif + + #define XMALLOC(s, h, type) ((void *)rtp_malloc((s), SSL_PRO_MALLOC)) + #define XFREE(p, h, type) (rtp_free(p)) + #define XREALLOC(p, n, h, t) realloc((p), (n)) + +#endif /* EBSNET */ + #ifdef CYASSL_GAME_BUILD #define SIZEOF_LONG_LONG 8 #if defined(__PPU) || defined(__XENON) diff --git a/cyassl/ctaocrypt/types.h b/cyassl/ctaocrypt/types.h index d93df712a..210c8bcb8 100644 --- a/cyassl/ctaocrypt/types.h +++ b/cyassl/ctaocrypt/types.h @@ -132,7 +132,8 @@ enum { /* Micrium will use Visual Studio for compilation but not the Win32 API */ -#if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) +#if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) \ + && !defined(EBSNET) #define USE_WINDOWS_API #endif @@ -147,7 +148,7 @@ enum { extern void *XMALLOC(size_t n, void* heap, int type); extern void *XREALLOC(void *p, size_t n, void* heap, int type); extern void XFREE(void *p, void* heap, int type); -#elif !defined(MICRIUM_MALLOC) +#elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) /* default C runtime, can install different routines at runtime */ #include #define XMALLOC(s, h, t) CyaSSL_Malloc((s)) diff --git a/cyassl/internal.h b/cyassl/internal.h index d958881ab..3174e76ae 100644 --- a/cyassl/internal.h +++ b/cyassl/internal.h @@ -71,6 +71,8 @@ /* do nothing, just don't pick Unix */ #elif defined(FREERTOS) || defined(CYASSL_SAFERTOS) /* do nothing */ +#elif defined(EBSNET) + /* do nothing */ #else #ifndef SINGLE_THREADED #define CYASSL_PTHREADS @@ -683,6 +685,8 @@ struct CYASSL_CIPHER { typedef TX_MUTEX CyaSSL_Mutex; #elif defined(MICRIUM) typedef OS_MUTEX CyaSSL_Mutex; + #elif defined(EBSNET) + typedef RTP_MUTEX CyaSSL_Mutex; #else #error Need a mutex type in multithreaded mode #endif /* USE_WINDOWS_API */ diff --git a/src/internal.c b/src/internal.c index 211483c0f..367b97ed3 100644 --- a/src/internal.c +++ b/src/internal.c @@ -7130,5 +7130,35 @@ int UnLockMutex(CyaSSL_Mutex* m) } + #elif defined(EBSNET) + + int InitMutex(CyaSSL_Mutex* m) + { + if (rtp_sig_mutex_alloc(m, "CyaSSL Mutex") == -1) + return BAD_MUTEX_ERROR; + else + return 0; + } + + int FreeMutex(CyaSSL_Mutex* m) + { + rtp_sig_mutex_free(*m); + return 0; + } + + int LockMutex(CyaSSL_Mutex* m) + { + if (rtp_sig_mutex_claim_timed(*m, RTIP_INF) == 0) + return 0; + else + return BAD_MUTEX_ERROR; + } + + int UnLockMutex(CyaSSL_Mutex* m) + { + rtp_sig_mutex_release(*m); + return 0; + } + #endif /* USE_WINDOWS_API */ #endif /* SINGLE_THREADED */ diff --git a/src/io.c b/src/io.c index 5040b425a..1b8602227 100644 --- a/src/io.c +++ b/src/io.c @@ -51,9 +51,11 @@ #else #include #include - #include + #ifndef EBSNET + #include + #endif #include - #if !(defined(DEVKITPRO) || defined(THREADX)) + #if !(defined(DEVKITPRO) || defined(THREADX) || defined(EBSNET)) #include #include #include @@ -67,6 +69,10 @@ #ifdef THREADX #include #endif + #ifdef EBSNET + #include "rtipapi.h" /* errno */ + #include "socket.h" + #endif #endif #endif /* USE_WINDOWS_API */ @@ -118,6 +124,8 @@ static INLINE int LastError(void) { #ifdef USE_WINDOWS_API return WSAGetLastError(); +#elif defined(EBSNET) + return xn_getlasterror(); #else return errno; #endif @@ -209,6 +217,13 @@ int EmbedSend(char *buf, int sz, void *ctx) #include +#ifdef USE_WINDOWS_API + #define XSOCKLENT int +#else + #define XSOCKLENT socklen_t +#endif + + /* The DTLS Generate Cookie callback * return : number of bytes copied into buf, or error */ @@ -216,15 +231,15 @@ int EmbedGenerateCookie(byte *buf, int sz, void *ctx) { CYASSL* ssl = (CYASSL*)ctx; int sd = ssl->wfd; - struct sockaddr_storage peer; - socklen_t peerSz = sizeof(peer); - byte cookieSrc[sizeof(struct in6_addr) + sizeof(int)]; + struct sockaddr_in peer; + XSOCKLENT peerSz = sizeof(peer); + byte cookieSrc[sizeof(struct in_addr) + sizeof(int)]; int cookieSrcSz = 0; Sha sha; getpeername(sd, (struct sockaddr*)&peer, &peerSz); - if (peer.ss_family == AF_INET) { + if (peer.sin_family == AF_INET) { struct sockaddr_in *s = (struct sockaddr_in*)&peer; cookieSrcSz = sizeof(struct in_addr) + sizeof(s->sin_port); @@ -232,17 +247,17 @@ int EmbedGenerateCookie(byte *buf, int sz, void *ctx) XMEMCPY(cookieSrc + sizeof(s->sin_port), &s->sin_addr, sizeof(struct in_addr)); } - else if (peer.ss_family == AF_INET6) { - struct sockaddr_in6 *s = (struct sockaddr_in6*)&peer; - - cookieSrcSz = sizeof(struct in6_addr) + sizeof(s->sin6_port); - XMEMCPY(cookieSrc, &s->sin6_port, sizeof(s->sin6_port)); - XMEMCPY(cookieSrc + sizeof(s->sin6_port), - &s->sin6_addr, sizeof(struct in6_addr)); - } InitSha(&sha); ShaUpdate(&sha, cookieSrc, cookieSrcSz); + + if (sz < SHA_DIGEST_SIZE) { + byte digest[SHA_DIGEST_SIZE]; + ShaFinal(&sha, digest); + XMEMCPY(buf, digest, sz); + return sz; + } + ShaFinal(&sha, buf); return SHA_DIGEST_SIZE; diff --git a/src/ocsp.c b/src/ocsp.c index 3b3dea968..b64bee736 100644 --- a/src/ocsp.c +++ b/src/ocsp.c @@ -25,21 +25,29 @@ #ifdef HAVE_OCSP +#ifdef EBSNET + #include "rtip.h" + #include "socket.h" +#endif + #include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include + +#ifndef EBSNET + #include + #include + #include + #include + #include + #include + #include + #include + #include +#endif CYASSL_API int ocsp_test(unsigned char* buf, int sz); diff --git a/src/ssl.c b/src/ssl.c index a8ee7c717..c2dc26931 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -61,9 +61,14 @@ #endif #ifndef NO_FILESYSTEM - #if !defined(USE_WINDOWS_API) && !defined(NO_CYASSL_DIR) + #if !defined(USE_WINDOWS_API) && !defined(NO_CYASSL_DIR) \ + && !defined(EBSNET) #include #endif + #ifdef EBSNET + #include "vfapi.h" + #include "vfile.h" + #endif #endif /* NO_FILESYSTEM */ @@ -1199,7 +1204,17 @@ static int ProcessChainBuffer(CYASSL_CTX* ctx, const unsigned char* buff, #ifndef NO_FILESYSTEM -#ifndef MICRIUM +#if defined(EBSNET) + #define XFILE int + #define XFOPEN(NAME, MODE) vf_open((const char *)NAME, VO_RDONLY, 0); + #define XFSEEK vf_lseek + #define XFTELL vf_tell + #define XREWIND vf_rewind + #define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT) + #define XFCLOSE vf_close + #define XSEEK_END VSEEK_END + #define XBADFILE -1 +#elif !defined(MICRIUM) #define XFILE FILE* #define XFOPEN fopen #define XFSEEK fseek