add support for Freescale MQX
This commit is contained in:
parent
a4220120ba
commit
f6304ae37a
@ -53,7 +53,11 @@
|
||||
#endif
|
||||
|
||||
#ifdef CYASSL_DEBUG_ENCODING
|
||||
#include <stdio.h>
|
||||
#ifdef FREESCALE_MQX
|
||||
#include <fio.h>
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@ -497,8 +501,11 @@ static int GetAlgoId(const byte* input, word32* inOutIdx, word32* oid,
|
||||
if (GetLength(input, &i, &length, maxIdx) < 0)
|
||||
return ASN_PARSE_E;
|
||||
|
||||
while(length--)
|
||||
*oid += input[i++];
|
||||
while(length--) {
|
||||
/* odd HC08 compiler behavior here when input[i++] */
|
||||
*oid += input[i];
|
||||
i++;
|
||||
}
|
||||
/* just sum it up for now */
|
||||
|
||||
/* could have NULL tag and 0 terminator, but may not */
|
||||
|
@ -88,7 +88,11 @@ void CyaSSL_Debugging_OFF(void)
|
||||
|
||||
#ifdef DEBUG_CYASSL
|
||||
|
||||
#include <stdio.h> /* for default printf stuff */
|
||||
#ifdef FREESCALE_MQX
|
||||
#include <fio.h>
|
||||
#else
|
||||
#include <stdio.h> /* for default printf stuff */
|
||||
#endif
|
||||
|
||||
#ifdef THREADX
|
||||
int dc_log_printf(char*, ...);
|
||||
|
@ -159,6 +159,19 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif defined(FREESCALE_MQX)
|
||||
|
||||
#warning "write a real random seed!!!!, just for testing now"
|
||||
|
||||
int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < sz; i++ )
|
||||
output[i] = i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif defined(NO_DEV_RANDOM)
|
||||
|
||||
#error "you need to write an os specific GenerateSeed() here"
|
||||
|
@ -32,7 +32,11 @@
|
||||
#include <cyassl/ctaocrypt/logging.h>
|
||||
|
||||
#ifdef SHOW_GEN
|
||||
#include <stdio.h>
|
||||
#ifdef FREESCALE_MQX
|
||||
#include <fio.h>
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -40,7 +40,7 @@ enum {
|
||||
DES_KS_SIZE = 32,
|
||||
|
||||
DES_ENCRYPTION = 0,
|
||||
DES_DECRYPTION = 1,
|
||||
DES_DECRYPTION = 1
|
||||
};
|
||||
|
||||
|
||||
|
@ -63,6 +63,9 @@
|
||||
/* Uncomment next line if building CyaSSL for LSR */
|
||||
/* #define CYASSL_LSR */
|
||||
|
||||
/* Uncomment next line if building CyaSSL for Freescale MQX/RTCS/MFS */
|
||||
/* #define FREESCALE_MQX */
|
||||
|
||||
|
||||
#include <cyassl/ctaocrypt/visibility.h>
|
||||
|
||||
@ -192,6 +195,27 @@
|
||||
#define TFM_TIMING_RESISTANT
|
||||
#endif
|
||||
|
||||
#ifdef FREESCALE_MQX
|
||||
#define SIZEOF_LONG_LONG 8
|
||||
#define NO_WRITEV
|
||||
#define NO_DEV_RANDOM
|
||||
#define NO_RABBIT
|
||||
#define NO_CYASSL_DIR
|
||||
#define USE_FAST_MATH
|
||||
#define TFM_TIMING_RESISTANT
|
||||
#ifndef NO_FILESYSTEM
|
||||
#include "mfs.h"
|
||||
#include "fio.h"
|
||||
#endif
|
||||
#ifndef SINGLE_THREADED
|
||||
#include "mutex.h"
|
||||
#endif
|
||||
|
||||
#define XMALLOC(s, h, type) (void *)_mem_alloc_system((s))
|
||||
#define XFREE(p, h, type) _mem_free(p)
|
||||
/* Note: MQX has no realloc, using fastmath above */
|
||||
#endif
|
||||
|
||||
#ifdef MICRIUM
|
||||
|
||||
#include "stdlib.h"
|
||||
|
@ -357,7 +357,7 @@ typedef struct {
|
||||
void fp_set(fp_int *a, fp_digit b);
|
||||
|
||||
/* copy from a to b */
|
||||
#define fp_copy(a, b) (void)(((a) != (b)) ? (XMEMCPY((b), (a), sizeof(fp_int))) : (void)0)
|
||||
#define fp_copy(a, b) (void)(((a) != (b)) ? ((void)XMEMCPY((b), (a), sizeof(fp_int))) : (void)0)
|
||||
#define fp_init_copy(a, b) fp_copy(b, a)
|
||||
|
||||
/* clamp digits */
|
||||
|
@ -150,7 +150,8 @@ 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) && !defined(EBSNET) && !defined(CYASSL_SAFERTOS)
|
||||
#elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) \
|
||||
&& !defined(CYASSL_SAFERTOS) && !defined(FREESCALE_MQX)
|
||||
/* default C runtime, can install different routines at runtime */
|
||||
#include <cyassl/ctaocrypt/memory.h>
|
||||
#define XMALLOC(s, h, t) ((void)h, (void)t, CyaSSL_Malloc((s)))
|
||||
|
@ -73,6 +73,8 @@
|
||||
/* do nothing */
|
||||
#elif defined(EBSNET)
|
||||
/* do nothing */
|
||||
#elif defined(FREESCALE_MQX)
|
||||
/* do nothing */
|
||||
#else
|
||||
#ifndef SINGLE_THREADED
|
||||
#define CYASSL_PTHREADS
|
||||
@ -724,6 +726,8 @@ struct CYASSL_CIPHER {
|
||||
typedef OS_MUTEX CyaSSL_Mutex;
|
||||
#elif defined(EBSNET)
|
||||
typedef RTP_MUTEX CyaSSL_Mutex;
|
||||
#elif defined(FREESCALE_MQX)
|
||||
typedef MUTEX_STRUCT CyaSSL_Mutex;
|
||||
#else
|
||||
#error Need a mutex type in multithreaded mode
|
||||
#endif /* USE_WINDOWS_API */
|
||||
@ -1359,7 +1363,7 @@ CYASSL_API void SSL_ResourceFree(CYASSL*); /* Micrium uses */
|
||||
|
||||
enum {
|
||||
IV_SZ = 32, /* max iv sz */
|
||||
NAME_SZ = 80, /* max one line */
|
||||
NAME_SZ = 80 /* max one line */
|
||||
};
|
||||
|
||||
|
||||
|
@ -32,7 +32,11 @@
|
||||
|
||||
|
||||
#ifndef NO_FILESYSTEM
|
||||
#include <stdio.h> /* ERR_printf */
|
||||
#ifdef FREESCALE_MQX
|
||||
#include <fio.h>
|
||||
#else
|
||||
#include <stdio.h> /* ERR_printf */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef YASSL_PREFIX
|
||||
|
@ -37,15 +37,23 @@
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG_CYASSL) || defined(SHOW_SECRETS)
|
||||
#include <stdio.h>
|
||||
#ifdef FREESCALE_MQX
|
||||
#include <fio.h>
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __sun
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(OPENSSL_EXTRA) && defined(NO_DH)
|
||||
@ -8011,5 +8019,39 @@ int UnLockMutex(CyaSSL_Mutex *m)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif defined(FREESCALE_MQX)
|
||||
|
||||
int InitMutex(CyaSSL_Mutex* m)
|
||||
{
|
||||
if (_mutex_init(m, NULL) == MQX_EOK)
|
||||
return 0;
|
||||
else
|
||||
return BAD_MUTEX_ERROR;
|
||||
}
|
||||
|
||||
int FreeMutex(CyaSSL_Mutex* m)
|
||||
{
|
||||
if (_mutex_destroy(m) == MQX_EOK)
|
||||
return 0;
|
||||
else
|
||||
return BAD_MUTEX_ERROR;
|
||||
}
|
||||
|
||||
int LockMutex(CyaSSL_Mutex* m)
|
||||
{
|
||||
if (_mutex_lock(m) == MQX_EOK)
|
||||
return 0;
|
||||
else
|
||||
return BAD_MUTEX_ERROR;
|
||||
}
|
||||
|
||||
int UnLockMutex(CyaSSL_Mutex* m)
|
||||
{
|
||||
if (_mutex_unlock(m) == MQX_EOK)
|
||||
return 0;
|
||||
else
|
||||
return BAD_MUTEX_ERROR;
|
||||
}
|
||||
|
||||
#endif /* USE_WINDOWS_API */
|
||||
#endif /* SINGLE_THREADED */
|
||||
|
38
src/io.c
38
src/io.c
@ -48,6 +48,9 @@
|
||||
#ifndef LWIP_PROVIDE_ERRNO
|
||||
#define LWIP_PROVIDE_ERRNO 1
|
||||
#endif
|
||||
#elif defined(FREESCALE_MQX)
|
||||
#include <errno.h>
|
||||
#include <rtcs.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
@ -98,6 +101,14 @@
|
||||
#define SOCKET_EINTR SYS_NET_EINTR
|
||||
#define SOCKET_EPIPE SYS_NET_EPIPE
|
||||
#define SOCKET_ECONNREFUSED SYS_NET_ECONNREFUSED
|
||||
#elif defined(FREESCALE_MQX)
|
||||
/* RTCS doesn't have an EWOULDBLOCK error */
|
||||
#define SOCKET_EWOULDBLOCK EAGAIN
|
||||
#define SOCKET_EAGAIN EAGAIN
|
||||
#define SOCKET_ECONNRESET RTCSERR_TCP_CONN_RESET
|
||||
#define SOCKET_EINTR EINTR
|
||||
#define SOCKET_EPIPE EPIPE
|
||||
#define SOCKET_ECONNREFUSED RTCSERR_TCP_CONN_REFUSED
|
||||
#else
|
||||
#define SOCKET_EWOULDBLOCK EWOULDBLOCK
|
||||
#define SOCKET_EAGAIN EAGAIN
|
||||
@ -133,6 +144,29 @@
|
||||
#endif
|
||||
|
||||
|
||||
/* Translates return codes returned from
|
||||
* send() and recv() if need be.
|
||||
*/
|
||||
static INLINE int TranslateReturnCode(int old, int sd)
|
||||
{
|
||||
(void)sd;
|
||||
|
||||
#ifdef FREESCALE_MQX
|
||||
if (old == 0) {
|
||||
errno = SOCKET_EWOULDBLOCK;
|
||||
return -1; /* convert to BSD style wouldblock as error */
|
||||
}
|
||||
|
||||
if (old < 0) {
|
||||
errno = RTCS_geterror(sd);
|
||||
if (errno == RTCSERR_TCP_CONN_CLOSING)
|
||||
return 0; /* convert to BSD style closing */
|
||||
}
|
||||
#endif
|
||||
|
||||
return old;
|
||||
}
|
||||
|
||||
static INLINE int LastError(void)
|
||||
{
|
||||
#ifdef USE_WINDOWS_API
|
||||
@ -172,6 +206,8 @@ int EmbedReceive(CYASSL *ssl, char *buf, int sz, void *ctx)
|
||||
|
||||
recvd = (int)RECV_FUNCTION(sd, buf, sz, ssl->rflags);
|
||||
|
||||
recvd = TranslateReturnCode(recvd, sd);
|
||||
|
||||
if (recvd < 0) {
|
||||
err = LastError();
|
||||
CYASSL_MSG("Embed Receive error");
|
||||
@ -294,6 +330,8 @@ int EmbedReceiveFrom(CYASSL *ssl, char *buf, int sz, void *ctx)
|
||||
recvd = (int)RECVFROM_FUNCTION(sd, buf, sz, ssl->rflags,
|
||||
(struct sockaddr*)&peer, &peerSz);
|
||||
|
||||
recvd = TranslateReturnCode(recvd, sd);
|
||||
|
||||
if (recvd < 0) {
|
||||
err = LastError();
|
||||
CYASSL_MSG("Embed Receive From error");
|
||||
|
@ -27,7 +27,11 @@
|
||||
#include <cyassl/internal.h>
|
||||
#include <cyassl/error.h>
|
||||
#ifdef SHOW_SECRETS
|
||||
#include <stdio.h>
|
||||
#ifdef FREESCALE_MQX
|
||||
#include <fio.h>
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
10
src/ssl.c
10
src/ssl.c
@ -1392,6 +1392,16 @@ static int ProcessChainBuffer(CYASSL_CTX* ctx, const unsigned char* buff,
|
||||
#define XFCLOSE fs_close
|
||||
#define XSEEK_END 0
|
||||
#define XBADFILE NULL
|
||||
#elif defined(FREESCALE_MQX)
|
||||
#define XFILE MQX_FILE_PTR
|
||||
#define XFOPEN fopen
|
||||
#define XFSEEK fseek
|
||||
#define XFTELL ftell
|
||||
#define XREWIND(F) fseek(F, 0, IO_SEEK_SET)
|
||||
#define XFREAD fread
|
||||
#define XFCLOSE fclose
|
||||
#define XSEEK_END IO_SEEK_END
|
||||
#define XBADFILE NULL
|
||||
#elif defined(MICRIUM)
|
||||
#include <fs.h>
|
||||
#define XFILE FS_FILE*
|
||||
|
Loading…
x
Reference in New Issue
Block a user