A library for setting up Secure Socket Layer (SSL) connections and verifying remote hosts using certificates. Contains only the source files for mbed platform implementation of the library.

Dependents:   HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL

Committer:
Vanger
Date:
Mon Jan 19 21:45:42 2015 +0000
Revision:
0:b86d15c6ba29
Updated CyaSSL Library to 3.3.0. Changed Settings and functions to be implemented for mbed platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vanger 0:b86d15c6ba29 1 /* port.h
Vanger 0:b86d15c6ba29 2 *
Vanger 0:b86d15c6ba29 3 * Copyright (C) 2006-2014 wolfSSL Inc.
Vanger 0:b86d15c6ba29 4 *
Vanger 0:b86d15c6ba29 5 * This file is part of CyaSSL.
Vanger 0:b86d15c6ba29 6 *
Vanger 0:b86d15c6ba29 7 * CyaSSL is free software; you can redistribute it and/or modify
Vanger 0:b86d15c6ba29 8 * it under the terms of the GNU General Public License as published by
Vanger 0:b86d15c6ba29 9 * the Free Software Foundation; either version 2 of the License, or
Vanger 0:b86d15c6ba29 10 * (at your option) any later version.
Vanger 0:b86d15c6ba29 11 *
Vanger 0:b86d15c6ba29 12 * CyaSSL is distributed in the hope that it will be useful,
Vanger 0:b86d15c6ba29 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Vanger 0:b86d15c6ba29 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Vanger 0:b86d15c6ba29 15 * GNU General Public License for more details.
Vanger 0:b86d15c6ba29 16 *
Vanger 0:b86d15c6ba29 17 * You should have received a copy of the GNU General Public License
Vanger 0:b86d15c6ba29 18 * along with this program; if not, write to the Free Software
Vanger 0:b86d15c6ba29 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Vanger 0:b86d15c6ba29 20 */
Vanger 0:b86d15c6ba29 21
Vanger 0:b86d15c6ba29 22
Vanger 0:b86d15c6ba29 23 #ifndef CTAO_CRYPT_PORT_H
Vanger 0:b86d15c6ba29 24 #define CTAO_CRYPT_PORT_H
Vanger 0:b86d15c6ba29 25
Vanger 0:b86d15c6ba29 26
Vanger 0:b86d15c6ba29 27 #ifdef __cplusplus
Vanger 0:b86d15c6ba29 28 extern "C" {
Vanger 0:b86d15c6ba29 29 #endif
Vanger 0:b86d15c6ba29 30
Vanger 0:b86d15c6ba29 31
Vanger 0:b86d15c6ba29 32 #ifdef USE_WINDOWS_API
Vanger 0:b86d15c6ba29 33 #ifdef CYASSL_GAME_BUILD
Vanger 0:b86d15c6ba29 34 #include "system/xtl.h"
Vanger 0:b86d15c6ba29 35 #else
Vanger 0:b86d15c6ba29 36 #ifndef WIN32_LEAN_AND_MEAN
Vanger 0:b86d15c6ba29 37 #define WIN32_LEAN_AND_MEAN
Vanger 0:b86d15c6ba29 38 #endif
Vanger 0:b86d15c6ba29 39 #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
Vanger 0:b86d15c6ba29 40 /* On WinCE winsock2.h must be included before windows.h */
Vanger 0:b86d15c6ba29 41 #include <winsock2.h>
Vanger 0:b86d15c6ba29 42 #endif
Vanger 0:b86d15c6ba29 43 #include <windows.h>
Vanger 0:b86d15c6ba29 44 #endif
Vanger 0:b86d15c6ba29 45 #elif defined(THREADX)
Vanger 0:b86d15c6ba29 46 #ifndef SINGLE_THREADED
Vanger 0:b86d15c6ba29 47 #include "tx_api.h"
Vanger 0:b86d15c6ba29 48 #endif
Vanger 0:b86d15c6ba29 49 #elif defined(MICRIUM)
Vanger 0:b86d15c6ba29 50 /* do nothing, just don't pick Unix */
Vanger 0:b86d15c6ba29 51 #elif defined(FREERTOS) || defined(CYASSL_SAFERTOS)
Vanger 0:b86d15c6ba29 52 /* do nothing */
Vanger 0:b86d15c6ba29 53 #elif defined(EBSNET)
Vanger 0:b86d15c6ba29 54 /* do nothing */
Vanger 0:b86d15c6ba29 55 #elif defined(FREESCALE_MQX)
Vanger 0:b86d15c6ba29 56 /* do nothing */
Vanger 0:b86d15c6ba29 57 #elif defined(CYASSL_MDK_ARM)
Vanger 0:b86d15c6ba29 58 #if defined(CYASSL_MDK5)
Vanger 0:b86d15c6ba29 59 #include "cmsis_os.h"
Vanger 0:b86d15c6ba29 60 #else
Vanger 0:b86d15c6ba29 61 #include <rtl.h>
Vanger 0:b86d15c6ba29 62 #endif
Vanger 0:b86d15c6ba29 63 #elif defined(CYASSL_CMSIS_RTOS)
Vanger 0:b86d15c6ba29 64 #include "cmsis_os.h"
Vanger 0:b86d15c6ba29 65 #elif defined(CYASSL_TIRTOS)
Vanger 0:b86d15c6ba29 66 #include <ti/sysbios/BIOS.h>
Vanger 0:b86d15c6ba29 67 #include <ti/sysbios/knl/Semaphore.h>
Vanger 0:b86d15c6ba29 68 #else
Vanger 0:b86d15c6ba29 69 #ifndef SINGLE_THREADED
Vanger 0:b86d15c6ba29 70 #define CYASSL_PTHREADS
Vanger 0:b86d15c6ba29 71 #include <pthread.h>
Vanger 0:b86d15c6ba29 72 #endif
Vanger 0:b86d15c6ba29 73 #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)
Vanger 0:b86d15c6ba29 74 #include <unistd.h> /* for close of BIO */
Vanger 0:b86d15c6ba29 75 #endif
Vanger 0:b86d15c6ba29 76 #endif
Vanger 0:b86d15c6ba29 77
Vanger 0:b86d15c6ba29 78
Vanger 0:b86d15c6ba29 79 #ifdef SINGLE_THREADED
Vanger 0:b86d15c6ba29 80 typedef int CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 81 #else /* MULTI_THREADED */
Vanger 0:b86d15c6ba29 82 /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */
Vanger 0:b86d15c6ba29 83 #ifdef FREERTOS
Vanger 0:b86d15c6ba29 84 typedef xSemaphoreHandle CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 85 #elif defined(CYASSL_SAFERTOS)
Vanger 0:b86d15c6ba29 86 typedef struct CyaSSL_Mutex {
Vanger 0:b86d15c6ba29 87 signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES];
Vanger 0:b86d15c6ba29 88 xSemaphoreHandle mutex;
Vanger 0:b86d15c6ba29 89 } CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 90 #elif defined(USE_WINDOWS_API)
Vanger 0:b86d15c6ba29 91 typedef CRITICAL_SECTION CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 92 #elif defined(CYASSL_PTHREADS)
Vanger 0:b86d15c6ba29 93 typedef pthread_mutex_t CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 94 #elif defined(THREADX)
Vanger 0:b86d15c6ba29 95 typedef TX_MUTEX CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 96 #elif defined(MICRIUM)
Vanger 0:b86d15c6ba29 97 typedef OS_MUTEX CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 98 #elif defined(EBSNET)
Vanger 0:b86d15c6ba29 99 typedef RTP_MUTEX CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 100 #elif defined(FREESCALE_MQX)
Vanger 0:b86d15c6ba29 101 typedef MUTEX_STRUCT CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 102 #elif defined(CYASSL_MDK_ARM)
Vanger 0:b86d15c6ba29 103 #if defined(CYASSL_CMSIS_RTOS)
Vanger 0:b86d15c6ba29 104 typedef osMutexId CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 105 #else
Vanger 0:b86d15c6ba29 106 typedef OS_MUT CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 107 #endif
Vanger 0:b86d15c6ba29 108 #elif defined(CYASSL_CMSIS_RTOS)
Vanger 0:b86d15c6ba29 109 typedef osMutexId CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 110 #elif defined(CYASSL_TIRTOS)
Vanger 0:b86d15c6ba29 111 typedef ti_sysbios_knl_Semaphore_Handle CyaSSL_Mutex;
Vanger 0:b86d15c6ba29 112 #else
Vanger 0:b86d15c6ba29 113 #error Need a mutex type in multithreaded mode
Vanger 0:b86d15c6ba29 114 #endif /* USE_WINDOWS_API */
Vanger 0:b86d15c6ba29 115 #endif /* SINGLE_THREADED */
Vanger 0:b86d15c6ba29 116
Vanger 0:b86d15c6ba29 117 CYASSL_LOCAL int InitMutex(CyaSSL_Mutex*);
Vanger 0:b86d15c6ba29 118 CYASSL_LOCAL int FreeMutex(CyaSSL_Mutex*);
Vanger 0:b86d15c6ba29 119 CYASSL_LOCAL int LockMutex(CyaSSL_Mutex*);
Vanger 0:b86d15c6ba29 120 CYASSL_LOCAL int UnLockMutex(CyaSSL_Mutex*);
Vanger 0:b86d15c6ba29 121
Vanger 0:b86d15c6ba29 122
Vanger 0:b86d15c6ba29 123 /* filesystem abstraction layer, used by ssl.c */
Vanger 0:b86d15c6ba29 124 #ifndef NO_FILESYSTEM
Vanger 0:b86d15c6ba29 125
Vanger 0:b86d15c6ba29 126 #if defined(EBSNET)
Vanger 0:b86d15c6ba29 127 #define XFILE int
Vanger 0:b86d15c6ba29 128 #define XFOPEN(NAME, MODE) vf_open((const char *)NAME, VO_RDONLY, 0);
Vanger 0:b86d15c6ba29 129 #define XFSEEK vf_lseek
Vanger 0:b86d15c6ba29 130 #define XFTELL vf_tell
Vanger 0:b86d15c6ba29 131 #define XREWIND vf_rewind
Vanger 0:b86d15c6ba29 132 #define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT)
Vanger 0:b86d15c6ba29 133 #define XFWRITE(BUF, SZ, AMT, FD) vf_write(FD, BUF, SZ*AMT)
Vanger 0:b86d15c6ba29 134 #define XFCLOSE vf_close
Vanger 0:b86d15c6ba29 135 #define XSEEK_END VSEEK_END
Vanger 0:b86d15c6ba29 136 #define XBADFILE -1
Vanger 0:b86d15c6ba29 137 #elif defined(LSR_FS)
Vanger 0:b86d15c6ba29 138 #include <fs.h>
Vanger 0:b86d15c6ba29 139 #define XFILE struct fs_file*
Vanger 0:b86d15c6ba29 140 #define XFOPEN(NAME, MODE) fs_open((char*)NAME);
Vanger 0:b86d15c6ba29 141 #define XFSEEK(F, O, W) (void)F
Vanger 0:b86d15c6ba29 142 #define XFTELL(F) (F)->len
Vanger 0:b86d15c6ba29 143 #define XREWIND(F) (void)F
Vanger 0:b86d15c6ba29 144 #define XFREAD(BUF, SZ, AMT, F) fs_read(F, (char*)BUF, SZ*AMT)
Vanger 0:b86d15c6ba29 145 #define XFWRITE(BUF, SZ, AMT, F) fs_write(F, (char*)BUF, SZ*AMT)
Vanger 0:b86d15c6ba29 146 #define XFCLOSE fs_close
Vanger 0:b86d15c6ba29 147 #define XSEEK_END 0
Vanger 0:b86d15c6ba29 148 #define XBADFILE NULL
Vanger 0:b86d15c6ba29 149 #elif defined(FREESCALE_MQX)
Vanger 0:b86d15c6ba29 150 #define XFILE MQX_FILE_PTR
Vanger 0:b86d15c6ba29 151 #define XFOPEN fopen
Vanger 0:b86d15c6ba29 152 #define XFSEEK fseek
Vanger 0:b86d15c6ba29 153 #define XFTELL ftell
Vanger 0:b86d15c6ba29 154 #define XREWIND(F) fseek(F, 0, IO_SEEK_SET)
Vanger 0:b86d15c6ba29 155 #define XFREAD fread
Vanger 0:b86d15c6ba29 156 #define XFWRITE fwrite
Vanger 0:b86d15c6ba29 157 #define XFCLOSE fclose
Vanger 0:b86d15c6ba29 158 #define XSEEK_END IO_SEEK_END
Vanger 0:b86d15c6ba29 159 #define XBADFILE NULL
Vanger 0:b86d15c6ba29 160 #elif defined(MICRIUM)
Vanger 0:b86d15c6ba29 161 #include <fs.h>
Vanger 0:b86d15c6ba29 162 #define XFILE FS_FILE*
Vanger 0:b86d15c6ba29 163 #define XFOPEN fs_fopen
Vanger 0:b86d15c6ba29 164 #define XFSEEK fs_fseek
Vanger 0:b86d15c6ba29 165 #define XFTELL fs_ftell
Vanger 0:b86d15c6ba29 166 #define XREWIND fs_rewind
Vanger 0:b86d15c6ba29 167 #define XFREAD fs_fread
Vanger 0:b86d15c6ba29 168 #define XFWRITE fs_fwrite
Vanger 0:b86d15c6ba29 169 #define XFCLOSE fs_fclose
Vanger 0:b86d15c6ba29 170 #define XSEEK_END FS_SEEK_END
Vanger 0:b86d15c6ba29 171 #define XBADFILE NULL
Vanger 0:b86d15c6ba29 172 #else
Vanger 0:b86d15c6ba29 173 /* stdio, default case */
Vanger 0:b86d15c6ba29 174 #define XFILE FILE*
Vanger 0:b86d15c6ba29 175 #if defined(CYASSL_MDK_ARM)
Vanger 0:b86d15c6ba29 176 #include <stdio.h>
Vanger 0:b86d15c6ba29 177 extern FILE * CyaSSL_fopen(const char *name, const char *mode) ;
Vanger 0:b86d15c6ba29 178 #define XFOPEN CyaSSL_fopen
Vanger 0:b86d15c6ba29 179 #else
Vanger 0:b86d15c6ba29 180 #define XFOPEN fopen
Vanger 0:b86d15c6ba29 181 #endif
Vanger 0:b86d15c6ba29 182 #define XFSEEK fseek
Vanger 0:b86d15c6ba29 183 #define XFTELL ftell
Vanger 0:b86d15c6ba29 184 #define XREWIND rewind
Vanger 0:b86d15c6ba29 185 #define XFREAD fread
Vanger 0:b86d15c6ba29 186 #define XFWRITE fwrite
Vanger 0:b86d15c6ba29 187 #define XFCLOSE fclose
Vanger 0:b86d15c6ba29 188 #define XSEEK_END SEEK_END
Vanger 0:b86d15c6ba29 189 #define XBADFILE NULL
Vanger 0:b86d15c6ba29 190 #endif
Vanger 0:b86d15c6ba29 191
Vanger 0:b86d15c6ba29 192 #endif /* NO_FILESYSTEM */
Vanger 0:b86d15c6ba29 193
Vanger 0:b86d15c6ba29 194
Vanger 0:b86d15c6ba29 195 #ifdef __cplusplus
Vanger 0:b86d15c6ba29 196 } /* extern "C" */
Vanger 0:b86d15c6ba29 197 #endif
Vanger 0:b86d15c6ba29 198
Vanger 0:b86d15c6ba29 199 #endif /* CTAO_CRYPT_PORT_H */
Vanger 0:b86d15c6ba29 200