wolfSSL 3.11.1 for TLS1.3 beta
Fork of wolfSSL by
wolfssl/wolfcrypt/wc_port.h@13:80fb167dafdf, 2017-05-30 (annotated)
- Committer:
- wolfSSL
- Date:
- Tue May 30 06:16:19 2017 +0000
- Revision:
- 13:80fb167dafdf
- Parent:
- 11:cee25a834751
wolfSSL 3.11.1: TLS1.3 Beta
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 11:cee25a834751 | 1 | /* wc_port.h |
wolfSSL | 11:cee25a834751 | 2 | * |
wolfSSL | 11:cee25a834751 | 3 | * Copyright (C) 2006-2016 wolfSSL Inc. |
wolfSSL | 11:cee25a834751 | 4 | * |
wolfSSL | 11:cee25a834751 | 5 | * This file is part of wolfSSL. |
wolfSSL | 11:cee25a834751 | 6 | * |
wolfSSL | 11:cee25a834751 | 7 | * wolfSSL is free software; you can redistribute it and/or modify |
wolfSSL | 11:cee25a834751 | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 11:cee25a834751 | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 11:cee25a834751 | 10 | * (at your option) any later version. |
wolfSSL | 11:cee25a834751 | 11 | * |
wolfSSL | 11:cee25a834751 | 12 | * wolfSSL is distributed in the hope that it will be useful, |
wolfSSL | 11:cee25a834751 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 11:cee25a834751 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 11:cee25a834751 | 15 | * GNU General Public License for more details. |
wolfSSL | 11:cee25a834751 | 16 | * |
wolfSSL | 11:cee25a834751 | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 11:cee25a834751 | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 11:cee25a834751 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
wolfSSL | 11:cee25a834751 | 20 | */ |
wolfSSL | 11:cee25a834751 | 21 | |
wolfSSL | 11:cee25a834751 | 22 | |
wolfSSL | 11:cee25a834751 | 23 | |
wolfSSL | 11:cee25a834751 | 24 | #ifndef WOLF_CRYPT_PORT_H |
wolfSSL | 11:cee25a834751 | 25 | #define WOLF_CRYPT_PORT_H |
wolfSSL | 11:cee25a834751 | 26 | |
wolfSSL | 11:cee25a834751 | 27 | #include <wolfssl/wolfcrypt/visibility.h> |
wolfSSL | 11:cee25a834751 | 28 | |
wolfSSL | 11:cee25a834751 | 29 | #ifdef __cplusplus |
wolfSSL | 11:cee25a834751 | 30 | extern "C" { |
wolfSSL | 11:cee25a834751 | 31 | #endif |
wolfSSL | 11:cee25a834751 | 32 | |
wolfSSL | 11:cee25a834751 | 33 | |
wolfSSL | 11:cee25a834751 | 34 | #ifdef USE_WINDOWS_API |
wolfSSL | 11:cee25a834751 | 35 | #ifdef WOLFSSL_GAME_BUILD |
wolfSSL | 11:cee25a834751 | 36 | #include "system/xtl.h" |
wolfSSL | 11:cee25a834751 | 37 | #else |
wolfSSL | 11:cee25a834751 | 38 | #ifndef WIN32_LEAN_AND_MEAN |
wolfSSL | 11:cee25a834751 | 39 | #define WIN32_LEAN_AND_MEAN |
wolfSSL | 11:cee25a834751 | 40 | #endif |
wolfSSL | 11:cee25a834751 | 41 | #ifndef WOLFSSL_SGX |
wolfSSL | 11:cee25a834751 | 42 | #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN) |
wolfSSL | 11:cee25a834751 | 43 | /* On WinCE winsock2.h must be included before windows.h */ |
wolfSSL | 11:cee25a834751 | 44 | #include <winsock2.h> |
wolfSSL | 11:cee25a834751 | 45 | #endif |
wolfSSL | 11:cee25a834751 | 46 | #include <windows.h> |
wolfSSL | 11:cee25a834751 | 47 | #endif /* WOLFSSL_SGX */ |
wolfSSL | 11:cee25a834751 | 48 | #endif |
wolfSSL | 11:cee25a834751 | 49 | #elif defined(THREADX) |
wolfSSL | 11:cee25a834751 | 50 | #ifndef SINGLE_THREADED |
wolfSSL | 11:cee25a834751 | 51 | #include "tx_api.h" |
wolfSSL | 11:cee25a834751 | 52 | #endif |
wolfSSL | 11:cee25a834751 | 53 | #elif defined(MICRIUM) |
wolfSSL | 11:cee25a834751 | 54 | /* do nothing, just don't pick Unix */ |
wolfSSL | 11:cee25a834751 | 55 | #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS) |
wolfSSL | 11:cee25a834751 | 56 | /* do nothing */ |
wolfSSL | 11:cee25a834751 | 57 | #elif defined(EBSNET) |
wolfSSL | 11:cee25a834751 | 58 | /* do nothing */ |
wolfSSL | 11:cee25a834751 | 59 | #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) |
wolfSSL | 11:cee25a834751 | 60 | /* do nothing */ |
wolfSSL | 11:cee25a834751 | 61 | #elif defined(FREESCALE_FREE_RTOS) |
wolfSSL | 11:cee25a834751 | 62 | #include "fsl_os_abstraction.h" |
wolfSSL | 11:cee25a834751 | 63 | #elif defined(WOLFSSL_uITRON4) |
wolfSSL | 11:cee25a834751 | 64 | #include "stddef.h" |
wolfSSL | 11:cee25a834751 | 65 | #include "kernel.h" |
wolfSSL | 11:cee25a834751 | 66 | #elif defined(WOLFSSL_uTKERNEL2) |
wolfSSL | 11:cee25a834751 | 67 | #include "tk/tkernel.h" |
wolfSSL | 11:cee25a834751 | 68 | #elif defined(WOLFSSL_MDK_ARM) |
wolfSSL | 11:cee25a834751 | 69 | #if defined(WOLFSSL_MDK5) |
wolfSSL | 11:cee25a834751 | 70 | #include "cmsis_os.h" |
wolfSSL | 11:cee25a834751 | 71 | #else |
wolfSSL | 11:cee25a834751 | 72 | #include <rtl.h> |
wolfSSL | 11:cee25a834751 | 73 | #endif |
wolfSSL | 11:cee25a834751 | 74 | #elif defined(WOLFSSL_CMSIS_RTOS) |
wolfSSL | 11:cee25a834751 | 75 | #include "cmsis_os.h" |
wolfSSL | 11:cee25a834751 | 76 | #elif defined(WOLFSSL_TIRTOS) |
wolfSSL | 11:cee25a834751 | 77 | #include <ti/sysbios/BIOS.h> |
wolfSSL | 11:cee25a834751 | 78 | #include <ti/sysbios/knl/Semaphore.h> |
wolfSSL | 11:cee25a834751 | 79 | #elif defined(WOLFSSL_FROSTED) |
wolfSSL | 11:cee25a834751 | 80 | #include <semaphore.h> |
wolfSSL | 11:cee25a834751 | 81 | #elif defined(INTIME_RTOS) |
wolfSSL | 11:cee25a834751 | 82 | #include <rt.h> |
wolfSSL | 11:cee25a834751 | 83 | #include <io.h> |
wolfSSL | 11:cee25a834751 | 84 | #else |
wolfSSL | 11:cee25a834751 | 85 | #ifndef SINGLE_THREADED |
wolfSSL | 11:cee25a834751 | 86 | #define WOLFSSL_PTHREADS |
wolfSSL | 11:cee25a834751 | 87 | #include <pthread.h> |
wolfSSL | 11:cee25a834751 | 88 | #endif |
wolfSSL | 11:cee25a834751 | 89 | #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS) |
wolfSSL | 11:cee25a834751 | 90 | #include <unistd.h> /* for close of BIO */ |
wolfSSL | 11:cee25a834751 | 91 | #endif |
wolfSSL | 11:cee25a834751 | 92 | #endif |
wolfSSL | 11:cee25a834751 | 93 | |
wolfSSL | 11:cee25a834751 | 94 | /* For FIPS keep the function names the same */ |
wolfSSL | 11:cee25a834751 | 95 | #ifdef HAVE_FIPS |
wolfSSL | 11:cee25a834751 | 96 | #define wc_InitMutex InitMutex |
wolfSSL | 11:cee25a834751 | 97 | #define wc_FreeMutex FreeMutex |
wolfSSL | 11:cee25a834751 | 98 | #define wc_LockMutex LockMutex |
wolfSSL | 11:cee25a834751 | 99 | #define wc_UnLockMutex UnLockMutex |
wolfSSL | 11:cee25a834751 | 100 | #endif /* HAVE_FIPS */ |
wolfSSL | 11:cee25a834751 | 101 | |
wolfSSL | 11:cee25a834751 | 102 | #ifdef SINGLE_THREADED |
wolfSSL | 11:cee25a834751 | 103 | typedef int wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 104 | #else /* MULTI_THREADED */ |
wolfSSL | 11:cee25a834751 | 105 | /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */ |
wolfSSL | 11:cee25a834751 | 106 | #if defined(FREERTOS) |
wolfSSL | 11:cee25a834751 | 107 | typedef xSemaphoreHandle wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 108 | #elif defined(FREERTOS_TCP) |
wolfSSL | 11:cee25a834751 | 109 | #include "FreeRTOS.h" |
wolfSSL | 11:cee25a834751 | 110 | #include "semphr.h" |
wolfSSL | 11:cee25a834751 | 111 | typedef SemaphoreHandle_t wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 112 | #elif defined(WOLFSSL_SAFERTOS) |
wolfSSL | 11:cee25a834751 | 113 | typedef struct wolfSSL_Mutex { |
wolfSSL | 11:cee25a834751 | 114 | signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES]; |
wolfSSL | 11:cee25a834751 | 115 | xSemaphoreHandle mutex; |
wolfSSL | 11:cee25a834751 | 116 | } wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 117 | #elif defined(USE_WINDOWS_API) |
wolfSSL | 11:cee25a834751 | 118 | typedef CRITICAL_SECTION wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 119 | #elif defined(WOLFSSL_PTHREADS) |
wolfSSL | 11:cee25a834751 | 120 | typedef pthread_mutex_t wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 121 | #elif defined(THREADX) |
wolfSSL | 11:cee25a834751 | 122 | typedef TX_MUTEX wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 123 | #elif defined(MICRIUM) |
wolfSSL | 11:cee25a834751 | 124 | typedef OS_MUTEX wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 125 | #elif defined(EBSNET) |
wolfSSL | 11:cee25a834751 | 126 | typedef RTP_MUTEX wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 127 | #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) |
wolfSSL | 11:cee25a834751 | 128 | typedef MUTEX_STRUCT wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 129 | #elif defined(FREESCALE_FREE_RTOS) |
wolfSSL | 11:cee25a834751 | 130 | typedef mutex_t wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 131 | #elif defined(WOLFSSL_uITRON4) |
wolfSSL | 11:cee25a834751 | 132 | typedef struct wolfSSL_Mutex { |
wolfSSL | 11:cee25a834751 | 133 | T_CSEM sem ; |
wolfSSL | 11:cee25a834751 | 134 | ID id ; |
wolfSSL | 11:cee25a834751 | 135 | } wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 136 | #elif defined(WOLFSSL_uTKERNEL2) |
wolfSSL | 11:cee25a834751 | 137 | typedef struct wolfSSL_Mutex { |
wolfSSL | 11:cee25a834751 | 138 | T_CSEM sem ; |
wolfSSL | 11:cee25a834751 | 139 | ID id ; |
wolfSSL | 11:cee25a834751 | 140 | } wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 141 | #elif defined(WOLFSSL_MDK_ARM) |
wolfSSL | 11:cee25a834751 | 142 | #if defined(WOLFSSL_CMSIS_RTOS) |
wolfSSL | 11:cee25a834751 | 143 | typedef osMutexId wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 144 | #else |
wolfSSL | 11:cee25a834751 | 145 | typedef OS_MUT wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 146 | #endif |
wolfSSL | 11:cee25a834751 | 147 | #elif defined(WOLFSSL_CMSIS_RTOS) |
wolfSSL | 11:cee25a834751 | 148 | typedef osMutexId wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 149 | #elif defined(WOLFSSL_TIRTOS) |
wolfSSL | 11:cee25a834751 | 150 | typedef ti_sysbios_knl_Semaphore_Handle wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 151 | #elif defined(WOLFSSL_FROSTED) |
wolfSSL | 11:cee25a834751 | 152 | typedef mutex_t * wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 153 | #elif defined(INTIME_RTOS) |
wolfSSL | 11:cee25a834751 | 154 | typedef RTHANDLE wolfSSL_Mutex; |
wolfSSL | 11:cee25a834751 | 155 | #else |
wolfSSL | 11:cee25a834751 | 156 | #error Need a mutex type in multithreaded mode |
wolfSSL | 11:cee25a834751 | 157 | #endif /* USE_WINDOWS_API */ |
wolfSSL | 11:cee25a834751 | 158 | #endif /* SINGLE_THREADED */ |
wolfSSL | 11:cee25a834751 | 159 | |
wolfSSL | 11:cee25a834751 | 160 | /* Enable crypt HW mutex for Freescale MMCAU */ |
wolfSSL | 11:cee25a834751 | 161 | #if defined(FREESCALE_MMCAU) |
wolfSSL | 11:cee25a834751 | 162 | #ifndef WOLFSSL_CRYPT_HW_MUTEX |
wolfSSL | 11:cee25a834751 | 163 | #define WOLFSSL_CRYPT_HW_MUTEX 1 |
wolfSSL | 11:cee25a834751 | 164 | #endif |
wolfSSL | 11:cee25a834751 | 165 | #endif /* FREESCALE_MMCAU */ |
wolfSSL | 11:cee25a834751 | 166 | |
wolfSSL | 11:cee25a834751 | 167 | #ifndef WOLFSSL_CRYPT_HW_MUTEX |
wolfSSL | 11:cee25a834751 | 168 | #define WOLFSSL_CRYPT_HW_MUTEX 0 |
wolfSSL | 11:cee25a834751 | 169 | #endif |
wolfSSL | 11:cee25a834751 | 170 | |
wolfSSL | 11:cee25a834751 | 171 | #if WOLFSSL_CRYPT_HW_MUTEX |
wolfSSL | 11:cee25a834751 | 172 | /* wolfSSL_CryptHwMutexInit is called on first wolfSSL_CryptHwMutexLock, |
wolfSSL | 11:cee25a834751 | 173 | however it's recommended to call this directly on Hw init to avoid possible |
wolfSSL | 11:cee25a834751 | 174 | race condition where two calls to wolfSSL_CryptHwMutexLock are made at |
wolfSSL | 11:cee25a834751 | 175 | the same time. */ |
wolfSSL | 11:cee25a834751 | 176 | int wolfSSL_CryptHwMutexInit(void); |
wolfSSL | 11:cee25a834751 | 177 | int wolfSSL_CryptHwMutexLock(void); |
wolfSSL | 11:cee25a834751 | 178 | int wolfSSL_CryptHwMutexUnLock(void); |
wolfSSL | 11:cee25a834751 | 179 | #else |
wolfSSL | 11:cee25a834751 | 180 | /* Define stubs, since HW mutex is disabled */ |
wolfSSL | 11:cee25a834751 | 181 | #define wolfSSL_CryptHwMutexInit() 0 /* Success */ |
wolfSSL | 11:cee25a834751 | 182 | #define wolfSSL_CryptHwMutexLock() 0 /* Success */ |
wolfSSL | 11:cee25a834751 | 183 | #define wolfSSL_CryptHwMutexUnLock() 0 /* Success */ |
wolfSSL | 11:cee25a834751 | 184 | #endif /* WOLFSSL_CRYPT_HW_MUTEX */ |
wolfSSL | 11:cee25a834751 | 185 | |
wolfSSL | 11:cee25a834751 | 186 | /* Mutex functions */ |
wolfSSL | 11:cee25a834751 | 187 | WOLFSSL_API int wc_InitMutex(wolfSSL_Mutex*); |
wolfSSL | 11:cee25a834751 | 188 | WOLFSSL_API wolfSSL_Mutex* wc_InitAndAllocMutex(void); |
wolfSSL | 11:cee25a834751 | 189 | WOLFSSL_API int wc_FreeMutex(wolfSSL_Mutex*); |
wolfSSL | 11:cee25a834751 | 190 | WOLFSSL_API int wc_LockMutex(wolfSSL_Mutex*); |
wolfSSL | 11:cee25a834751 | 191 | WOLFSSL_API int wc_UnLockMutex(wolfSSL_Mutex*); |
wolfSSL | 11:cee25a834751 | 192 | |
wolfSSL | 11:cee25a834751 | 193 | /* main crypto initialization function */ |
wolfSSL | 11:cee25a834751 | 194 | WOLFSSL_API int wolfCrypt_Init(void); |
wolfSSL | 11:cee25a834751 | 195 | WOLFSSL_API int wolfCrypt_Cleanup(void); |
wolfSSL | 11:cee25a834751 | 196 | |
wolfSSL | 11:cee25a834751 | 197 | /* filesystem abstraction layer, used by ssl.c */ |
wolfSSL | 11:cee25a834751 | 198 | #ifndef NO_FILESYSTEM |
wolfSSL | 11:cee25a834751 | 199 | |
wolfSSL | 11:cee25a834751 | 200 | #if defined(EBSNET) |
wolfSSL | 11:cee25a834751 | 201 | #include "vfapi.h" |
wolfSSL | 11:cee25a834751 | 202 | #include "vfile.h" |
wolfSSL | 11:cee25a834751 | 203 | |
wolfSSL | 11:cee25a834751 | 204 | #define XFILE int |
wolfSSL | 11:cee25a834751 | 205 | #define XFOPEN(NAME, MODE) vf_open((const char *)NAME, VO_RDONLY, 0); |
wolfSSL | 11:cee25a834751 | 206 | #define XFSEEK vf_lseek |
wolfSSL | 11:cee25a834751 | 207 | #define XFTELL vf_tell |
wolfSSL | 11:cee25a834751 | 208 | #define XREWIND vf_rewind |
wolfSSL | 11:cee25a834751 | 209 | #define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT) |
wolfSSL | 11:cee25a834751 | 210 | #define XFWRITE(BUF, SZ, AMT, FD) vf_write(FD, BUF, SZ*AMT) |
wolfSSL | 11:cee25a834751 | 211 | #define XFCLOSE vf_close |
wolfSSL | 11:cee25a834751 | 212 | #define XSEEK_END VSEEK_END |
wolfSSL | 11:cee25a834751 | 213 | #define XBADFILE -1 |
wolfSSL | 11:cee25a834751 | 214 | #define XFGETS(b,s,f) -2 /* Not ported yet */ |
wolfSSL | 11:cee25a834751 | 215 | #elif defined(LSR_FS) |
wolfSSL | 11:cee25a834751 | 216 | #include <fs.h> |
wolfSSL | 11:cee25a834751 | 217 | #define XFILE struct fs_file* |
wolfSSL | 11:cee25a834751 | 218 | #define XFOPEN(NAME, MODE) fs_open((char*)NAME); |
wolfSSL | 11:cee25a834751 | 219 | #define XFSEEK(F, O, W) (void)F |
wolfSSL | 11:cee25a834751 | 220 | #define XFTELL(F) (F)->len |
wolfSSL | 11:cee25a834751 | 221 | #define XREWIND(F) (void)F |
wolfSSL | 11:cee25a834751 | 222 | #define XFREAD(BUF, SZ, AMT, F) fs_read(F, (char*)BUF, SZ*AMT) |
wolfSSL | 11:cee25a834751 | 223 | #define XFWRITE(BUF, SZ, AMT, F) fs_write(F, (char*)BUF, SZ*AMT) |
wolfSSL | 11:cee25a834751 | 224 | #define XFCLOSE fs_close |
wolfSSL | 11:cee25a834751 | 225 | #define XSEEK_END 0 |
wolfSSL | 11:cee25a834751 | 226 | #define XBADFILE NULL |
wolfSSL | 11:cee25a834751 | 227 | #define XFGETS(b,s,f) -2 /* Not ported yet */ |
wolfSSL | 11:cee25a834751 | 228 | #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) |
wolfSSL | 11:cee25a834751 | 229 | #define XFILE MQX_FILE_PTR |
wolfSSL | 11:cee25a834751 | 230 | #define XFOPEN fopen |
wolfSSL | 11:cee25a834751 | 231 | #define XFSEEK fseek |
wolfSSL | 11:cee25a834751 | 232 | #define XFTELL ftell |
wolfSSL | 11:cee25a834751 | 233 | #define XREWIND(F) fseek(F, 0, IO_SEEK_SET) |
wolfSSL | 11:cee25a834751 | 234 | #define XFREAD fread |
wolfSSL | 11:cee25a834751 | 235 | #define XFWRITE fwrite |
wolfSSL | 11:cee25a834751 | 236 | #define XFCLOSE fclose |
wolfSSL | 11:cee25a834751 | 237 | #define XSEEK_END IO_SEEK_END |
wolfSSL | 11:cee25a834751 | 238 | #define XBADFILE NULL |
wolfSSL | 11:cee25a834751 | 239 | #define XFGETS fgets |
wolfSSL | 11:cee25a834751 | 240 | #elif defined(MICRIUM) |
wolfSSL | 11:cee25a834751 | 241 | #include <fs.h> |
wolfSSL | 11:cee25a834751 | 242 | #define XFILE FS_FILE* |
wolfSSL | 11:cee25a834751 | 243 | #define XFOPEN fs_fopen |
wolfSSL | 11:cee25a834751 | 244 | #define XFSEEK fs_fseek |
wolfSSL | 11:cee25a834751 | 245 | #define XFTELL fs_ftell |
wolfSSL | 11:cee25a834751 | 246 | #define XREWIND fs_rewind |
wolfSSL | 11:cee25a834751 | 247 | #define XFREAD fs_fread |
wolfSSL | 11:cee25a834751 | 248 | #define XFWRITE fs_fwrite |
wolfSSL | 11:cee25a834751 | 249 | #define XFCLOSE fs_fclose |
wolfSSL | 11:cee25a834751 | 250 | #define XSEEK_END FS_SEEK_END |
wolfSSL | 11:cee25a834751 | 251 | #define XBADFILE NULL |
wolfSSL | 11:cee25a834751 | 252 | #define XFGETS(b,s,f) -2 /* Not ported yet */ |
wolfSSL | 11:cee25a834751 | 253 | #else |
wolfSSL | 11:cee25a834751 | 254 | /* stdio, default case */ |
wolfSSL | 11:cee25a834751 | 255 | #include <stdio.h> |
wolfSSL | 11:cee25a834751 | 256 | #define XFILE FILE* |
wolfSSL | 11:cee25a834751 | 257 | #if defined(WOLFSSL_MDK_ARM) |
wolfSSL | 11:cee25a834751 | 258 | extern FILE * wolfSSL_fopen(const char *name, const char *mode) ; |
wolfSSL | 11:cee25a834751 | 259 | #define XFOPEN wolfSSL_fopen |
wolfSSL | 11:cee25a834751 | 260 | #else |
wolfSSL | 11:cee25a834751 | 261 | #define XFOPEN fopen |
wolfSSL | 11:cee25a834751 | 262 | #endif |
wolfSSL | 11:cee25a834751 | 263 | #define XFSEEK fseek |
wolfSSL | 11:cee25a834751 | 264 | #define XFTELL ftell |
wolfSSL | 11:cee25a834751 | 265 | #define XREWIND rewind |
wolfSSL | 11:cee25a834751 | 266 | #define XFREAD fread |
wolfSSL | 11:cee25a834751 | 267 | #define XFWRITE fwrite |
wolfSSL | 11:cee25a834751 | 268 | #define XFCLOSE fclose |
wolfSSL | 11:cee25a834751 | 269 | #define XSEEK_END SEEK_END |
wolfSSL | 11:cee25a834751 | 270 | #define XBADFILE NULL |
wolfSSL | 11:cee25a834751 | 271 | #define XFGETS fgets |
wolfSSL | 11:cee25a834751 | 272 | |
wolfSSL | 11:cee25a834751 | 273 | #if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR) |
wolfSSL | 11:cee25a834751 | 274 | #include <dirent.h> |
wolfSSL | 11:cee25a834751 | 275 | #include <unistd.h> |
wolfSSL | 11:cee25a834751 | 276 | #include <sys/stat.h> |
wolfSSL | 11:cee25a834751 | 277 | #endif |
wolfSSL | 11:cee25a834751 | 278 | #endif |
wolfSSL | 11:cee25a834751 | 279 | |
wolfSSL | 11:cee25a834751 | 280 | #ifndef MAX_FILENAME_SZ |
wolfSSL | 11:cee25a834751 | 281 | #define MAX_FILENAME_SZ 256 /* max file name length */ |
wolfSSL | 11:cee25a834751 | 282 | #endif |
wolfSSL | 11:cee25a834751 | 283 | #ifndef MAX_PATH |
wolfSSL | 11:cee25a834751 | 284 | #define MAX_PATH 256 |
wolfSSL | 11:cee25a834751 | 285 | #endif |
wolfSSL | 11:cee25a834751 | 286 | |
wolfSSL | 11:cee25a834751 | 287 | #if !defined(NO_WOLFSSL_DIR) |
wolfSSL | 11:cee25a834751 | 288 | typedef struct ReadDirCtx { |
wolfSSL | 11:cee25a834751 | 289 | #ifdef USE_WINDOWS_API |
wolfSSL | 11:cee25a834751 | 290 | WIN32_FIND_DATAA FindFileData; |
wolfSSL | 11:cee25a834751 | 291 | HANDLE hFind; |
wolfSSL | 11:cee25a834751 | 292 | #else |
wolfSSL | 11:cee25a834751 | 293 | struct dirent* entry; |
wolfSSL | 11:cee25a834751 | 294 | DIR* dir; |
wolfSSL | 11:cee25a834751 | 295 | struct stat s; |
wolfSSL | 11:cee25a834751 | 296 | #endif |
wolfSSL | 11:cee25a834751 | 297 | char name[MAX_FILENAME_SZ]; |
wolfSSL | 11:cee25a834751 | 298 | } ReadDirCtx; |
wolfSSL | 11:cee25a834751 | 299 | |
wolfSSL | 11:cee25a834751 | 300 | WOLFSSL_API int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name); |
wolfSSL | 11:cee25a834751 | 301 | WOLFSSL_API int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name); |
wolfSSL | 11:cee25a834751 | 302 | WOLFSSL_API void wc_ReadDirClose(ReadDirCtx* ctx); |
wolfSSL | 11:cee25a834751 | 303 | #endif /* !NO_WOLFSSL_DIR */ |
wolfSSL | 11:cee25a834751 | 304 | |
wolfSSL | 11:cee25a834751 | 305 | #endif /* !NO_FILESYSTEM */ |
wolfSSL | 11:cee25a834751 | 306 | |
wolfSSL | 11:cee25a834751 | 307 | |
wolfSSL | 11:cee25a834751 | 308 | /* Windows API defines its own min() macro. */ |
wolfSSL | 11:cee25a834751 | 309 | #if defined(USE_WINDOWS_API) |
wolfSSL | 11:cee25a834751 | 310 | #if defined(min) || defined(WOLFSSL_MYSQL_COMPATIBLE) |
wolfSSL | 11:cee25a834751 | 311 | #define WOLFSSL_HAVE_MIN |
wolfSSL | 11:cee25a834751 | 312 | #endif /* min */ |
wolfSSL | 11:cee25a834751 | 313 | #if defined(max) || defined(WOLFSSL_MYSQL_COMPATIBLE) |
wolfSSL | 11:cee25a834751 | 314 | #define WOLFSSL_HAVE_MAX |
wolfSSL | 11:cee25a834751 | 315 | #endif /* max */ |
wolfSSL | 11:cee25a834751 | 316 | #endif /* USE_WINDOWS_API */ |
wolfSSL | 11:cee25a834751 | 317 | |
wolfSSL | 11:cee25a834751 | 318 | |
wolfSSL | 11:cee25a834751 | 319 | #ifdef __cplusplus |
wolfSSL | 11:cee25a834751 | 320 | } /* extern "C" */ |
wolfSSL | 11:cee25a834751 | 321 | #endif |
wolfSSL | 11:cee25a834751 | 322 | |
wolfSSL | 11:cee25a834751 | 323 | #endif /* WOLF_CRYPT_PORT_H */ |
wolfSSL | 11:cee25a834751 | 324 | |
wolfSSL | 11:cee25a834751 | 325 |