pull in Kojo MDK-ARM projects, changes

This commit is contained in:
toddouska 2013-05-16 09:47:27 -07:00
parent 05f11c4bca
commit cfdfa7b2b3
35 changed files with 7332 additions and 180 deletions

View File

@ -0,0 +1,269 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rt_sys.h>
#include <File_Config.h>
#pragma import(__use_no_semihosting_swi)
/* The following macro definitions may be used to translate this file:
STDIO - use standard Input/Output device
(default is NOT used)
*/
/* Standard IO device handles. */
#define STDIN 0x8001
#define STDOUT 0x8002
#define STDERR 0x8003
/* Standard IO device name defines. */
const char __stdin_name[] = "STDIN";
const char __stdout_name[] = "STDOUT";
const char __stderr_name[] = "STDERR";
struct __FILE { int handle; /* Add whatever you need here */ };
#ifdef STDIO
extern int SER_GetChar (void);
extern int SER_PutChar (int ch);
/*-----------------------------------------------------------------------------
Write character to the Serial Port
*----------------------------------------------------------------------------*/
int sendchar (int c)
{
if (c == '\n') {
SER_PutChar ('\r');
}
SER_PutChar (c);
return (c);
}
/*-----------------------------------------------------------------------------
Read character from the Serial Port
*----------------------------------------------------------------------------*/
int getkey (void)
{
int ch = SER_GetChar();
if (ch < 0) {
return 0;
}
return ch;
}
#endif
/*--------------------------- _ttywrch ---------------------------------------*/
void _ttywrch (int ch)
{
#ifdef STDIO
sendchar (ch);
#endif
}
/*--------------------------- _sys_open --------------------------------------*/
#ifndef NO_FILESYSTEM
static int KEIL_FS_open(const char *name, int openmode)
{
int i ; int ret ;
#define PATHSIZE 100
char path[PATHSIZE] ; char *p ;
if(strlen(name) > PATHSIZE)return(-1) ;
for(i = 0; i<= strlen(name); i++) {
if(name[i] == '/')path[i] = '\\' ;
else path[i] = name[i] ;
}
if(path[0] == '.' && path[1] == '\\') p = path + 2 ;
else p = path ;
ret = __sys_open (p, openmode) ;
return(ret) ;
}
#endif
FILEHANDLE _sys_open (const char *name, int openmode)
{
/* Register standard Input Output devices. */
if (strcmp(name, "STDIN") == 0) {
return (STDIN);
}
if (strcmp(name, "STDOUT") == 0) {
return (STDOUT);
}
if (strcmp(name, "STDERR") == 0) {
return (STDERR);
}
#ifndef NO_FILESYSTEM
return (KEIL_FS_open(name, openmode));
#else
return(0) ;
#endif
}
/*--------------------------- _sys_close -------------------------------------*/
int _sys_close (FILEHANDLE fh)
{
if (fh > 0x8000) {
return (0);
}
#ifndef NO_FILESYSTEM
return (__sys_close (fh));
#else
return(0) ;
#endif
}
/*--------------------------- _sys_write -------------------------------------*/
int _sys_write (FILEHANDLE fh, const U8 *buf, U32 len, int mode)
{
#ifdef STDIO
if (fh == STDOUT) {
/* Standard Output device. */
for ( ; len; len--) {
sendchar (*buf++);
}
return (0);
}
#endif
if (fh > 0x8000) {
return (-1);
}
#ifndef NO_FILESYSTEM
return (__sys_write (fh, buf, len));
#else
return(0) ;
#endif
}
/*--------------------------- _sys_read --------------------------------------*/
int _sys_read (FILEHANDLE fh, U8 *buf, U32 len, int mode)
{
#ifdef STDIO
if (fh == STDIN) {
/* Standard Input device. */
int sz ;
while((buf[0] = getkey()) == 0) ;
;
for (sz = 0 ; sz <= len ; sz ++ ) {
if(buf[sz] == 0) break ;
else sz++ ;
buf[sz] = getkey ();
}
return (sz);
}
#endif
if (fh > 0x8000) {
return (-1);
}
#ifndef NO_FILESYSTEM
return (__sys_read (fh, buf, len));
#else
return(0) ;
#endif
}
/*--------------------------- _sys_istty -------------------------------------*/
int _sys_istty (FILEHANDLE fh)
{
if (fh > 0x8000) {
return (1);
}
return (0);
}
/*--------------------------- _sys_seek --------------------------------------*/
int _sys_seek (FILEHANDLE fh, long pos)
{
if (fh > 0x8000) {
return (-1);
}
#ifndef NO_FILESYSTEM
return (__sys_seek (fh, pos));
#else
return(0) ;
#endif
}
/*--------------------------- _sys_ensure ------------------------------------*/
int _sys_ensure (FILEHANDLE fh)
{
if (fh > 0x8000) {
return (-1);
}
#ifndef NO_FILESYSTEM
return (__sys_ensure (fh));
#else
return(0) ;
#endif
}
/*--------------------------- _sys_flen --------------------------------------*/
long _sys_flen (FILEHANDLE fh)
{
if (fh > 0x8000) {
return (0);
}
#ifndef NO_FILESYSTEM
return (__sys_flen (fh));
#else
return(0) ;
#endif
}
/*--------------------------- _sys_tmpnam ------------------------------------*/
int _sys_tmpnam (char *name, int sig, unsigned maxlen)
{
return (1);
}
/*--------------------------- _sys_command_string ----------------------------*/
char *_sys_command_string (char *cmd, int len)
{
return (cmd);
}
/*--------------------------- _sys_exit --------------------------------------*/
void _sys_exit (int return_code)
{
#ifdef CYASSL_MDK_SHELL
return ;
#else
/* Endless loop. */
while (1);
#endif
}
/*--------------------------- time -----------------------------------------*/
long time(long *t)
{
return ((long) 0) ; /** DUMMY TIME() **/
}
/*-----------------------------------------------------------------------------
* end of file
*----------------------------------------------------------------------------*/

View File

@ -0,0 +1,28 @@
/* certs_test.c
*
* Copyright (C) 2006-2013 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/* Define initial data for cert buffers */
#include <cyassl/certs_test.h>

View File

@ -0,0 +1,39 @@
#ifndef CYASSL_CERT_DATA_H
#define CYASSL_CERT_DATA_H
#ifdef USE_CERT_BUFFERS_1024
extern const unsigned char client_key_der_1024[] ;
extern int sizeof_client_key_der_1024 ;
/* ./certs/1024/client-cert.der, 1024-bit */
extern const unsigned char client_cert_der_1024[] ;
extern int sizeof_client_cert_der_1024 ;
/* ./certs/1024/dh1024.der, 1024-bit */
extern const unsigned char dh_key_der_1024[] ;
extern int sizeof_dh_key_der_1024 ;
/* ./certs/1024/dsa1024.der, 1024-bit */
extern const unsigned char dsa_key_der_1024[] ;
extern int sizeof_dsa_key_der_1024 ;
/* ./certs/1024/rsa1024.der, 1024-bit */
extern const unsigned char rsa_key_der_1024[] ;
extern int sizeof_rsa_key_der_1024 ;
#elif defined(USE_CERT_BUFFERS_2048)
/* ./certs/client-key.der, 2048-bit */
extern const unsigned char client_key_der_2048[] ;
extern int sizeof_client_key_der_2048 ;
/* ./certs/client-cert.der, 2048-bit */
extern const unsigned char client_cert_der_2048[] ;
extern int sizeof_client_cert_der_2048 ;
/* ./certs/dh2048.der, 2048-bit */
extern const unsigned char dh_key_der_2048[] ;
extern int sizeof_dh_key_der_2048 ;
/* ./certs/dsa2048.der, 2048-bit */
extern const unsigned char dsa_key_der_2048[] ;
extern int sizeof_dsa_key_der_2048;
/* ./certs/rsa2048.der, 2048-bit */
extern const unsigned char rsa_key_der_2048[] ;
extern int sizeof_rsa_key_der_2048 ;
#endif
#endif

View File

@ -0,0 +1,235 @@
/* cyassl_KEIL_RL.c
*
* Copyright (C) 2006-2013 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/***************************************************************************************/
/** This file is for defining functions for specific to KEIL-RL. **/
/***************************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <rtl.h>
#include "cyassl_MDK_ARM.h"
#include <cyassl/ctaocrypt/visibility.h>
#include <cyassl/ctaocrypt/logging.h>
/** KEIL-RL TCPnet ****/
/** TCPnet BSD socket does not have following functions. **/
char *inet_ntoa(struct in_addr in)
{
#define NAMESIZE 16
static char name[NAMESIZE] ;
sprintf(name, "%d.%d.%d.%d", (in.s_addr>>24)&0xff, (in.s_addr>>16)&0xff, (in.s_addr>>8)&0xff, in.s_addr&0xff) ;
return name ;
}
unsigned long inet_addr(const char *cp)
{
unsigned int a[4] ; unsigned long ret ;
sscanf(cp, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]) ;
ret = ((a[3]<<24) + (a[2]<<16) + (a[1]<<8) + a[0]) ;
return(ret) ;
}
/*** tcp_connect is actually associated with following syassl_tcp_connect. ***/
int Cyassl_connect(int sd, const struct sockaddr* sa, int sz)
{
int ret ;
#if defined(CYASSL_KEIL_TCP_NET)
SOCKADDR_IN addr ;
addr = *(SOCKADDR_IN *)sa ;
do {
#undef connect /* Go to KEIL TCPnet connect */
ret = connect(sd, (SOCKADDR *)&addr, sizeof(addr)) ;
os_dly_wait(50);
} while(ret == SCK_EWOULDBLOCK) ;
#ifdef DEBUG_CYASSL
{
char msg[50] ;
sprintf(msg, "BSD Connect return code: %d\n", ret) ;
CYASSL_MSG(msg) ;
}
#endif
#endif /* CYASSL_KEIL_TCP_NET */
return(ret ) ;
}
int Cyassl_accept(int sd, struct sockaddr *addr, int *addrlen)
{
int ret ;
#if defined(CYASSL_KEIL_TCP_NET)
while(1) {
#undef accept /* Go to KEIL TCPnet accept */
ret = accept(sd, addr, addrlen) ;
if(ret != SCK_EWOULDBLOCK) break ;
os_dly_wait(1);
}
#ifdef DEBUG_CYASSL
{
char msg[50] ;
sprintf(msg, "BSD Accept return code: %d\n", ret) ;
CYASSL_MSG(msg) ;
}
#endif
#endif /* CYASSL_KEIL_TCP_NET */
return(ret ) ;
}
int Cyassl_recv(int sd, void *buf, size_t len, int flags)
{
int ret ;
#if defined(CYASSL_KEIL_TCP_NET)
while(1) {
#undef recv /* Go to KEIL TCPnet recv */
ret = recv(sd, buf, len, flags) ;
if(ret != SCK_EWOULDBLOCK) break ;
os_dly_wait(1);
}
#ifdef DEBUG_CYASSL
{
char msg[50] ;
sprintf(msg, "BSD Recv return code: %d\n", ret) ;
CYASSL_MSG(msg) ;
}
#endif
#endif /* CYASSL_KEIL_TCP_NET */
return(ret ) ;
}
int Cyassl_send(int sd, const void *buf, size_t len, int flags)
{
int ret ;
#if defined(CYASSL_KEIL_TCP_NET)
while(1) {
#undef send /* Go to KEIL TCPnet send */
ret = send(sd, buf, len, flags) ;
if(ret != SCK_EWOULDBLOCK) break ;
os_dly_wait(1);
}
#ifdef DEBUG_CYASSL
{
char msg[50] ;
sprintf(msg, "BSD Send return code: %d\n", ret) ;
CYASSL_MSG(msg) ;
}
#endif
#endif /* CYASSL_KEIL_TCP_NET */
return(ret) ;
}
#if defined(CYASSL_KEIL_TCP_NET)
void Cyassl_sleep(int t)
{
#if defined(HAVE_KEIL_RTX)
os_dly_wait(t/1000+1) ;
#endif
}
int Cyassl_tcp_select(int sd, int timeout)
{
return 0 ;
}
#endif
struct tm *Cyassl_MDK_gmtime(const time_t *c)
{
RTC_TimeTypeDef RTC_Time ;
RTC_DateTypeDef RTC_Date ;
static struct tm date ;
RTC_GetTime(RTC_Format_BIN, &RTC_Time) ;
RTC_GetDate(RTC_Format_BIN, &RTC_Date) ;
date.tm_year = RTC_Date.RTC_Year + 100 ;
date.tm_mon = RTC_Date.RTC_Month - 1 ;
date.tm_mday = RTC_Date.RTC_Date ;
date.tm_hour = RTC_Time.RTC_Hours ;
date.tm_min = RTC_Time.RTC_Minutes ;
date.tm_sec = RTC_Time.RTC_Seconds ;
#if defined(DEBUG_CYASSL)
{
char msg[100] ;
sprintf(msg, "Debug::Cyassl_KEIL_gmtime(DATE=/%4d/%02d/%02d TIME=%02d:%02d:%02d)\n",
RTC_Date.RTC_Year+2000, RTC_Date.RTC_Month, RTC_Date.RTC_Date,
RTC_Time.RTC_Hours, RTC_Time.RTC_Minutes, RTC_Time.RTC_Seconds) ;
CYASSL_MSG(msg) ;
}
#endif
return(&date) ;
}
double current_time()
{
return ((double)TIM2->CNT/1000000.0) ;
}
extern int getkey(void) ;
extern int sendchar(int c) ;
char * Cyassl_fgets ( char * str, int num, FILE * f )
{
int i ;
for(i = 0 ; i< num ; i++) {
while((str[i] = getkey()) == 0) ;
if(str[i] == '\n' || str[i] == '\012' || str[i] == '\015') {
sendchar('\n') ;
str[i++] = '\n' ;
str[i] = '\0' ;
break ;
} else if(str[i] == '\010') { /* BS */
if(i) { /* erace one char */
sendchar('\010') ; sendchar(' ') ; sendchar('\010') ;
i = (i>0 ? (i-2) : -1 ) ;
continue ;
}
} else if(str[i] == '\033' || str[i] == '\004' ) { /* ESC or ^D */
str[i] = '\0' ;
return(0) ;
}
sendchar(str[i]) ;
}
return(str) ;
}

View File

@ -0,0 +1,110 @@
/* cyassl_KEIL_RL.h
*
* Copyright (C) 2006-2013 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/******************************************************************************/
/** This file is for defining types, values for specific to KEIL-MDK-ARM. **/
/******************************************************************************/
#ifndef CYASSL_KEIL_RL_H
#define CYASSL_KEIL_RL_H
#include <stdio.h>
/* Go to STDIN */
#define fgets(buff, sz, fd) Cyassl_fgets(buff, sz, fd)
extern char * Cyassl_fgets ( char * str, int num, FILE * f ) ;
#define SOCKET_T int
/*** #include <socket.h> ***/
#define NUMBITSPERBYTE 8
#define FD_SETSIZE 10
typedef long fd_mask;
#define NFDBITS (sizeof(fd_mask) * NUMBITSPERBYTE) /* bits per mask */
typedef struct fd_set {
fd_mask fds_bits[(FD_SETSIZE + NFDBITS - 1) / NFDBITS];
} fd_set;
/*** #include <sys/types.h> ***/
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* microseconds */
};
/*** #include <unistd.h> **/
/*
int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const struct timeval *timeout);
void FD_CLR(int fd, fd_set *set);
int FD_ISSET(int fd, fd_set *set);
void FD_SET(int fd, fd_set *set);
void FD_ZERO(fd_set *set);
*/
typedef int socklen_t ;
/* for avoiding conflict with KEIL-TCPnet BSD socket */
/* Bodies are in cyassl_KEIL_RL.c */
#define connect Cyassl_connect
#define accept Cyassl_accept
#define recv Cyassl_recv
#define send Cyassl_send
#define sleep Cyassl_sleep
/* for avoiding conflicting with KEIL-TCPnet TCP socket */
/* Bodies are in test.h */
#define tcp_connect Cyassl_tcp_connect
#define tcp_socket Cyassl_tcp_soket
#define tcp_listen Cyassl_tcp_listen
#define tcp_select Cyassl_tcp_select
extern int Cyassl_connect(int sd, const struct sockaddr * sa, int sz) ;
extern int Cyassl_accept(int sd, struct sockaddr *addr, socklen_t *addrlen);
extern int Cyassl_recv(int sd, void *buf, size_t len, int flags);
extern int Cyassl_send(int sd, const void *buf, size_t len, int flags);
extern void Cyassl_sleep(int sec) ;
extern int Cyassl_tcp_socket(SOCKET_T* sockfd, int udp) ;
extern void Cyassl_tcp_listen(SOCKET_T* sockfd, int port,
int useAnyAddr, int udp) ;
extern int Cyassl_tcp_select(int sd, int timeout) ;
/** KEIL-RL TCPnet ****/
/* TCPnet BSD socket does not have following functions. */
extern char *inet_ntoa(struct in_addr in);
extern unsigned long inet_addr(const char *cp);
extern int setsockopt(int sockfd, int level, int optname,
const void *optval, socklen_t optlen);
extern int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const struct timeval *timeout);
/** KEIL-RL gmtime ****/
#include <time.h>
#include "stm32f2xx_rtc.h"
extern struct tm *gmtime(const time_t *timer);
extern struct tm *Cyassl_MDK_gmtime(const time_t *timer);
extern double current_time(void) ;
#endif /* CYASSL_KEIL_RL_H */

View File

@ -0,0 +1,244 @@
/* main.c
*
* Copyright (C) 2006-2013 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <cyassl/ctaocrypt/visibility.h>
#include <cyassl/ctaocrypt/logging.h>
#include <RTL.h>
#include <stdio.h>
#include "cyassl_MDK_ARM.h"
#include "stm32f2xx_tim.h"
#include "stm32f2xx_rcc.h"
/*-----------------------------------------------------------------------------
* Initialize a Flash Memory Card
*----------------------------------------------------------------------------*/
#if !defined(NO_FILESYSTEM)
static void init_card (void)
{
U32 retv;
while ((retv = finit (NULL)) != 0) { /* Wait until the Card is ready */
if (retv == 1) {
printf ("\nSD/MMC Init Failed");
printf ("\nInsert Memory card and press key...\n");
} else {
printf ("\nSD/MMC Card is Unformatted");
}
}
}
#endif
/*-----------------------------------------------------------------------------
* TCP/IP tasks
*----------------------------------------------------------------------------*/
#ifdef CYASSL_KEIL_TCP_NET
__task void tcp_tick (void)
{
CYASSL_MSG("Time tick started.") ;
#if defined (HAVE_KEIL_RTX)
os_itv_set (10);
#endif
while (1) {
#if defined (HAVE_KEIL_RTX)
os_itv_wait ();
#endif
/* Timer tick every 100 ms */
timer_tick ();
}
}
__task void tcp_poll (void)
{
CYASSL_MSG("TCP polling started.\n") ;
while (1) {
main_TcpNet ();
#if defined (HAVE_KEIL_RTX)
os_tsk_pass ();
#endif
}
}
#endif
/*-----------------------------------------------------------------------------
* initialize RTC
*----------------------------------------------------------------------------*/
#include "stm32f2xx_rtc.h"
#include "stm32f2xx_rcc.h"
#include "stm32f2xx_pwr.h"
static init_RTC()
{
RTC_InitTypeDef RTC_InitStruct ;
RTC_TimeTypeDef RTC_Time ;
RTC_DateTypeDef RTC_Date ;
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
/***Configures the External Low Speed oscillator (LSE)****/
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Calendar Configuration with LSI supposed at 32KHz */
RTC_InitStruct.RTC_AsynchPrediv = 0x7F;
RTC_InitStruct.RTC_SynchPrediv = 0xFF;
RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStruct);
RTC_GetTime(RTC_Format_BIN, &RTC_Time) ;
RTC_GetDate(RTC_Format_BIN, &RTC_Date) ;
}
/*-----------------------------------------------------------------------------
* initialize TIM
*----------------------------------------------------------------------------*/
void init_timer()
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure ;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE) ;
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Prescaler = 60;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 0xffffffff;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure) ;
TIM_Cmd(TIM2, ENABLE) ;
}
#if defined(HAVE_KEIL_RTX) && defined(CYASSL_MDK_SHELL)
#define SHELL_STACKSIZE 1000
static unsigned char Shell_stack[SHELL_STACKSIZE] ;
#endif
#if defined(CYASSL_MDK_SHELL)
extern void shell_main(void) ;
#endif
extern void time_main(int) ;
extern void benchmark_test(void) ;
extern void SER_Init(void) ;
/*-----------------------------------------------------------------------------
* mian entry
*----------------------------------------------------------------------------*/
/*** This is the parent task entry ***/
void main_task (void)
{
#ifdef CYASSL_KEIL_TCP_NET
init_TcpNet ();
os_tsk_create (tcp_tick, 2);
os_tsk_create (tcp_poll, 1);
#endif
#ifdef CYASSL_MDK_SHELL
#ifdef HAVE_KEIL_RTX
os_tsk_create_user(shell_main, 1, Shell_stack, SHELL_STACKSIZE) ;
#else
shell_main() ;
#endif
#else
/************************************/
/*** USER APPLICATION HERE ***/
/************************************/
#endif
#ifdef HAVE_KEIL_RTX
CYASSL_MSG("Terminating tcp_main\n") ;
os_tsk_delete_self ();
#endif
}
int myoptind = 0;
char* myoptarg = NULL;
#if defined(DEBUG_CYASSL)
extern void CyaSSL_Debugging_ON(void) ;
#endif
/*** main entry ***/
int main() {
/* stm32_Init (); STM32 setup */
#if !defined(NO_FILESYSTEM)
init_card () ; /* initializing SD card */
#endif
init_RTC() ;
init_timer() ;
SER_Init() ;
#if defined(DEBUG_CYASSL)
printf("Turning ON Debug message\n") ;
CyaSSL_Debugging_ON() ;
#endif
#ifdef HAVE_KEIL_RTX
os_sys_init (main_task) ;
#else
main_task() ;
#endif
return 0 ; /* There should be no return here */
}

View File

@ -0,0 +1,628 @@
/*shell.c
*
* Copyright (C) 2006-2013 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/*** tiny Shell for CyaSSL apps ***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "cyassl/internal.h"
#undef RNG
#include <cyassl/ctaocrypt/logging.h>
#if defined(CYASSL_MDK_ARM)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <rtl.h>
#include "cyassl_MDK_ARM.h"
#endif
#ifdef CYASSL_KEIL_NET
#include "cyassl/test.h"
#else
typedef struct func_args {
int argc;
char** argv;
int return_code;
} func_args;
#endif
#ifdef NO_ECHOCLIENT
#define echoclient_test command_not_found
#endif
#ifdef NO_ECHOSERVER
#define echoserver_test command_not_found
#endif
#ifdef NO_SIMPLE_CLIENT
#define client_test command_not_found
#endif
#ifdef NO_SIMPLE_SERVER
#define server_test command_not_found
#endif
#ifdef NO_CRYPT_BENCHMARK
#define benchmark_test command_not_found
#endif
#ifdef NO_CRYPT_TEST
#define ctaocrypt_test command_not_found
#endif
#ifndef CYASSL_KEIL_NET
#define ipaddr_comm command_not_found
#endif
#if !defined(HAVE_KEIL_RTX)
#define stack_comm command_not_found
#endif
#if !defined(DEBUG_CYASSL)
#define dbg_comm command_not_found
#endif
void command_not_found(void *argv) {
printf("Command not found\n") ;
}
extern void echoclient_test(void *args) ;
extern void echoserver_test(void *args) ;
extern void benchmark_test(void *args) ;
extern void ctaocrypt_test(void *args) ;
extern void client_test(void *args) ;
extern void server_test(void *args) ;
extern void kill_task(void *args) ;
extern void time_main(void *args) ;
extern void ipaddr_comm(void *args) ;
extern void stack_comm(void *args) ;
extern void for_command(void *args) ;
extern void dbg_comm(void *arg) ;
extern void help_comm(void *arg) ;
#if !defined(NO_CRYPT_TEST)
#ifndef NO_MD5
extern void md5_test(void *arg) ;
#endif
#ifdef CYASSL_MD2
extern void md2_test(void *arg) ;
#endif
#ifndef NO_MD4
extern void md4_test(void *arg) ;
#endif
extern void sha_test(void *arg) ;
#ifndef NO_SHA256
extern void sha256_test(void *arg) ;
#endif
#ifdef CYASSL_SHA384
extern void sha384_test(void *arg) ;
#endif
#ifdef CYASSL_SHA512
extern void sha512_test(void *arg) ;
#endif
#ifdef CYASSL_RIPEMD
extern void ripemd_test(void *arg) ;
#endif
#ifndef NO_HMAC
#ifndef NO_MD5
extern void hmac_md5_test(void *arg) ;
#endif
extern void hmac_sha_test(void *arg) ;
#ifndef NO_SHA256
extern void hmac_sha256_test(void *arg) ;
#endif
#ifdef CYASSL_SHA384
extern void hmac_sha384_test(void *arg) ;
#endif
#endif
#ifndef NO_RC4
extern void arc4_test(void *arg) ;
#endif
#ifndef NO_HC128
extern void hc128_test(void *arg) ;
#endif
#ifndef NO_RABBIT
extern void rabbit_test(void *arg) ;
#endif
#ifndef NO_DES3
extern void des_test(void *arg) ;
extern void des3_test(void *arg) ;
#endif
#ifndef NO_AES
extern void aes_test(void *arg) ;
#ifdef HAVE_AESGCM
extern void aesgcm_test(void *arg) ;
#endif
#ifdef HAVE_AESCCM
extern void aesccm_test(void *arg) ;
#endif
#endif
#ifdef HAVE_CAMELLIA
extern void camellia_test(void *arg) ;
#endif
extern void random_test(void *arg) ;
#ifndef NO_RSA
extern void rsa_test(void *arg) ;
#endif
#ifndef NO_DH
extern void dh_test(void *arg) ;
#endif
#ifndef NO_DSA
extern void dsa_test(void *arg) ;
#endif
#ifndef NO_PWDBASED
extern void pwdbased_test(void *arg) ;
#endif
#ifdef HAVE_ECC
extern void openssl_test(void *arg) ;
#endif
#ifdef HAVE_ECC
extern void ecc_test(void *arg) ;
#endif
#endif /* NO_CRYPT_TEST */
static struct {
const char *command ;
void (*func)(void *args) ;
} commandTable[] = {
"echoclient", echoclient_test,
"echoserver", echoserver_test,
"benchmark", benchmark_test,
"test", ctaocrypt_test,
"client", client_test,
"server", server_test,
"time", time_main, /* get/set RTC: [-d yy/mm/dd] [-t hh:mm:ss]*/
"ipaddr", ipaddr_comm, /* TBD */
"stack", stack_comm, /* On/Off check stack size */
"for", for_command, /* iterate next command X times */
"debug", dbg_comm, /* On/Off debug message */
"help", help_comm, /* Breif description about the commands */
/** short name **/
"ec", echoclient_test,
"es", echoserver_test,
"bm", benchmark_test,
"te", ctaocrypt_test,
"cl", client_test,
"sv", server_test,
"ip", ipaddr_comm,
"st", stack_comm,
"dbg", dbg_comm,
"?", help_comm,
/*** test suites ****/
#if !defined(NO_CRYPT_TEST)
#ifndef NO_MD5
"md5", md5_test,
#endif
#ifdef CYASSL_MD2
"md2", md2_test,
#endif
#ifndef NO_MD4
"md4", md4_test,
#endif
"sha", sha_test,
#ifndef NO_SHA256
"sha256", sha256_test,
#endif
#ifdef CYASSL_SHA384
"sha384", sha384_test,
#endif
#ifdef CYASSL_SHA512
"sha512", sha512_test,
#endif
#ifdef CYASSL_RIPEMD
"ripemd", ripemd_test,
#endif
#ifndef NO_HMAC
#ifndef NO_MD5
"hmac_md5", hmac_md5_test,
#endif
"hmac_sha", hmac_sha_test,
#ifndef NO_SHA256
"hmac_sha256", hmac_sha256_test,
#endif
#ifdef CYASSL_SHA384
"hmac_sha384", hmac_sha384_test,
#endif
#endif
#ifndef NO_RC4
"arc4", arc4_test,
#endif
#ifndef NO_HC128
"hc128", hc128_test,
#endif
#ifndef NO_RABBIT
"rabbit", rabbit_test,
#endif
#ifndef NO_DES3
"des", des_test,
"des3", des3_test,
#endif
#ifndef NO_AES
"aes", aes_test,
#ifdef HAVE_AESGCM
"aesgcm", aesgcm_test,
#endif
#ifdef HAVE_AESCCM
"aesccm", aesccm_test,
#endif
#endif
#ifdef HAVE_CAMELLIA
"camellia", camellia_test,
#endif
"random", random_test,
#ifndef NO_RSA
"rsa", rsa_test,
#endif
#ifndef NO_DH
"dh", dh_test,
#endif
#ifndef NO_DSA
"dsa", dsa_test,
#endif
#ifndef NO_PWDBASED
"pwdbased", pwdbased_test,
#endif
#ifdef OPENSSL_EXTRA
"openssl", openssl_test,
#endif
#ifdef HAVE_ECC
"ecc", ecc_test,
#endif
#endif /* NO_CRYPT_TEST */
"", NULL
} ;
enum jobtype { FORGROUND, BACKGROUND } ;
#define IF_DELIMITER(ch) ((ch) == ' ' || (ch) == '\n')
/******* Get Command Line *****************************/
static int getline(char * line, int sz, func_args *args, int*bf_flg)
{
char * ret ;
int i ;
#define MAXARGS 10
#define MAXARGLEN 30
static char *argv[MAXARGS] ;
args->argv = argv ;
putchar('>') ;
fflush(stdout) ;
ret = fgets(line, sz, stdin) ;
#define SHELL_ERROR_FGETS -102
if(ret != line) return(SHELL_ERROR_FGETS) ;
if(line[strlen(line)-2] == '&') {
(*bf_flg) = BACKGROUND ;
line[strlen(line)-2] = '\n' ;
} else {
(*bf_flg) = FORGROUND ;
}
args->argc = 0 ;
for(i=0; i<sz; i++) {
args->argv[args->argc] = &(line[i]) ;
while(!IF_DELIMITER(line[i])) i++ ;
args->argc++ ;
if(line[i] == '\n') {
line[i] = '\0' ;
break ;
} else {
line[i] = '\0' ;
}
}
return i ;
}
static int BackGround = 0 ; /* 1: background job is running */
/************* Embedded Shell Commands **********************************/
#define IP_SIZE 16
#ifdef CYASSL_KEIL_NET
static void ipaddr_comm(void *args)
{
if(((func_args *)args)->argc == 1) {
printf("IP addr: %s, port %d\n", yasslIP, yasslPort) ;
} else {
if(BackGround != 0) {
printf("Cannot change IP addr while background server is running\n") ;
} else if(((func_args *)args)->argc == 3 &&
((func_args *)args)->argv[1][0] == '-'&&
((func_args *)args)->argv[1][1] == 'a' ) {
/* strcpy(yasslIP, ((func_args *)args)->argv[2]) ; */
} else if(((func_args *)args)->argc == 3 &&
((func_args *)args)->argv[1][0] == '-' &&
((func_args *)args)->argv[1][1] == 'p' ) {
/* yasslPort = atoi(((func_args *)args)->argv[2]) ; */
} else printf("Invalid argument\n") ;
}
}
#endif
static void time_main(void *args)
{
char * datetime ;
RTC_TimeTypeDef RTC_Time ;
RTC_DateTypeDef RTC_Date ;
int year ;
if( args == NULL || ((func_args *)args)->argc == 1) {
RTC_GetTime(RTC_Format_BIN, &RTC_Time) ;
RTC_GetDate(RTC_Format_BIN, &RTC_Date) ;
printf("Date: %d/%d/%d, Time: %02d:%02d:%02d\n",
RTC_Date.RTC_Month, RTC_Date.RTC_Date, RTC_Date.RTC_Year+2000,
RTC_Time.RTC_Hours, RTC_Time.RTC_Minutes, RTC_Time.RTC_Seconds) ;
} else if(((func_args *)args)->argc == 3 &&
((func_args *)args)->argv[1][0] == '-' &&
((func_args *)args)->argv[1][1] == 'd' ) {
datetime = ((func_args *)args)->argv[2];
sscanf(datetime, "%d/%d/%d",
(int *)&RTC_Date.RTC_Month, (int *)&RTC_Date.RTC_Date, &year) ;
RTC_Date.RTC_Year = year - 2000 ;
RTC_Date.RTC_WeekDay = 0 ;
RTC_SetDate(RTC_Format_BIN, &RTC_Date) ;
} else if(((func_args *)args)->argc == 3 &&
((func_args *)args)->argv[1][0] == '-' &&
((func_args *)args)->argv[1][1] == 't' ) {
datetime = ((func_args *)args)->argv[2];
sscanf(datetime, "%d:%d:%d",
(int *)&RTC_Time.RTC_Hours,
(int *)&RTC_Time.RTC_Minutes,
(int *)&RTC_Time.RTC_Seconds
) ;
RTC_SetTime(RTC_Format_BIN, &RTC_Time) ;
} else printf("Invalid argument\n") ;
}
#if defined(HAVE_KEIL_RTX)
static int stack_ck = 0 ;
static void stack_comm(void *args)
{
if(stack_ck) {
printf("Stack Check: Off\n") ;
stack_ck = 0 ;
} else {
printf("Stack Check: On\n") ;
stack_ck = 1 ;
}
}
#define FILL_PATTERN 0xa596695a
void stack_fill(char * stack, int size)
{
int i ;
if(stack_ck == 0)return ;
for(i=1; i<size/4-10; i++)
((int *)stack)[i] = FILL_PATTERN ;
}
void stack_check(char * stack, int size)
{
int i ;
if(stack_ck == 0)return ;
if(stack_ck == 1) {
stack_ck ++ ; return ;
}
for(i=1; i<size/4 ; i++) {
if(((int *)stack)[i] != FILL_PATTERN) break ;
}
if(i < size/4) {
printf("Stack is used %d bytes out of %d\n", size - i*4, size) ;
} else {
printf("Stack overflow. Stack size: %d\n", size) ;
}
}
#endif /* HAVE_KEIL_RTX */
static int for_iteration = 1 ;
static void for_command(void *args)
{
if( args == NULL || ((func_args *)args)->argc == 1) {
printf("For %d times\n", for_iteration) ;
} else if( args == NULL || ((func_args *)args)->argc == 2) {
for_iteration = atoi(((func_args *)args)->argv[1]) ;
} else printf("Invalid argument\n") ;
}
#if defined(DEBUG_CYASSL)
static int CyasslDebug = 1 ;
static void dbg_comm(void *args)
{
if(CyasslDebug == 1) {
CyasslDebug = 0 ;
printf("Turning OFF Debug message\n") ;
CyaSSL_Debugging_OFF() ;
} else {
CyasslDebug = 1 ;
printf("Turning ON Debug message\n") ;
CyaSSL_Debugging_ON() ;
}
}
#endif
static void help_comm(void *args)
{
}
#define BG_JOB_STACK_SIZE 12000
#if (!defined(NO_SIMPLE_SERVER) && !defined(NO_ECHOSERVER)) && \
defined(HAVE_KEIL_RTX)
static char bg_job_stack[BG_JOB_STACK_SIZE] ;
#endif
#define COMMAND_STACK_SIZE 12000
#if defined(HAVE_KEIL_RTX)
static char command_stack[COMMAND_STACK_SIZE] ;
#endif
#ifdef HAVE_KEIL_RTX
static CyaSSL_Mutex command_mutex ;
#endif
/*********** Invoke Forground Command *********************/
static void command_invoke(void *args)
{
void (*func)(void * ) ;
int i,iteration ;
func = (void(*)(void *))((func_args *)args)->argv[0] ;
#ifdef HAVE_KEIL_RTX
LockMutex((CyaSSL_Mutex *)&command_mutex) ;
#endif
iteration = for_iteration ;
for(i=0; i< iteration; i++) {
if(iteration > 1) printf("--- Start for %d ---->\n", i) ;
#if defined(HAVE_KEIL_RTX)
stack_fill(command_stack, COMMAND_STACK_SIZE) ;
#endif
func(args) ; /* invoke command */
#if defined(HAVE_KEIL_RTX)
stack_check(command_stack, COMMAND_STACK_SIZE) ;
#endif
}
if(iteration > 1)
for_iteration = 1 ;
#ifdef HAVE_KEIL_RTX
UnLockMutex((CyaSSL_Mutex *)&command_mutex) ;
os_tsk_delete_self() ;
#endif
}
#if (!defined(NO_SIMPLE_SERVER) && !defined(NO_ECHOSERVER)) && \
defined(HAVE_KEIL_RTX)
/******* Invoke Background Job *******************************/
static void bg_job_invoke(void *args)
{
void (*func)(void * ) ;
BackGround = 1 ;
stack_fill(bg_job_stack, BG_JOB_STACK_SIZE) ;
func = (void(*)(void *))((func_args *)args)->argv[0] ;
func(args) ; /* invoke command */
stack_check(bg_job_stack, BG_JOB_STACK_SIZE) ;
#ifdef CYASSL_KEIL_NET
init_TcpNet ();
#endif
BackGround = 0 ;
os_tsk_delete_self() ; ;
}
#endif
#define LINESIZE 100
static char line[LINESIZE] ;
/********* SHEULL MAIN LOOP ***********************************/
void shell_main(void) {
int i ;
func_args args ;
int bf_flg ;
i = BackGround ;
/* Dummy for avoiding warning: BackGround is defined but not used. */
#if defined(HAVE_KEIL_RTX)
InitMutex(&command_mutex) ;
#endif
time_main(NULL) ;
printf("Starting Shell\n") ;
while(1) {
if(getline(line, LINESIZE, &args, &bf_flg) > 0) {
for(i=0; commandTable[i].func != NULL; i++) {
if(strcmp(commandTable[i].command, args.argv[0]) == 0) {
args.argv[0] = (char *) commandTable[i].func ;
if(bf_flg == FORGROUND) {
#ifdef HAVE_KEIL_RTX
UnLockMutex((CyaSSL_Mutex *)&command_mutex) ;
os_tsk_create_user_ex( (void(*)(void *))&command_invoke, 7,
command_stack, COMMAND_STACK_SIZE, &args) ;
#else
command_invoke(&args) ;
#endif
#ifdef HAVE_KEIL_RTX
LockMutex((CyaSSL_Mutex *)&command_mutex) ;
#endif
} else {
#if (!defined(NO_SIMPLE_SERVER) && \
!defined(NO_ECHOSERVER)) && \
defined(HAVE_KEIL_RTX)
if(BackGround != 0) {
printf("Multiple background servers not supported.\n") ;
} else {
printf("\"%s\" is running with the background mode.\n",
commandTable[i].command) ;
os_tsk_create_user_ex( (void(*)(void *))&bg_job_invoke,
6, bg_job_stack, BG_JOB_STACK_SIZE, &args) ;
}
#else
printf("Invalid Command: no background job\n") ;
#endif
}
break ;
}
}
if(commandTable[i].func == NULL)
printf("Command not found\n") ;
}
}
}

View File

@ -0,0 +1,48 @@
/* ssl-dummy.c
*
* Copyright (C) 2006-2013 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <cyassl/ssl.h>
#include <cyassl/internal.h>
#include <cyassl/error.h>
#include <cyassl/ctaocrypt/coding.h>
Signer* GetCA(void* vp, byte* hash)
{
Signer*s ;
return s ;
}
int CyaSSL_dtls(CYASSL* ssl)
{
return ssl->options.dtls;
}
int CyaSSL_get_using_nonblock(CYASSL* ssl)
{
CYASSL_ENTER("CyaSSL_get_using_nonblock");
CYASSL_LEAVE("CyaSSL_get_using_nonblock", ssl->options.usingNonblock);
return ssl->options.usingNonblock;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -53,7 +53,12 @@
#endif
#if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048)
/* include test cert and key buffers for use with NO_FILESYSTEM */
#include <cyassl/certs_test.h>
#if defined(CYASSL_MDK_ARM)
#include "cert_data.h" /* use certs_test.c for initial data,
so other commands can share the data. */
#else
#include <cyassl/certs_test.h>
#endif
#endif
@ -118,13 +123,19 @@ static int OpenNitroxDevice(int dma_mode,int dev_id)
/* so embedded projects can pull in tests on their own */
#ifndef NO_MAIN_DRIVER
#if !defined(NO_MAIN_DRIVER)
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
#ifdef HAVE_CAVIUM
#else
int benchmark_test(void *args)
{
#endif
#ifdef HAVE_CAVIUM
int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
if (ret != 0) {
printf("Cavium OpenNitroxDevice failed\n");
@ -200,7 +211,6 @@ int main(int argc, char** argv)
return 0;
}
#endif /* NO_MAIN_DRIVER */
#ifdef BENCH_EMBEDDED
const int numBlocks = 25; /* how many kB/megs to test (en/de)cryption */
@ -659,6 +669,19 @@ RNG rng;
#endif
#ifndef NO_RSA
#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
defined(CYASSL_MDK_SHELL)
static char *certRSAname = "certs/rsa2048.der" ;
void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
/* set by shell command */
#elif defined(CYASSL_MDK_SHELL)
/* nothing */
#else
static const char *certRSAname = "certs/rsa2048.der" ;
#endif
void bench_rsa(void)
{
int i;
@ -676,18 +699,17 @@ void bench_rsa(void)
int rsaKeySz = 2048; /* used in printf */
#ifdef USE_CERT_BUFFERS_1024
XMEMCPY(tmp, rsa_key_der_1024, sizeof(rsa_key_der_1024));
bytes = sizeof(rsa_key_der_1024);
XMEMCPY(tmp, rsa_key_der_1024, sizeof_rsa_key_der_1024);
bytes = sizeof_rsa_key_der_1024;
rsaKeySz = 1024;
#elif defined(USE_CERT_BUFFERS_2048)
XMEMCPY(tmp, rsa_key_der_2048, sizeof(rsa_key_der_2048));
bytes = sizeof(rsa_key_der_2048);
XMEMCPY(tmp, rsa_key_der_2048, sizeof_rsa_key_der_2048);
bytes = sizeof_rsa_key_der_2048;
#else
FILE* file = fopen("./certs/rsa2048.der", "rb");
FILE* file = fopen(certRSAname, "rb");
if (!file) {
printf("can't find ./certs/rsa2048.der, "
"Please run from CyaSSL home dir\n");
printf("can't find %s, Please run from CyaSSL home dir\n", certRSAname);
return;
}
@ -695,6 +717,7 @@ void bench_rsa(void)
fclose(file);
#endif /* USE_CERT_BUFFERS */
#ifdef HAVE_CAVIUM
if (RsaInitCavium(&rsaKey, CAVIUM_DEV_ID) != 0)
printf("RSA init cavium failed\n");
@ -747,6 +770,19 @@ void bench_rsa(void)
#ifndef NO_DH
#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
defined(CYASSL_MDK_SHELL)
static char *certDHname = "certs/dh2048.der" ;
void set_Bench_DH_File(char * cert) { certDHname = cert ; }
/* set by shell command */
#elif defined(CYASSL_MDK_SHELL)
/* nothing */
#else
static const char *certDHname = "certs/dh2048.der" ;
#endif
void bench_dh(void)
{
int i;
@ -764,25 +800,26 @@ void bench_dh(void)
DhKey dhKey;
int dhKeySz = 2048; /* used in printf */
#ifdef USE_CERT_BUFFERS_1024
XMEMCPY(tmp, dh_key_der_1024, sizeof(dh_key_der_1024));
bytes = sizeof(dh_key_der_1024);
XMEMCPY(tmp, dh_key_der_1024, sizeof_dh_key_der_1024);
bytes = sizeof_dh_key_der_1024;
dhKeySz = 1024;
#elif defined(USE_CERT_BUFFERS_2048)
XMEMCPY(tmp, dh_key_der_2048, sizeof(dh_key_der_2048));
bytes = sizeof(dh_key_der_2048);
XMEMCPY(tmp, dh_key_der_2048, sizeof_dh_key_der_2048);
bytes = sizeof_dh_key_der_2048;
#else
FILE* file = fopen("./certs/dh2048.der", "rb");
FILE* file = fopen(certDHname, "rb");
if (!file) {
printf("can't find ./certs/dh2048.der, "
"Please run from CyaSSL home dir\n");
printf("can't find %s, Please run from CyaSSL home dir\n", certDHname);
return;
}
bytes = fread(tmp, 1, sizeof(tmp), file);
#endif /* USE_CERT_BUFFERS */
InitDhKey(&dhKey);
bytes = DhKeyDecode(tmp, &idx, &dhKey, (word32)bytes);
if (bytes != 0) {
@ -1001,7 +1038,9 @@ void bench_eccKeyAgree(void)
/* return seconds as a double */
return ( ns / 1000000000.0 );
}
#elif defined CYASSL_MDK_ARM
extern double current_time(int reset) ;
#else
#include <sys/time.h>

View File

@ -59,7 +59,8 @@
* document (See note in README).
*/
#include "stm32f2xx.h"
#include "stm32f2xx_cryp.h"
int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
int dir)
{
@ -2212,8 +2213,9 @@ static void GHASH(Aes* aes, const byte* a, word32 aSz,
static void GMULT(word64* X, word64* Y)
{
word64 Z[2] = {0,0};
word64 V[2] = {X[0], X[1]};
int i, j;
word64 V[2] ;
int i, j;
V[0] = X[0] ; V[1] = X[1] ;
for (i = 0; i < 2; i++)
{
@ -2312,7 +2314,8 @@ static void GHASH(Aes* aes, const byte* a, word32 aSz,
/* Hash in the lengths in bits of A and C */
{
word64 len[2] = {aSz, cSz};
word64 len[2] ;
len[0] = aSz ; len[1] = cSz;
/* Lengths are in bytes. Convert to bits. */
len[0] *= 8;
@ -2334,9 +2337,11 @@ static void GHASH(Aes* aes, const byte* a, word32 aSz,
static void GMULT(word32* X, word32* Y)
{
word32 Z[4] = {0,0,0,0};
word32 V[4] = {X[0], X[1], X[2], X[3]};
word32 V[4] ;
int i, j;
V[0] = X[0]; V[1] = X[1]; V[2] = X[2]; V[3] = X[3];
for (i = 0; i < 4; i++)
{
word32 y = Y[i];
@ -2717,7 +2722,7 @@ int AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
byte A[AES_BLOCK_SIZE];
byte B[AES_BLOCK_SIZE];
byte* o;
word32 i, lenSz, oSz, result = 0;
word32 i, lenSz, oSz; int result = 0;
o = out;
oSz = inSz;

View File

@ -44,8 +44,10 @@
#include <cyassl/ctaocrypt/sha256.h>
#include <cyassl/ctaocrypt/sha512.h>
#include <cyassl/ctaocrypt/logging.h>
#include <cyassl/ctaocrypt/random.h>
#ifndef NO_RC4
#include <cyassl/ctaocrypt/arc4.h>
#endif
@ -98,6 +100,15 @@
#define XTIME(t1) pic32_time((t1))
#define XGMTIME(c) gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#elif defined(CYASSL_MDK_ARM)
#include <rtl.h>
#undef RNG
#include "cyassl_MDK_ARM.h"
#undef RNG
#define RNG CyaSSL_RNG /*for avoiding name conflict in "stm32f2xx.h" */
#define XTIME(tl) (0)
#define XGMTIME(c) Cyassl_MDK_gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#elif defined(USER_TIME)
/* user time, and gmtime compatible functions, there is a gmtime
implementation here that WINCE uses, so really just need some ticks
@ -129,7 +140,7 @@
#else
/* default */
/* uses complete <time.h> facility */
#include <time.h>
#include <time.h>
#define XTIME(tl) time((tl))
#define XGMTIME(c) gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
@ -462,7 +473,8 @@ static int GetShortInt(const byte* input, word32* inOutIdx, int* number)
return *number;
}
#endif
#endif /* !NO_PWDBASED */
/* May not have one, not an error */
static int GetExplicitVersion(const byte* input, word32* inOutIdx, int* version)
@ -1377,7 +1389,7 @@ static int GetKey(DecodedCert* cert)
return StoreRsaKey(cert);
}
break;
#endif /* NO_RSA */
#ifdef HAVE_NTRU
case NTRUk:
@ -1782,8 +1794,8 @@ int ValidateDate(const byte* date, byte format, int dateType)
GetTime(&certTime.tm_hour, date, &i);
GetTime(&certTime.tm_min, date, &i);
GetTime(&certTime.tm_sec, date, &i);
if (date[i] != 'Z') { /* only Zulu supported for this profile */
if (date[i] != 'Z') { /* only Zulu supported for this profile */
CYASSL_MSG("Only Zulu time supported for this profile");
return 0;
}
@ -2307,7 +2319,7 @@ static int ConfirmSignature(const byte* buf, word32 bufSz,
FreeRsaKey(&pubKey);
return ret;
}
break;
#endif /* NO_RSA */
#ifdef HAVE_ECC
case ECDSAk:
@ -3396,28 +3408,28 @@ static const char* GetOneName(CertName* name, int idx)
switch (idx) {
case 0:
return name->country;
break;
case 1:
return name->state;
break;
case 2:
return name->locality;
break;
case 3:
return name->sur;
break;
case 4:
return name->org;
break;
case 5:
return name->unit;
break;
case 6:
return name->commonName;
break;
case 7:
return name->email;
break;
default:
return 0;
}
@ -3430,29 +3442,29 @@ static byte GetNameId(int idx)
switch (idx) {
case 0:
return ASN_COUNTRY_NAME;
break;
case 1:
return ASN_STATE_NAME;
break;
case 2:
return ASN_LOCALITY_NAME;
break;
case 3:
return ASN_SUR_NAME;
break;
case 4:
return ASN_ORG_NAME;
break;
case 5:
return ASN_ORGUNIT_NAME;
break;
case 6:
return ASN_COMMON_NAME;
break;
case 7:
/* email uses different id type */
return 0;
break;
default:
return 0;
}
@ -3602,10 +3614,14 @@ static int SetName(byte* output, CertName* name)
return totalBytes;
}
/* encode info from cert into DER enocder format */
static int EncodeCert(Cert* cert, DerCert* der, RsaKey* rsaKey, RNG* rng,
const byte* ntruKey, word16 ntruSz)
static int EncodeCert(
Cert* cert,
DerCert* der,
RsaKey* rsaKey,
RNG* rng,
const byte* ntruKey,
word16 ntruSz)
{
(void)ntruKey;
(void)ntruSz;
@ -5305,5 +5321,5 @@ int ParseCRL(DecodedCRL* dcrl, const byte* buff, word32 sz, void* cm)
}
#endif /* HAVE_CRL */
#endif

View File

@ -51,6 +51,7 @@
* Peripheral Library document (See note in README).
*/
#include "stm32f2xx.h"
#include "stm32f2xx_cryp.h"
void Des_SetKey(Des* des, const byte* key, const byte* iv, int dir)
{

View File

@ -32,6 +32,7 @@
#include <cyassl/ctaocrypt/logging.h>
#ifdef NO_INLINE
#include <cyassl/ctaocrypt/hc128.h>
#include <cyassl/ctaocrypt/misc.h>
#else
#include <ctaocrypt/src/misc.c>
#endif

View File

@ -38,7 +38,6 @@
word32 length);
#endif
static int InitHmac(Hmac* hmac, int type)
{
hmac->innerHashKeyed = 0;

View File

@ -111,6 +111,10 @@ static void cyassl_log(const int logLevel, const char *const logMessage)
#if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
NetSecure_TraceOut((CPU_CHAR *)logMessage);
#endif
#elif defined(CYASSL_MDK_ARM)
fflush(stdout) ;
printf("%s\n", logMessage);
fflush(stdout) ;
#else
fprintf(stderr, "%s\n", logMessage);
#endif

View File

@ -53,6 +53,7 @@
* md5->loLen = num bytes that have been written to STM32 FIFO
*/
XMEMSET(md5->buffer, 0, MD5_REG_SIZE);
md5->buffLen = 0;
md5->loLen = 0;

View File

@ -25,13 +25,19 @@
#include <cyassl/ctaocrypt/settings.h>
/* submitted by eof */
#ifdef USE_CYASSL_MEMORY
#include <cyassl/ctaocrypt/memory.h>
#include <cyassl/ctaocrypt/error.h>
#ifdef CYASSL_MALLOC_CHECK
#include <stdio.h>
static void err_sys(const char* msg)
{
printf("error = %s\n", msg);
return;
}
#endif
/* Set these to default values initially. */
static CyaSSL_Malloc_cb malloc_function = 0;
@ -71,7 +77,11 @@ void* CyaSSL_Malloc(size_t size)
res = malloc_function(size);
else
res = malloc(size);
#ifdef CYASSL_MALLOC_CHECK
if(res == NULL)
err_sys("CyaSSL_malloc") ;
#endif
return res;
}

View File

@ -172,7 +172,5 @@ STATIC INLINE void xorbuf(byte* buf, const byte* mask, word32 count)
for (i = 0; i < count; i++) buf[i] ^= mask[i];
}
}
#undef STATIC

View File

@ -31,9 +31,10 @@
#include <cyassl/ctaocrypt/hmac.h>
#include <cyassl/ctaocrypt/integer.h>
#include <cyassl/ctaocrypt/error.h>
#ifdef CYASSL_SHA512
#if defined(CYASSL_SHA512) || defined(CYASSL_SHA384)
#include <cyassl/ctaocrypt/sha512.h>
#endif
#ifdef NO_INLINE
#include <cyassl/ctaocrypt/misc.h>
#else

View File

@ -50,8 +50,8 @@
#include <windows.h>
#include <wincrypt.h>
#else
#ifndef NO_DEV_RANDOM
#include <fcntl.h>
#if !defined(NO_DEV_RANDOM) && !defined(CYASSL_MDK_ARM)
#include <fcntl.h>
#ifndef EBSNET
#include <unistd.h>
#endif
@ -541,8 +541,9 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
#endif /* FREESCALE_K70_RNGA */
#elif defined(STM32F2_RNG)
#undef RNG
#include "stm32f2xx_rng.h"
#include "stm32f2xx_rcc.h"
/*
* Generate a RNG seed using the hardware random number generator
* on the STM32F2. Documentation located in STM32F2xx Standard Peripheral
@ -571,8 +572,13 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
#elif defined(NO_DEV_RANDOM)
#warning "you need to write an os specific GenerateSeed() here"
#error "you need to write an os specific GenerateSeed() here"
/*
int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
return 0;
}
*/
#else /* !USE_WINDOWS_API && !THREADX && !MICRIUM && !NO_DEV_RANDOM */

View File

@ -43,7 +43,8 @@
* document (See note in README).
*/
#include "stm32f2xx.h"
#include "stm32f2xx_hash.h"
void InitSha(Sha* sha)
{
/* STM32F2 struct notes:

View File

@ -25,6 +25,8 @@
#include <cyassl/ctaocrypt/settings.h>
#ifndef NO_CRYPT_TEST
#ifdef CYASSL_TEST_CERT
#include <cyassl/ctaocrypt/asn.h>
#else
@ -72,11 +74,19 @@
#include <cyassl/openssl/des.h>
#endif
#if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048)
/* include test cert and key buffers for use with NO_FILESYSTEM */
#include <cyassl/certs_test.h>
#if defined(CYASSL_MDK_ARM)
#include "cert_data.h"
/* use certs_test.c for initial data, so other
commands can share the data. */
#else
#include <cyassl/certs_test.h>
#endif
#endif
#ifdef HAVE_NTRU
#include "crypto_ntru.h"
#endif
@ -86,14 +96,12 @@
#include "cavium_ioctl.h"
#endif
#include <string.h>
#ifdef FREESCALE_MQX
#include <mqx.h>
#include <fio.h>
#else
#include <stdio.h>
#endif
#include <stdlib.h>
#ifdef THREADX
@ -159,10 +167,10 @@ int pbkdf2_test(void);
static void err_sys(const char* msg, int es)
{
printf("%s error = %d\n", msg, es);
#ifndef THREADX
if (msg)
#if !defined(THREADX) && !defined(CYASSL_MDK_ARM)
if (msg)
exit(es);
#endif
#endif
return;
}
@ -193,63 +201,63 @@ void ctaocrypt_test(void* args)
#ifndef NO_MD5
if ( (ret = md5_test()) )
if ( (ret = md5_test()) != 0)
err_sys("MD5 test failed!\n", ret);
else
printf( "MD5 test passed!\n");
#endif
#ifdef CYASSL_MD2
if ( (ret = md2_test()) )
if ( (ret = md2_test()) != 0)
err_sys("MD2 test failed!\n", ret);
else
printf( "MD2 test passed!\n");
#endif
#ifndef NO_MD4
if ( (ret = md4_test()) )
if ( (ret = md4_test()) != 0)
err_sys("MD4 test failed!\n", ret);
else
printf( "MD4 test passed!\n");
#endif
#ifndef NO_SHA
if ( (ret = sha_test()) )
if ( (ret = sha_test()) != 0)
err_sys("SHA test failed!\n", ret);
else
printf( "SHA test passed!\n");
#endif
#ifndef NO_SHA256
if ( (ret = sha256_test()) )
if ( (ret = sha256_test()) != 0)
err_sys("SHA-256 test failed!\n", ret);
else
printf( "SHA-256 test passed!\n");
#endif
#ifdef CYASSL_SHA384
if ( (ret = sha384_test()) )
if ( (ret = sha384_test()) != 0)
err_sys("SHA-384 test failed!\n", ret);
else
printf( "SHA-384 test passed!\n");
#endif
#ifdef CYASSL_SHA512
if ( (ret = sha512_test()) )
if ( (ret = sha512_test()) != 0)
err_sys("SHA-512 test failed!\n", ret);
else
printf( "SHA-512 test passed!\n");
#endif
#ifdef CYASSL_RIPEMD
if ( (ret = ripemd_test()) )
if ( (ret = ripemd_test()) != 0)
err_sys("RIPEMD test failed!\n", ret);
else
printf( "RIPEMD test passed!\n");
#endif
#ifdef HAVE_BLAKE2
if ( (ret = blake2b_test()) )
if ( (ret = blake2b_test()) != 0)
err_sys("BLAKE2b test failed!\n", ret);
else
printf( "BLAKE2b test passed!\n");
@ -257,35 +265,35 @@ void ctaocrypt_test(void* args)
#ifndef NO_HMAC
#ifndef NO_MD5
if ( (ret = hmac_md5_test()) )
if ( (ret = hmac_md5_test()) != 0)
err_sys("HMAC-MD5 test failed!\n", ret);
else
printf( "HMAC-MD5 test passed!\n");
#endif
#ifndef NO_SHA
if ( (ret = hmac_sha_test()) )
if ( (ret = hmac_sha_test()) != 0)
err_sys("HMAC-SHA test failed!\n", ret);
else
printf( "HMAC-SHA test passed!\n");
#endif
#ifndef NO_SHA256
if ( (ret = hmac_sha256_test()) )
if ( (ret = hmac_sha256_test()) != 0)
err_sys("HMAC-SHA256 test failed!\n", ret);
else
printf( "HMAC-SHA256 test passed!\n");
#endif
#ifdef CYASSL_SHA384
if ( (ret = hmac_sha384_test()) )
if ( (ret = hmac_sha384_test()) != 0)
err_sys("HMAC-SHA384 test failed!\n", ret);
else
printf( "HMAC-SHA384 test passed!\n");
#endif
#ifdef CYASSL_SHA512
if ( (ret = hmac_sha512_test()) )
if ( (ret = hmac_sha512_test()) != 0)
err_sys("HMAC-SHA512 test failed!\n", ret);
else
printf( "HMAC-SHA512 test passed!\n");
@ -294,55 +302,55 @@ void ctaocrypt_test(void* args)
#endif
#ifndef NO_RC4
if ( (ret = arc4_test()) )
if ( (ret = arc4_test()) != 0)
err_sys("ARC4 test failed!\n", ret);
else
printf( "ARC4 test passed!\n");
#endif
#ifndef NO_HC128
if ( (ret = hc128_test()) )
if ( (ret = hc128_test()) != 0)
err_sys("HC-128 test failed!\n", ret);
else
printf( "HC-128 test passed!\n");
#endif
#ifndef NO_RABBIT
if ( (ret = rabbit_test()) )
if ( (ret = rabbit_test()) != 0)
err_sys("Rabbit test failed!\n", ret);
else
printf( "Rabbit test passed!\n");
#endif
#ifndef NO_DES3
if ( (ret = des_test()) )
if ( (ret = des_test()) != 0)
err_sys("DES test failed!\n", ret);
else
printf( "DES test passed!\n");
#endif
#ifndef NO_DES3
if ( (ret = des3_test()) )
if ( (ret = des3_test()) != 0)
err_sys("DES3 test failed!\n", ret);
else
printf( "DES3 test passed!\n");
#endif
#ifndef NO_AES
if ( (ret = aes_test()) )
if ( (ret = aes_test()) != 0)
err_sys("AES test failed!\n", ret);
else
printf( "AES test passed!\n");
#ifdef HAVE_AESGCM
if ( (ret = aesgcm_test()) )
if ( (ret = aesgcm_test()) != 0)
err_sys("AES-GCM test failed!\n", ret);
else
printf( "AES-GCM test passed!\n");
#endif
#ifdef HAVE_AESCCM
if ( (ret = aesccm_test()) )
if ( (ret = aesccm_test()) != 0)
err_sys("AES-CCM test failed!\n", ret);
else
printf( "AES-CCM test passed!\n");
@ -350,61 +358,61 @@ void ctaocrypt_test(void* args)
#endif
#ifdef HAVE_CAMELLIA
if ( (ret = camellia_test()) )
if ( (ret = camellia_test()) != 0)
err_sys("CAMELLIA test failed!\n", ret);
else
printf( "CAMELLIA test passed!\n");
#endif
if ( (ret = random_test()) )
if ( (ret = random_test()) != 0)
err_sys("RANDOM test failed!\n", ret);
else
printf( "RANDOM test passed!\n");
#ifndef NO_RSA
if ( (ret = rsa_test()) )
if ( (ret = rsa_test()) != 0)
err_sys("RSA test failed!\n", ret);
else
printf( "RSA test passed!\n");
#endif
#ifndef NO_DH
if ( (ret = dh_test()) )
if ( (ret = dh_test()) != 0)
err_sys("DH test failed!\n", ret);
else
printf( "DH test passed!\n");
#endif
#ifndef NO_DSA
if ( (ret = dsa_test()) )
if ( (ret = dsa_test()) != 0)
err_sys("DSA test failed!\n", ret);
else
printf( "DSA test passed!\n");
#endif
#ifndef NO_PWDBASED
if ( (ret = pwdbased_test()) )
if ( (ret = pwdbased_test()) != 0)
err_sys("PWDBASED test failed!\n", ret);
else
printf( "PWDBASED test passed!\n");
#endif
#ifdef OPENSSL_EXTRA
if ( (ret = openssl_test()) )
if ( (ret = openssl_test()) != 0)
err_sys("OPENSSL test failed!\n", ret);
else
printf( "OPENSSL test passed!\n");
#endif
#ifdef HAVE_ECC
if ( (ret = ecc_test()) )
if ( (ret = ecc_test()) != 0)
err_sys("ECC test failed!\n", ret);
else
printf( "ECC test passed!\n");
#endif
#ifdef HAVE_LIBZ
if ( (ret = compress_test()) )
if ( (ret = compress_test()) != 0)
err_sys("COMPRESS test failed!\n", ret);
else
printf( "COMPRESS test passed!\n");
@ -443,8 +451,10 @@ static int OpenNitroxDevice(int dma_mode,int dev_id)
int main(int argc, char** argv)
{
func_args args;
#ifdef HAVE_CAVIUM
int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
if (ret != 0)
@ -459,6 +469,7 @@ static int OpenNitroxDevice(int dma_mode,int dev_id)
#ifdef HAVE_CAVIUM
CspShutdown(CAVIUM_DEV_ID);
#endif
return args.return_code;
}
@ -1993,102 +2004,102 @@ typedef struct {
int camellia_test(void)
{
/* Camellia ECB Test Plaintext */
const byte pte[] =
static const byte pte[] =
{
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
};
/* Camellia ECB Test Initialization Vector */
const byte ive[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static const byte ive[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
/* Test 1: Camellia ECB 128-bit key */
const byte k1[] =
static const byte k1[] =
{
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
};
const byte c1[] =
static const byte c1[] =
{
0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43
};
/* Test 2: Camellia ECB 192-bit key */
const byte k2[] =
static const byte k2[] =
{
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
};
const byte c2[] =
static const byte c2[] =
{
0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9
};
/* Test 3: Camellia ECB 256-bit key */
const byte k3[] =
static const byte k3[] =
{
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
};
const byte c3[] =
static const byte c3[] =
{
0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09
};
/* Camellia CBC Test Plaintext */
const byte ptc[] =
static const byte ptc[] =
{
0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
};
/* Camellia CBC Test Initialization Vector */
const byte ivc[] =
static const byte ivc[] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
};
/* Test 4: Camellia-CBC 128-bit key */
const byte k4[] =
static const byte k4[] =
{
0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
};
const byte c4[] =
static const byte c4[] =
{
0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB
};
/* Test 5: Camellia-CBC 192-bit key */
const byte k5[] =
static const byte k5[] =
{
0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B
};
const byte c5[] =
static const byte c5[] =
{
0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93
};
/* Test 6: CBC 256-bit key */
const byte k6[] =
static const byte k6[] =
{
0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4
};
const byte c6[] =
static const byte c6[] =
{
0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA
@ -2233,13 +2244,24 @@ byte GetEntropy(ENTROPY_CMD cmd, byte* out)
#ifndef NO_RSA
#ifdef FREESCALE_MQX
static const char* clientKey = "a:\certs\\client-key.der";
static const char* clientCert = "a:\certs\\client-cert.der";
static const char* clientKey = "a:\\certs\\client-key.der";
static const char* clientCert = "a:\\certs\\client-cert.der";
#ifdef CYASSL_CERT_GEN
static const char* caKeyFile = "a:\certs\\ca-key.der";
static const char* caCertFile = "a:\certs\\ca-cert.pem";
static const char* caKeyFile = "a:\\certs\\ca-key.der";
static const char* caCertFile = "a:\\certs\\ca-cert.pem";
#endif
#elif !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
#elif !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && defined(CYASSL_MKD_SHELL)
static char* clientKey = "certs/client-key.der";
static char* clientCert = "certs/client-cert.der";
void set_clientKey(char *key) { clientKey = key ; } /* set by shell command */
void set_clientCert(char *cert) { clientCert = cert ; } /* set by shell command */
#ifdef CYASSL_CERT_GEN
static char* caKeyFile = "certs/ca-key.der";
static char* caCertFile = "certs/ca-cert.pem";
void set_caKeyFile (char * key) { caKeyFile = key ; } /* set by shell command */
void set_caCertFile(char * cert) { caCertFile = cert ; } /* set by shell command */
#endif
#elif !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
static const char* clientKey = "./certs/client-key.der";
static const char* clientCert = "./certs/client-cert.der";
#ifdef CYASSL_CERT_GEN
@ -2248,6 +2270,8 @@ byte GetEntropy(ENTROPY_CMD cmd, byte* out)
#endif
#endif
#define FOURK_BUF 4096
int rsa_test(void)
@ -2274,11 +2298,11 @@ int rsa_test(void)
return -40;
#ifdef USE_CERT_BUFFERS_1024
XMEMCPY(tmp, client_key_der_1024, sizeof(client_key_der_1024));
bytes = sizeof(client_key_der_1024);
XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
bytes = sizeof_client_key_der_1024;
#elif defined(USE_CERT_BUFFERS_2048)
XMEMCPY(tmp, client_key_der_2048, sizeof(client_key_der_2048));
bytes = sizeof(client_key_der_2048);
XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
bytes = sizeof_client_key_der_2048;
#else
file = fopen(clientKey, "rb");
@ -2317,12 +2341,16 @@ int rsa_test(void)
if (memcmp(plain, in, ret)) return -48;
#if defined(CYASSL_MDK_ARM)
#define sizeof(s) strlen((char *)(s))
#endif
#ifdef USE_CERT_BUFFERS_1024
XMEMCPY(tmp, client_cert_der_1024, sizeof(client_cert_der_1024));
bytes = sizeof(client_cert_der_1024);
XMEMCPY(tmp, client_cert_der_1024, sizeof_client_cert_der_1024);
bytes = sizeof_client_cert_der_1024;
#elif defined(USE_CERT_BUFFERS_2048)
XMEMCPY(tmp, client_cert_der_2048, sizeof(client_cert_der_2048));
bytes = sizeof(client_cert_der_2048);
XMEMCPY(tmp, client_cert_der_2048, sizeof_client_cert_der_2048);
bytes = sizeof_client_cert_der_2048;
#else
file2 = fopen(clientCert, "rb");
if (!file2)
@ -2332,6 +2360,10 @@ int rsa_test(void)
fclose(file2);
#endif
#ifdef sizeof
#undef sizeof
#endif
#ifdef CYASSL_TEST_CERT
InitDecodedCert(&cert, tmp, (word32)bytes, 0);
@ -2475,6 +2507,7 @@ int rsa_test(void)
int pemSz;
size_t bytes3;
word32 idx3 = 0;
FILE* file3 ;
#ifdef CYASSL_TEST_CERT
DecodedCert decode;
#endif
@ -2486,7 +2519,7 @@ int rsa_test(void)
if (pem == NULL)
return -312;
FILE* file3 = fopen(caKeyFile, "rb");
file3 = fopen(caKeyFile, "rb");
if (!file3)
return -412;
@ -2703,12 +2736,14 @@ int dh_test(void)
DhKey key;
DhKey key2;
RNG rng;
#ifdef USE_CERT_BUFFERS_1024
XMEMCPY(tmp, dh_key_der_1024, sizeof(dh_key_der_1024));
bytes = sizeof(dh_key_der_1024);
XMEMCPY(tmp, dh_key_der_1024, sizeof_dh_key_der_1024);
bytes = sizeof_dh_key_der_1024;
#elif defined(USE_CERT_BUFFERS_2048)
XMEMCPY(tmp, dh_key_der_2048, sizeof(dh_key_der_2048));
bytes = sizeof(dh_key_der_2048);
XMEMCPY(tmp, dh_key_der_2048, sizeof_dh_key_der_2048);
bytes = sizeof_dh_key_der_2048;
#else
FILE* file = fopen(dhKey, "rb");
@ -2759,7 +2794,7 @@ int dh_test(void)
#ifndef NO_DSA
#ifdef FREESCALE_MQX
static const char* dsaKey = "a:\certs\\dsa2048.der";
static const char* dsaKey = "a:\\certs\\dsa2048.der";
#elif !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
static const char* dsaKey = "./certs/dsa2048.der";
#endif
@ -2775,12 +2810,14 @@ int dsa_test(void)
Sha sha;
byte hash[SHA_DIGEST_SIZE];
byte signature[40];
#ifdef USE_CERT_BUFFERS_1024
XMEMCPY(tmp, dsa_key_der_1024, sizeof(dsa_key_der_1024));
bytes = sizeof(dsa_key_der_1024);
XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
bytes = sizeof_dsa_key_der_1024;
#elif defined(USE_CERT_BUFFERS_2048)
XMEMCPY(tmp, dsa_key_der_2048, sizeof(dsa_key_der_2048));
bytes = sizeof(dsa_key_der_2048);
XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
bytes = sizeof_dsa_key_der_2048;
#else
FILE* file = fopen(dsaKey, "rb");
@ -3350,3 +3387,4 @@ int compress_test(void)
#endif /* HAVE_LIBZ */
#endif /* NO_CRYPT_TEST */

View File

@ -70,6 +70,7 @@ const unsigned char client_key_der_1024[] =
0xA2, 0xFE, 0xBF, 0x08, 0x6B, 0x1A, 0x5D, 0x3F, 0x90, 0x12,
0xB1, 0x05, 0x86, 0x31, 0x29, 0xDB, 0xD9, 0xE2
};
const int sizeof_client_key_der_1024 = sizeof(client_key_der_1024) ;
/* ./certs/1024/client-cert.der, 1024-bit */
const unsigned char client_cert_der_1024[] =
@ -151,6 +152,7 @@ const unsigned char client_cert_der_1024[] =
0x1B, 0x4E, 0x5D, 0xBC, 0x4E, 0x9A, 0x7C, 0x1F, 0xAB, 0x56,
0x47, 0x4A
};
const int sizeof_client_cert_der_1024 = sizeof(client_cert_der_1024) ;
/* ./certs/1024/dh1024.der, 1024-bit */
const unsigned char dh_key_der_1024[] =
@ -170,6 +172,7 @@ const unsigned char dh_key_der_1024[] =
0x8C, 0x63, 0x0A, 0xAD, 0xC7, 0x10, 0xEA, 0xC7, 0xA1, 0xB9,
0x9D, 0xF2, 0xA8, 0x37, 0x73, 0x02, 0x01, 0x02
};
const int sizeof_dh_key_der_1024 = sizeof(dh_key_der_1024) ;
/* ./certs/1024/dsa1024.der, 1024-bit */
const unsigned char dsa_key_der_1024[] =
@ -220,6 +223,7 @@ const unsigned char dsa_key_der_1024[] =
0x3B, 0xA1, 0x19, 0x75, 0xDF, 0x9B, 0xF5, 0x72, 0x53, 0x4F,
0x39, 0xE1, 0x1C, 0xEC, 0x13, 0x84, 0x82, 0x18
};
const int sizeof_dsa_key_der_1024 = sizeof(dsa_key_der_1024) ;
/* ./certs/1024/rsa1024.der, 1024-bit */
const unsigned char rsa_key_der_1024[] =
@ -286,6 +290,7 @@ const unsigned char rsa_key_der_1024[] =
0xB9, 0x9E, 0xD5, 0x5B, 0x2E, 0x87, 0x1C, 0x58, 0xD0, 0x37,
0x89, 0x96, 0xEC, 0x48, 0x54, 0xF5, 0x9F, 0x0F, 0xB3
};
const int sizeof_rsa_key_der_1024 = sizeof(rsa_key_der_1024) ;
#elif defined(USE_CERT_BUFFERS_2048)
@ -413,6 +418,7 @@ const unsigned char client_key_der_2048[] =
0x45, 0x5D, 0x13, 0x39, 0x65, 0x42, 0x46, 0xA1, 0x9F, 0xCD,
0xF5, 0xBF
};
const int sizeof_client_key_der_2048 = sizeof(client_key_der_2048) ;
/* ./certs/client-cert.der, 2048-bit */
const unsigned char client_cert_der_2048[] =
@ -537,10 +543,11 @@ const unsigned char client_cert_der_2048[] =
0xC9, 0xB1, 0x71, 0x7E, 0x1B, 0x2B, 0xE1, 0xE3, 0xAF, 0xC0
};
const int sizeof_client_cert_der_2048 = sizeof(client_cert_der_2048) ;
/* ./certs/dh2048.der, 2048-bit */
const unsigned char dh_key_der_2048[] =
{
{
0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0xB0,
0xA1, 0x08, 0x06, 0x9C, 0x08, 0x13, 0xBA, 0x59, 0x06, 0x3C,
0xBC, 0x30, 0xD5, 0xF5, 0x00, 0xC1, 0x4F, 0x44, 0xA7, 0xD6,
@ -569,6 +576,7 @@ const unsigned char dh_key_der_2048[] =
0xC3, 0xA9, 0x41, 0x83, 0xFB, 0xC7, 0xFA, 0xC8, 0xE2, 0x1E,
0x7E, 0xAF, 0x00, 0x3F, 0x93, 0x02, 0x01, 0x02
};
const int sizeof_dh_key_der_2048 = sizeof(dh_key_der_2048) ;
/* ./certs/dsa2048.der, 2048-bit */
const unsigned char dsa_key_der_2048[] =
@ -658,6 +666,7 @@ const unsigned char dsa_key_der_2048[] =
0x3E, 0x75, 0x13, 0x13, 0x06, 0x8F, 0x94, 0xD3, 0xE6, 0xE9,
0x00, 0xCB, 0x62, 0x6D, 0x9A
};
const int sizeof_dsa_key_der_2048 = sizeof(dsa_key_der_2048) ;
/* ./certs/rsa2048.der, 2048-bit */
const unsigned char rsa_key_der_2048[] =
@ -783,6 +792,7 @@ const unsigned char rsa_key_der_2048[] =
0x83, 0x0B, 0xD4, 0x74, 0x80, 0xB6, 0x7D, 0x62, 0x45, 0xBF,
0x56
};
const int sizeof_rsa_key_der_2048 = sizeof(rsa_key_der_2048) ;
#endif /* USE_CERT_BUFFERS_1024 */

View File

@ -59,11 +59,18 @@ typedef struct OS_Seed {
CYASSL_LOCAL
int GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
#if defined(CYASSL_MDK_ARM)
#undef RNG
#define RNG CyaSSL_RNG /* for avoiding name conflict in "stm32f2xx.h" */
#endif
#ifndef NO_RC4
#define CYASSL_RNG_CAVIUM_MAGIC 0xBEEF0004
/* secure Random Nnumber Generator */
typedef struct RNG {
OS_Seed seed;
Arc4 cipher;
@ -82,6 +89,7 @@ typedef struct RNG {
#define DBRG_SEED_LEN (440/8)
/* secure Random Nnumber Generator */
typedef struct RNG {
OS_Seed seed;

View File

@ -56,7 +56,7 @@ CYASSL_API void Sha512Update(Sha512*, const byte*, word32);
CYASSL_API void Sha512Final(Sha512*, byte*);
#ifdef CYASSL_SHA384
#if defined(CYASSL_SHA384) || defined(HAVE_AESGCM)
/* in bytes */
enum {

View File

@ -54,7 +54,7 @@
|| defined(__mips64) || defined(__x86_64__))
/* long should be 64bit */
#define SIZEOF_LONG 8
#elif defined(__i386__)
#elif defined(__i386__) || defined(__CORTEX_M3__)
/* long long should be 64bit */
#define SIZEOF_LONG_LONG 8
#endif

View File

@ -52,6 +52,11 @@
#ifdef CYASSL_SHA512
#include <cyassl/ctaocrypt/sha512.h>
#endif
#ifdef HAVE_AESGCM
#include <cyassl/ctaocrypt/sha512.h>
#endif
#ifdef CYASSL_RIPEMD
#include <cyassl/ctaocrypt/ripemd.h>
#endif
@ -83,6 +88,8 @@
/* do nothing */
#elif defined(FREESCALE_MQX)
/* do nothing */
#elif defined(CYASSL_MDK_ARM)
#include <rtl.h>
#else
#ifndef SINGLE_THREADED
#define CYASSL_PTHREADS
@ -236,7 +243,7 @@ void c32to24(word32 in, word24 out);
#define BUILD_TLS_PSK_WITH_NULL_SHA
#endif
#ifndef NO_SHA256
#define BUILD_TLS_PSK_WITH_NULL_SHA256
#define BUILD_TLS_PSK_WITH_NULL_SHA256
#endif
#endif
#endif
@ -955,6 +962,8 @@ struct CYASSL_CIPHER {
typedef RTP_MUTEX CyaSSL_Mutex;
#elif defined(FREESCALE_MQX)
typedef MUTEX_STRUCT CyaSSL_Mutex;
#elif defined(CYASSL_MDK_ARM)
typedef OS_MUT CyaSSL_Mutex;
#else
#error Need a mutex type in multithreaded mode
#endif /* USE_WINDOWS_API */
@ -1321,7 +1330,7 @@ typedef struct Ciphers {
#ifdef BUILD_DES3
Des3* des3;
#endif
#ifdef BUILD_AES
#if defined(BUILD_AES) || defined(BUILD_AESGCM)
Aes* aes;
#endif
#ifdef HAVE_CAMELLIA

View File

@ -767,6 +767,7 @@ CYASSL_API int CyaSSL_CTX_SetTmpDH(CYASSL_CTX*, const unsigned char* p,
CYASSL_API int CyaSSL_CTX_SetTmpDH_buffer(CYASSL_CTX*, const unsigned char* b,
long sz, int format);
CYASSL_API int CyaSSL_CTX_SetTmpEC_DHE_Sz(CYASSL_CTX*, unsigned short);
#ifndef NO_FILESYSTEM
CYASSL_API int CyaSSL_CTX_SetTmpDH_file(CYASSL_CTX*, const char* f,
int format);
@ -790,7 +791,7 @@ CYASSL_API int CyaSSL_make_eap_keys(CYASSL*, void* key, unsigned int len,
#ifdef __PPU
#include <sys/types.h>
#include <sys/socket.h>
#else
#elif !defined(CYASSL_MDK_ARM)
#include <sys/uio.h>
#endif
/* allow writev style writing */

View File

@ -14,11 +14,14 @@
#include <winsock2.h>
#include <process.h>
#ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */
#include <ws2tcpip.h>
#include <ws2tcpip.h>
#include <wspiapi.h>
#endif
#define SOCKET_T SOCKET
#define SNPRINTF _snprintf
#elif defined(CYASSL_MDK_ARM)
#include <string.h>
#define SOCKET_T unsigned int
#else
#include <string.h>
#include <sys/types.h>
@ -66,7 +69,7 @@
/* HPUX doesn't use socklent_t for third parameter to accept, unless
_XOPEN_SOURCE_EXTENDED is defined */
#if !defined(__hpux__)
#if !defined(__hpux__) && !defined(CYASSL_MDK_ARM)
typedef socklen_t* ACCEPT_THIRD_T;
#else
#if defined _XOPEN_SOURCE_EXTENDED
@ -80,6 +83,9 @@
#ifdef USE_WINDOWS_API
#define CloseSocket(s) closesocket(s)
#define StartTCP() { WSADATA wsd; WSAStartup(0x0002, &wsd); }
#elif defined(CYASSL_MDK_ARM)
#define CloseSocket(s) closesocket(s)
#define StartTCP()
#else
#define CloseSocket(s) close(s)
#define StartTCP()
@ -97,6 +103,10 @@
#define CYASSL_THREAD
#define INFINITE -1
#define WAIT_OBJECT_0 0L
#elif defined(CYASSL_MDK_ARM)
typedef unsigned int THREAD_RETURN;
typedef int THREAD_TYPE;
#define CYASSL_THREAD
#else
typedef unsigned int THREAD_RETURN;
typedef intptr_t THREAD_TYPE;
@ -172,12 +182,13 @@ void join_thread(THREAD_TYPE);
#endif
static const word16 yasslPort = 11111;
static INLINE void err_sys(const char* msg)
{
printf("yassl error: %s\n", msg);
#ifndef CYASSL_MDK_SHELL
if (msg)
exit(EXIT_FAILURE);
#endif
}
@ -357,8 +368,13 @@ static INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer,
#ifndef TEST_IPV6
/* peer could be in human readable form */
if (peer != INADDR_ANY && isalpha((int)peer[0])) {
struct hostent* entry = gethostbyname(peer);
if ( (peer != INADDR_ANY) && isalpha((int)peer[0])) {
#ifdef CYASSL_MDK_ARM
int err;
struct hostent* entry = gethostbyname(peer, &err);
#else
struct hostent* entry = gethostbyname(peer);
#endif
if (entry) {
memcpy(&addr->sin_addr.s_addr, entry->h_addr_list[0],
@ -372,7 +388,11 @@ static INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer,
#ifndef TEST_IPV6
addr->sin_family = AF_INET_V;
#if defined(CYASSL_MDK_ARM)
addr->sin_family = PF_INET;
#else
addr->sin_family = AF_INET_V;
#endif
addr->sin_port = htons(port);
if (peer == INADDR_ANY)
addr->sin_addr.s_addr = INADDR_ANY;
@ -440,6 +460,8 @@ static INLINE void tcp_socket(SOCKET_T* sockfd, int udp)
if (res < 0)
err_sys("setsockopt SO_NOSIGPIPE failed\n");
}
#elif defined(CYASSL_MDK_ARM)
/* nothing to define */
#else /* no S_NOSIGPIPE */
signal(SIGPIPE, SIG_IGN);
#endif /* S_NOSIGPIPE */
@ -457,7 +479,6 @@ static INLINE void tcp_socket(SOCKET_T* sockfd, int udp)
#endif /* USE_WINDOWS_API */
}
static INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port,
int udp)
{
@ -486,6 +507,8 @@ enum {
TEST_ERROR_READY
};
#if !defined(CYASSL_MDK_ARM)
static INLINE int tcp_select(SOCKET_T socketfd, int to_sec)
{
fd_set recvfds, errfds;
@ -511,6 +534,7 @@ static INLINE int tcp_select(SOCKET_T socketfd, int to_sec)
return TEST_SELECT_FAIL;
}
#endif /* !CYASSL_MDK_ARM */
static INLINE void tcp_listen(SOCKET_T* sockfd, int* port, int useAnyAddr,
@ -523,7 +547,7 @@ static INLINE void tcp_listen(SOCKET_T* sockfd, int* port, int useAnyAddr,
build_addr(&addr, (useAnyAddr ? INADDR_ANY : yasslIP), *port, udp);
tcp_socket(sockfd, udp);
#ifndef USE_WINDOWS_API
#if !defined(USE_WINDOWS_API) && !defined(CYASSL_MDK_ARM)
{
int res, on = 1;
socklen_t len = sizeof(on);
@ -584,7 +608,7 @@ static INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
tcp_socket(sockfd, 1);
#ifndef USE_WINDOWS_API
#if !defined(USE_WINDOWS_API) && !defined(CYASSL_MDK_ARM)
{
int res, on = 1;
socklen_t len = sizeof(on);
@ -670,6 +694,8 @@ static INLINE void tcp_set_nonblocking(SOCKET_T* sockfd)
int ret = ioctlsocket(*sockfd, FIONBIO, &blocking);
if (ret == SOCKET_ERROR)
err_sys("ioctlsocket failed");
#elif defined(CYASSL_MDK_ARM)
/* non blocking not suppported, for now */
#else
int flags = fcntl(*sockfd, F_GETFL, 0);
if (flags < 0)
@ -753,6 +779,7 @@ static INLINE unsigned int my_psk_server_cb(CYASSL* ssl, const char* identity,
#else
#if !defined(CYASSL_MDK_ARM)
#include <sys/time.h>
static INLINE double current_time(void)
@ -762,7 +789,8 @@ static INLINE unsigned int my_psk_server_cb(CYASSL* ssl, const char* identity,
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000;
}
#endif
#endif /* USE_WINDOWS_API */
@ -853,7 +881,6 @@ static INLINE void CRL_CallBack(const char* url)
#endif
#ifndef NO_CERTS
static INLINE void CaCb(unsigned char* der, int sz, int type)
@ -984,6 +1011,8 @@ static INLINE int CurrentDir(const char* str)
return 0;
}
#elif defined(CYASSL_MDK_ARM)
/* KEIL-RL File System does not support relative directry */
#else
#ifndef MAX_PATH

View File

@ -22,6 +22,13 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if defined(CYASSL_MDK_ARM)
#include <stdio.h>
#include <string.h>
#include <rtl.h>
#include "cyassl_MDK_ARM.h"
#endif
#include <cyassl/ctaocrypt/settings.h>
@ -125,6 +132,9 @@ static void Usage(void)
#endif
}
#ifdef CYASSL_MDK_SHELL
#define exit(code) return
#endif
THREAD_RETURN CYASSL_THREAD client_test(void* args)
{
@ -314,7 +324,9 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args)
case 0:
method = CyaSSLv3_client_method();
break;
#ifndef NO_TLS
case 1:
method = CyaTLSv1_client_method();
break;
@ -322,11 +334,15 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args)
case 2:
method = CyaTLSv1_1_client_method();
break;
#endif
#endif /* NO_TLS */
#endif /* NO_OLD_TLS */
#ifndef NO_TLS
case 3:
method = CyaTLSv1_2_client_method();
break;
#endif
#ifdef CYASSL_DTLS
case -1:
@ -436,6 +452,7 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args)
for (i = 0; i < times; i++) {
tcp_connect(&sockfd, host, port, doDTLS);
ssl = CyaSSL_new(ctx);
CyaSSL_set_fd(ssl, sockfd);
if (CyaSSL_connect(ssl) != SSL_SUCCESS)
@ -455,7 +472,11 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args)
exit(EXIT_SUCCESS);
}
#if defined(CYASSL_MDK_ARM)
CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
#endif
ssl = CyaSSL_new(ctx);
if (ssl == NULL)
err_sys("unable to get SSL object");
@ -649,7 +670,7 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args)
args.argv = argv;
CyaSSL_Init();
#ifdef DEBUG_CYASSL
#if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL)
CyaSSL_Debugging_ON();
#endif
if (CurrentDir("client") || CurrentDir("build"))

View File

@ -26,6 +26,14 @@
#include <cyassl/ctaocrypt/settings.h>
#include <cyassl/openssl/ssl.h>
#if defined(CYASSL_MDK_ARM)
#include <stdio.h>
#include <string.h>
#include <rtl.h>
#include "cyassl_MDK_ARM.h"
#endif
#include <cyassl/test.h>
#include "examples/echoclient/echoclient.h"
@ -34,7 +42,7 @@ void echoclient_test(void* args)
{
SOCKET_T sockfd = 0;
FILE* fin = stdin;
FILE* fin = stdin ;
FILE* fout = stdout;
int inCreated = 0;
@ -55,8 +63,11 @@ void echoclient_test(void* args)
int port = yasslPort;
((func_args*)args)->return_code = -1; /* error state */
#ifndef CYASSL_MDK_SHELL
argc = ((func_args*)args)->argc;
argv = ((func_args*)args)->argv;
#endif
if (argc >= 2) {
fin = fopen(argv[1], "r");
@ -131,7 +142,13 @@ void echoclient_test(void* args)
#ifdef OPENSSL_EXTRA
SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
#endif
#if defined(CYASSL_MDK_ARM)
CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
#endif
ssl = SSL_new(ctx);
if (doDTLS) {
SOCKADDR_IN_T addr;
@ -142,16 +159,17 @@ void echoclient_test(void* args)
else {
tcp_connect(&sockfd, yasslIP, port, 0);
}
SSL_set_fd(ssl, sockfd);
#if defined(USE_WINDOWS_API) && defined(CYASSL_DTLS) && defined(NO_MAIN_DRIVER)
/* let echoserver bind first, TODO: add Windows signal like pthreads does */
Sleep(100);
#endif
if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");
while (fgets(msg, sizeof(msg), fin)) {
while (fgets(msg, sizeof(msg), fin) != 0) {
sendSz = (int)strlen(msg);
if (SSL_write(ssl, msg, sendSz) != sendSz)
@ -167,18 +185,32 @@ void echoclient_test(void* args)
break;
}
#ifndef CYASSL_MDK_SHELL
while (sendSz) {
int got;
if ( (got = SSL_read(ssl, reply, sizeof(reply)-1)) > 0) {
reply[got] = 0;
fputs(reply, fout);
fflush(fout) ;
sendSz -= got;
}
else
break;
}
#else
{
int got;
if ( (got = SSL_read(ssl, reply, sizeof(reply)-1)) > 0) {
reply[got] = 0;
fputs(reply, fout);
fflush(fout) ;
sendSz -= got;
}
}
#endif
}
#ifdef CYASSL_DTLS
strncpy(msg, "break", 6);
sendSz = (int)strlen(msg);
@ -219,12 +251,14 @@ void echoclient_test(void* args)
args.argv = argv;
CyaSSL_Init();
#ifdef DEBUG_CYASSL
#if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL)
CyaSSL_Debugging_ON();
#endif
if (CurrentDir("echoclient") || CurrentDir("build"))
ChangeDirBack(2);
echoclient_test(&args);
CyaSSL_Cleanup();
#ifdef HAVE_CAVIUM
@ -232,11 +266,7 @@ void echoclient_test(void* args)
#endif
return args.return_code;
}
int myoptind = 0;
char* myoptarg = NULL;
#endif /* NO_MAIN_DRIVER */

View File

@ -25,6 +25,13 @@
#include <cyassl/ctaocrypt/settings.h>
#if defined(CYASSL_MDK_ARM)
#include <stdio.h>
#include <string.h>
#include <rtl.h>
#include "cyassl_MDK_ARM.h"
#endif
#include <cyassl/ssl.h>
#include <cyassl/test.h>
@ -39,6 +46,7 @@
CYASSL_API void PrintSessionStats(void);
#endif
#define SVR_COMMAND_SIZE 256
static void SignalReady(void* args, int port)
{
@ -192,7 +200,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
while (!shutDown) {
CYASSL* ssl = 0;
char command[1024+1];
char command[SVR_COMMAND_SIZE+1];
int echoSz = 0;
int clientfd;
int firstRead = 1;
@ -328,7 +336,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
args.argv = argv;
CyaSSL_Init();
#ifdef DEBUG_CYASSL
#if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL)
CyaSSL_Debugging_ON();
#endif
if (CurrentDir("echoserver") || CurrentDir("build"))
@ -342,10 +350,9 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
return args.return_code;
}
int myoptind = 0;
char* myoptarg = NULL;
#endif /* NO_MAIN_DRIVER */

View File

@ -30,6 +30,13 @@
#define CYASSL_TRACK_MEMORY
#endif
#if defined(CYASSL_MDK_ARM)
#include <stdio.h>
#include <string.h>
#include <rtl.h>
#include "cyassl_MDK_ARM.h"
#endif
#include <cyassl/openssl/ssl.h>
#include <cyassl/test.h>
@ -117,6 +124,10 @@ static void Usage(void)
printf("-N Use Non-blocking sockets\n");
}
#ifdef CYASSL_MDK_SHELL
#define exit(code) return(code)
#endif
THREAD_RETURN CYASSL_THREAD server_test(void* args)
{
@ -264,19 +275,25 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
method = SSLv3_server_method();
break;
#ifndef NO_TLS
case 1:
method = TLSv1_server_method();
break;
case 2:
method = TLSv1_1_server_method();
break;
#endif
#endif
#ifndef NO_TLS
case 3:
method = TLSv1_2_server_method();
break;
#endif
#ifdef CYASSL_DTLS
case -1:
method = DTLSv1_server_method();
@ -432,6 +449,10 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg))
err_sys("SSL_write failed");
#if defined(CYASSL_MDK_SHELL) && defined(HAVE_MDK_RTX)
os_dly_wait(500) ;
#endif
SSL_shutdown(ssl);
SSL_free(ssl);
@ -468,7 +489,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
args.argv = argv;
CyaSSL_Init();
#ifdef DEBUG_CYASSL
#if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL)
CyaSSL_Debugging_ON();
#endif
if (CurrentDir("server") || CurrentDir("build"))
@ -510,4 +531,3 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
#endif