From 7ec04c16b64685216a113d58c3af57d8e3d8ee65 Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Mon, 13 Aug 2012 17:10:05 -0600 Subject: [PATCH] EBSnet RTIP support --- ctaocrypt/src/random.c | 6 ++++-- cyassl/ctaocrypt/settings.h | 36 ++++++++++++++++++++++++++++++++++++ cyassl/ctaocrypt/types.h | 5 +++-- cyassl/internal.h | 4 ++++ src/internal.c | 30 ++++++++++++++++++++++++++++++ src/io.c | 12 ++++++++++-- src/ocsp.c | 26 +++++++++++++++++--------- src/ssl.c | 19 +++++++++++++++++-- 8 files changed, 121 insertions(+), 17 deletions(-) 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 ef60087aa..63f698abf 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 */ @@ -103,6 +106,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 372ca4a82..a5d6514d3 100644 --- a/cyassl/internal.h +++ b/cyassl/internal.h @@ -71,6 +71,8 @@ /* do nothing, just don't pick Unix */ #elif defined(FREERTOS) /* do nothing */ +#elif defined(EBSNET) + /* do nothing */ #else #ifndef SINGLE_THREADED #define CYASSL_PTHREADS @@ -678,6 +680,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 ff73e0bfd..0e843b37b 100644 --- a/src/internal.c +++ b/src/internal.c @@ -7098,5 +7098,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 660f1320a..cc0c25080 100644 --- a/src/io.c +++ b/src/io.c @@ -49,9 +49,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 @@ -65,6 +67,10 @@ #ifdef THREADX #include #endif + #ifdef EBSNET + #include "rtipapi.h" /* errno */ + #include "socket.h" + #endif #endif #endif /* USE_WINDOWS_API */ @@ -113,6 +119,8 @@ static INLINE int LastError(void) { #ifdef USE_WINDOWS_API return WSAGetLastError(); +#elif defined(EBSNET) + return un_getlasterror(); #else return errno; #endif 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 6101f8eb5..abd0f2b49 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 */ @@ -1200,7 +1205,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