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