Fork of CyaSSL for my specific settings

Dependents:   CyaSSL_Example

Fork of CyaSSL by wolf SSL

Committer:
wolfSSL
Date:
Sat Jul 12 07:18:23 2014 +0000
Revision:
0:1239e9b70ca2
Child:
4:28ac50e1d49c
CyaSSL 3.0.0;

Who changed what in which revision?

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