ssh lib

Dependents:   OS

Committer:
sPymbed
Date:
Mon Nov 25 14:23:49 2019 +0000
Revision:
1:e4ea39eba2fb
Parent:
0:1387ff3eed4a
improved

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sPymbed 0:1387ff3eed4a 1 /* wc_port.h
sPymbed 0:1387ff3eed4a 2 *
sPymbed 0:1387ff3eed4a 3 * Copyright (C) 2006-2017 wolfSSL Inc.
sPymbed 0:1387ff3eed4a 4 *
sPymbed 0:1387ff3eed4a 5 * This file is part of wolfSSL.
sPymbed 0:1387ff3eed4a 6 *
sPymbed 0:1387ff3eed4a 7 * wolfSSL is free software; you can redistribute it and/or modify
sPymbed 0:1387ff3eed4a 8 * it under the terms of the GNU General Public License as published by
sPymbed 0:1387ff3eed4a 9 * the Free Software Foundation; either version 2 of the License, or
sPymbed 0:1387ff3eed4a 10 * (at your option) any later version.
sPymbed 0:1387ff3eed4a 11 *
sPymbed 0:1387ff3eed4a 12 * wolfSSL is distributed in the hope that it will be useful,
sPymbed 0:1387ff3eed4a 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sPymbed 0:1387ff3eed4a 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
sPymbed 0:1387ff3eed4a 15 * GNU General Public License for more details.
sPymbed 0:1387ff3eed4a 16 *
sPymbed 0:1387ff3eed4a 17 * You should have received a copy of the GNU General Public License
sPymbed 0:1387ff3eed4a 18 * along with this program; if not, write to the Free Software
sPymbed 0:1387ff3eed4a 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
sPymbed 0:1387ff3eed4a 20 */
sPymbed 0:1387ff3eed4a 21
sPymbed 0:1387ff3eed4a 22 /*!
sPymbed 0:1387ff3eed4a 23 \file wolfssl/wolfcrypt/wc_port.h
sPymbed 0:1387ff3eed4a 24 */
sPymbed 0:1387ff3eed4a 25
sPymbed 0:1387ff3eed4a 26 #ifndef WOLF_CRYPT_PORT_H
sPymbed 0:1387ff3eed4a 27 #define WOLF_CRYPT_PORT_H
sPymbed 0:1387ff3eed4a 28
sPymbed 0:1387ff3eed4a 29 #include <wolfcrypt/settings.h>
sPymbed 0:1387ff3eed4a 30 #include <wolfcrypt/visibility.h>
sPymbed 0:1387ff3eed4a 31
sPymbed 0:1387ff3eed4a 32 #ifdef __cplusplus
sPymbed 0:1387ff3eed4a 33 extern "C" {
sPymbed 0:1387ff3eed4a 34 #endif
sPymbed 0:1387ff3eed4a 35
sPymbed 0:1387ff3eed4a 36 /* Detect if compiler supports C99. "NO_WOLF_C99" can be defined in
sPymbed 0:1387ff3eed4a 37 * user_settings.h to disable checking for C99 support. */
sPymbed 0:1387ff3eed4a 38 #if !defined(WOLF_C99) && defined(__STDC_VERSION__) && \
sPymbed 0:1387ff3eed4a 39 !defined(WOLFSSL_ARDUINO) && !defined(NO_WOLF_C99)
sPymbed 0:1387ff3eed4a 40 #if __STDC_VERSION__ >= 199901L
sPymbed 0:1387ff3eed4a 41 #define WOLF_C99
sPymbed 0:1387ff3eed4a 42 #endif
sPymbed 0:1387ff3eed4a 43 #endif
sPymbed 0:1387ff3eed4a 44
sPymbed 0:1387ff3eed4a 45 #ifdef USE_WINDOWS_API
sPymbed 0:1387ff3eed4a 46 #ifdef WOLFSSL_GAME_BUILD
sPymbed 0:1387ff3eed4a 47 #include "system/xtl.h"
sPymbed 0:1387ff3eed4a 48 #else
sPymbed 0:1387ff3eed4a 49 #ifndef WIN32_LEAN_AND_MEAN
sPymbed 0:1387ff3eed4a 50 #define WIN32_LEAN_AND_MEAN
sPymbed 0:1387ff3eed4a 51 #endif
sPymbed 0:1387ff3eed4a 52 #ifndef WOLFSSL_SGX
sPymbed 0:1387ff3eed4a 53 #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
sPymbed 0:1387ff3eed4a 54 /* On WinCE winsock2.h must be included before windows.h */
sPymbed 0:1387ff3eed4a 55 #include <winsock2.h>
sPymbed 0:1387ff3eed4a 56 #endif
sPymbed 0:1387ff3eed4a 57 #include <windows.h>
sPymbed 0:1387ff3eed4a 58 #endif /* WOLFSSL_SGX */
sPymbed 0:1387ff3eed4a 59 #endif
sPymbed 0:1387ff3eed4a 60 #elif defined(THREADX)
sPymbed 0:1387ff3eed4a 61 #ifndef SINGLE_THREADED
sPymbed 0:1387ff3eed4a 62 #ifdef NEED_THREADX_TYPES
sPymbed 0:1387ff3eed4a 63 #include <types.h>
sPymbed 0:1387ff3eed4a 64 #endif
sPymbed 0:1387ff3eed4a 65 #include <tx_api.h>
sPymbed 0:1387ff3eed4a 66 #endif
sPymbed 0:1387ff3eed4a 67 #elif defined(MICRIUM)
sPymbed 0:1387ff3eed4a 68 /* do nothing, just don't pick Unix */
sPymbed 0:1387ff3eed4a 69 #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS)
sPymbed 0:1387ff3eed4a 70 /* do nothing */
sPymbed 0:1387ff3eed4a 71 #elif defined(EBSNET)
sPymbed 0:1387ff3eed4a 72 /* do nothing */
sPymbed 0:1387ff3eed4a 73 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
sPymbed 0:1387ff3eed4a 74 /* do nothing */
sPymbed 0:1387ff3eed4a 75 #elif defined(FREESCALE_FREE_RTOS)
sPymbed 0:1387ff3eed4a 76 #include "fsl_os_abstraction.h"
sPymbed 0:1387ff3eed4a 77 #elif defined(WOLFSSL_uITRON4)
sPymbed 0:1387ff3eed4a 78 #include "stddef.h"
sPymbed 0:1387ff3eed4a 79 #include "kernel.h"
sPymbed 0:1387ff3eed4a 80 #elif defined(WOLFSSL_uTKERNEL2)
sPymbed 0:1387ff3eed4a 81 #include "tk/tkernel.h"
sPymbed 0:1387ff3eed4a 82 #elif defined(WOLFSSL_CMSIS_RTOS)
sPymbed 0:1387ff3eed4a 83 #include "cmsis_os.h"
sPymbed 0:1387ff3eed4a 84 #elif defined(WOLFSSL_MDK_ARM)
sPymbed 0:1387ff3eed4a 85 #if defined(WOLFSSL_MDK5)
sPymbed 0:1387ff3eed4a 86 #include "cmsis_os.h"
sPymbed 0:1387ff3eed4a 87 #else
sPymbed 0:1387ff3eed4a 88 #include <rtl.h>
sPymbed 0:1387ff3eed4a 89 #endif
sPymbed 0:1387ff3eed4a 90 #elif defined(WOLFSSL_CMSIS_RTOS)
sPymbed 0:1387ff3eed4a 91 #include "cmsis_os.h"
sPymbed 0:1387ff3eed4a 92 #elif defined(WOLFSSL_TIRTOS)
sPymbed 0:1387ff3eed4a 93 #include <ti/sysbios/BIOS.h>
sPymbed 0:1387ff3eed4a 94 #include <ti/sysbios/knl/Semaphore.h>
sPymbed 0:1387ff3eed4a 95 #elif defined(WOLFSSL_FROSTED)
sPymbed 0:1387ff3eed4a 96 #include <semaphore.h>
sPymbed 0:1387ff3eed4a 97 #elif defined(INTIME_RTOS)
sPymbed 0:1387ff3eed4a 98 #include <rt.h>
sPymbed 0:1387ff3eed4a 99 #include <io.h>
sPymbed 0:1387ff3eed4a 100 #elif defined(WOLFSSL_NUCLEUS_1_2)
sPymbed 0:1387ff3eed4a 101 /* NU_DEBUG needed struct access in nucleus_realloc */
sPymbed 0:1387ff3eed4a 102 #define NU_DEBUG
sPymbed 0:1387ff3eed4a 103 #include "plus/nucleus.h"
sPymbed 0:1387ff3eed4a 104 #include "nucleus.h"
sPymbed 0:1387ff3eed4a 105 #else
sPymbed 0:1387ff3eed4a 106 #ifndef SINGLE_THREADED
sPymbed 0:1387ff3eed4a 107 #define WOLFSSL_PTHREADS
sPymbed 0:1387ff3eed4a 108 #include <pthread.h>
sPymbed 0:1387ff3eed4a 109 #endif
sPymbed 0:1387ff3eed4a 110 #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)
sPymbed 0:1387ff3eed4a 111 #include <unistd.h> /* for close of BIO */
sPymbed 0:1387ff3eed4a 112 #endif
sPymbed 0:1387ff3eed4a 113 #endif
sPymbed 0:1387ff3eed4a 114
sPymbed 0:1387ff3eed4a 115 /* For FIPS keep the function names the same */
sPymbed 0:1387ff3eed4a 116 #ifdef HAVE_FIPS
sPymbed 0:1387ff3eed4a 117 #define wc_InitMutex InitMutex
sPymbed 0:1387ff3eed4a 118 #define wc_FreeMutex FreeMutex
sPymbed 0:1387ff3eed4a 119 #define wc_LockMutex LockMutex
sPymbed 0:1387ff3eed4a 120 #define wc_UnLockMutex UnLockMutex
sPymbed 0:1387ff3eed4a 121 #endif /* HAVE_FIPS */
sPymbed 0:1387ff3eed4a 122
sPymbed 0:1387ff3eed4a 123 #ifdef SINGLE_THREADED
sPymbed 0:1387ff3eed4a 124 typedef int wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 125 #else /* MULTI_THREADED */
sPymbed 0:1387ff3eed4a 126 /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */
sPymbed 0:1387ff3eed4a 127 #if defined(FREERTOS)
sPymbed 0:1387ff3eed4a 128 typedef xSemaphoreHandle wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 129 #elif defined(FREERTOS_TCP)
sPymbed 0:1387ff3eed4a 130 #include "FreeRTOS.h"
sPymbed 0:1387ff3eed4a 131 #include "semphr.h"
sPymbed 0:1387ff3eed4a 132 typedef SemaphoreHandle_t wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 133 #elif defined(WOLFSSL_SAFERTOS)
sPymbed 0:1387ff3eed4a 134 typedef struct wolfSSL_Mutex {
sPymbed 0:1387ff3eed4a 135 signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES];
sPymbed 0:1387ff3eed4a 136 xSemaphoreHandle mutex;
sPymbed 0:1387ff3eed4a 137 } wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 138 #elif defined(USE_WINDOWS_API)
sPymbed 0:1387ff3eed4a 139 typedef CRITICAL_SECTION wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 140 #elif defined(WOLFSSL_PTHREADS)
sPymbed 0:1387ff3eed4a 141 typedef pthread_mutex_t wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 142 #elif defined(THREADX)
sPymbed 0:1387ff3eed4a 143 typedef TX_MUTEX wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 144 #elif defined(MICRIUM)
sPymbed 0:1387ff3eed4a 145 typedef OS_MUTEX wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 146 #elif defined(EBSNET)
sPymbed 0:1387ff3eed4a 147 typedef RTP_MUTEX wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 148 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
sPymbed 0:1387ff3eed4a 149 typedef MUTEX_STRUCT wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 150 #elif defined(FREESCALE_FREE_RTOS)
sPymbed 0:1387ff3eed4a 151 typedef mutex_t wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 152 #elif defined(WOLFSSL_uITRON4)
sPymbed 0:1387ff3eed4a 153 typedef struct wolfSSL_Mutex {
sPymbed 0:1387ff3eed4a 154 T_CSEM sem ;
sPymbed 0:1387ff3eed4a 155 ID id ;
sPymbed 0:1387ff3eed4a 156 } wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 157 #elif defined(WOLFSSL_uTKERNEL2)
sPymbed 0:1387ff3eed4a 158 typedef struct wolfSSL_Mutex {
sPymbed 0:1387ff3eed4a 159 T_CSEM sem ;
sPymbed 0:1387ff3eed4a 160 ID id ;
sPymbed 0:1387ff3eed4a 161 } wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 162 #elif defined(WOLFSSL_MDK_ARM)
sPymbed 0:1387ff3eed4a 163 #if defined(WOLFSSL_CMSIS_RTOS)
sPymbed 0:1387ff3eed4a 164 typedef osMutexId wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 165 #else
sPymbed 0:1387ff3eed4a 166 typedef OS_MUT wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 167 #endif
sPymbed 0:1387ff3eed4a 168 #elif defined(WOLFSSL_CMSIS_RTOS)
sPymbed 0:1387ff3eed4a 169 typedef osMutexId wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 170 #elif defined(WOLFSSL_TIRTOS)
sPymbed 0:1387ff3eed4a 171 typedef ti_sysbios_knl_Semaphore_Handle wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 172 #elif defined(WOLFSSL_FROSTED)
sPymbed 0:1387ff3eed4a 173 typedef mutex_t * wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 174 #elif defined(INTIME_RTOS)
sPymbed 0:1387ff3eed4a 175 typedef RTHANDLE wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 176 #elif defined(WOLFSSL_NUCLEUS_1_2)
sPymbed 0:1387ff3eed4a 177 typedef NU_SEMAPHORE wolfSSL_Mutex;
sPymbed 0:1387ff3eed4a 178 #else
sPymbed 0:1387ff3eed4a 179 #error Need a mutex type in multithreaded mode
sPymbed 0:1387ff3eed4a 180 #endif /* USE_WINDOWS_API */
sPymbed 0:1387ff3eed4a 181 #endif /* SINGLE_THREADED */
sPymbed 0:1387ff3eed4a 182
sPymbed 0:1387ff3eed4a 183 /* Enable crypt HW mutex for Freescale MMCAU or PIC32MZ */
sPymbed 0:1387ff3eed4a 184 #if defined(FREESCALE_MMCAU) || defined(WOLFSSL_MICROCHIP_PIC32MZ)
sPymbed 0:1387ff3eed4a 185 #ifndef WOLFSSL_CRYPT_HW_MUTEX
sPymbed 0:1387ff3eed4a 186 #define WOLFSSL_CRYPT_HW_MUTEX 1
sPymbed 0:1387ff3eed4a 187 #endif
sPymbed 0:1387ff3eed4a 188 #endif /* FREESCALE_MMCAU */
sPymbed 0:1387ff3eed4a 189
sPymbed 0:1387ff3eed4a 190 #ifndef WOLFSSL_CRYPT_HW_MUTEX
sPymbed 0:1387ff3eed4a 191 #define WOLFSSL_CRYPT_HW_MUTEX 0
sPymbed 0:1387ff3eed4a 192 #endif
sPymbed 0:1387ff3eed4a 193
sPymbed 0:1387ff3eed4a 194 #if WOLFSSL_CRYPT_HW_MUTEX
sPymbed 0:1387ff3eed4a 195 /* wolfSSL_CryptHwMutexInit is called on first wolfSSL_CryptHwMutexLock,
sPymbed 0:1387ff3eed4a 196 however it's recommended to call this directly on Hw init to avoid possible
sPymbed 0:1387ff3eed4a 197 race condition where two calls to wolfSSL_CryptHwMutexLock are made at
sPymbed 0:1387ff3eed4a 198 the same time. */
sPymbed 0:1387ff3eed4a 199 int wolfSSL_CryptHwMutexInit(void);
sPymbed 0:1387ff3eed4a 200 int wolfSSL_CryptHwMutexLock(void);
sPymbed 0:1387ff3eed4a 201 int wolfSSL_CryptHwMutexUnLock(void);
sPymbed 0:1387ff3eed4a 202 #else
sPymbed 0:1387ff3eed4a 203 /* Define stubs, since HW mutex is disabled */
sPymbed 0:1387ff3eed4a 204 #define wolfSSL_CryptHwMutexInit() 0 /* Success */
sPymbed 0:1387ff3eed4a 205 #define wolfSSL_CryptHwMutexLock() 0 /* Success */
sPymbed 0:1387ff3eed4a 206 #define wolfSSL_CryptHwMutexUnLock() (void)0 /* Success */
sPymbed 0:1387ff3eed4a 207 #endif /* WOLFSSL_CRYPT_HW_MUTEX */
sPymbed 0:1387ff3eed4a 208
sPymbed 0:1387ff3eed4a 209 /* Mutex functions */
sPymbed 0:1387ff3eed4a 210 WOLFSSL_API int wc_InitMutex(wolfSSL_Mutex*);
sPymbed 0:1387ff3eed4a 211 WOLFSSL_API wolfSSL_Mutex* wc_InitAndAllocMutex(void);
sPymbed 0:1387ff3eed4a 212 WOLFSSL_API int wc_FreeMutex(wolfSSL_Mutex*);
sPymbed 0:1387ff3eed4a 213 WOLFSSL_API int wc_LockMutex(wolfSSL_Mutex*);
sPymbed 0:1387ff3eed4a 214 WOLFSSL_API int wc_UnLockMutex(wolfSSL_Mutex*);
sPymbed 0:1387ff3eed4a 215 #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
sPymbed 0:1387ff3eed4a 216 /* dynamiclly set which mutex to use. unlock / lock is controlled by flag */
sPymbed 0:1387ff3eed4a 217 typedef void (mutex_cb)(int flag, int type, const char* file, int line);
sPymbed 0:1387ff3eed4a 218
sPymbed 0:1387ff3eed4a 219 WOLFSSL_API int wc_LockMutex_ex(int flag, int type, const char* file, int line);
sPymbed 0:1387ff3eed4a 220 WOLFSSL_API int wc_SetMutexCb(mutex_cb* cb);
sPymbed 0:1387ff3eed4a 221 #endif
sPymbed 0:1387ff3eed4a 222
sPymbed 0:1387ff3eed4a 223 /* main crypto initialization function */
sPymbed 0:1387ff3eed4a 224 WOLFSSL_API int wolfCrypt_Init(void);
sPymbed 0:1387ff3eed4a 225 WOLFSSL_API int wolfCrypt_Cleanup(void);
sPymbed 0:1387ff3eed4a 226
sPymbed 0:1387ff3eed4a 227 /* filesystem abstraction layer, used by ssl.c */
sPymbed 0:1387ff3eed4a 228 #ifndef NO_FILESYSTEM
sPymbed 0:1387ff3eed4a 229
sPymbed 0:1387ff3eed4a 230 #if defined(EBSNET)
sPymbed 0:1387ff3eed4a 231 #include "vfapi.h"
sPymbed 0:1387ff3eed4a 232 #include "vfile.h"
sPymbed 0:1387ff3eed4a 233
sPymbed 0:1387ff3eed4a 234 #define XFILE int
sPymbed 0:1387ff3eed4a 235 #define XFOPEN(NAME, MODE) vf_open((const char *)NAME, VO_RDONLY, 0);
sPymbed 0:1387ff3eed4a 236 #define XFSEEK vf_lseek
sPymbed 0:1387ff3eed4a 237 #define XFTELL vf_tell
sPymbed 0:1387ff3eed4a 238 #define XREWIND vf_rewind
sPymbed 0:1387ff3eed4a 239 #define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT)
sPymbed 0:1387ff3eed4a 240 #define XFWRITE(BUF, SZ, AMT, FD) vf_write(FD, BUF, SZ*AMT)
sPymbed 0:1387ff3eed4a 241 #define XFCLOSE vf_close
sPymbed 0:1387ff3eed4a 242 #define XSEEK_END VSEEK_END
sPymbed 0:1387ff3eed4a 243 #define XBADFILE -1
sPymbed 0:1387ff3eed4a 244 #define XFGETS(b,s,f) -2 /* Not ported yet */
sPymbed 0:1387ff3eed4a 245 #elif defined(LSR_FS)
sPymbed 0:1387ff3eed4a 246 #include <fs.h>
sPymbed 0:1387ff3eed4a 247 #define XFILE struct fs_file*
sPymbed 0:1387ff3eed4a 248 #define XFOPEN(NAME, MODE) fs_open((char*)NAME);
sPymbed 0:1387ff3eed4a 249 #define XFSEEK(F, O, W) (void)F
sPymbed 0:1387ff3eed4a 250 #define XFTELL(F) (F)->len
sPymbed 0:1387ff3eed4a 251 #define XREWIND(F) (void)F
sPymbed 0:1387ff3eed4a 252 #define XFREAD(BUF, SZ, AMT, F) fs_read(F, (char*)BUF, SZ*AMT)
sPymbed 0:1387ff3eed4a 253 #define XFWRITE(BUF, SZ, AMT, F) fs_write(F, (char*)BUF, SZ*AMT)
sPymbed 0:1387ff3eed4a 254 #define XFCLOSE fs_close
sPymbed 0:1387ff3eed4a 255 #define XSEEK_END 0
sPymbed 0:1387ff3eed4a 256 #define XBADFILE NULL
sPymbed 0:1387ff3eed4a 257 #define XFGETS(b,s,f) -2 /* Not ported yet */
sPymbed 0:1387ff3eed4a 258 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
sPymbed 0:1387ff3eed4a 259 #define XFILE MQX_FILE_PTR
sPymbed 0:1387ff3eed4a 260 #define XFOPEN fopen
sPymbed 0:1387ff3eed4a 261 #define XFSEEK fseek
sPymbed 0:1387ff3eed4a 262 #define XFTELL ftell
sPymbed 0:1387ff3eed4a 263 #define XREWIND(F) fseek(F, 0, IO_SEEK_SET)
sPymbed 0:1387ff3eed4a 264 #define XFREAD fread
sPymbed 0:1387ff3eed4a 265 #define XFWRITE fwrite
sPymbed 0:1387ff3eed4a 266 #define XFCLOSE fclose
sPymbed 0:1387ff3eed4a 267 #define XSEEK_END IO_SEEK_END
sPymbed 0:1387ff3eed4a 268 #define XBADFILE NULL
sPymbed 0:1387ff3eed4a 269 #define XFGETS fgets
sPymbed 0:1387ff3eed4a 270 #elif defined(MICRIUM)
sPymbed 0:1387ff3eed4a 271 #include <fs_api.h>
sPymbed 0:1387ff3eed4a 272 #define XFILE FS_FILE*
sPymbed 0:1387ff3eed4a 273 #define XFOPEN fs_fopen
sPymbed 0:1387ff3eed4a 274 #define XFSEEK fs_fseek
sPymbed 0:1387ff3eed4a 275 #define XFTELL fs_ftell
sPymbed 0:1387ff3eed4a 276 #define XREWIND fs_rewind
sPymbed 0:1387ff3eed4a 277 #define XFREAD fs_fread
sPymbed 0:1387ff3eed4a 278 #define XFWRITE fs_fwrite
sPymbed 0:1387ff3eed4a 279 #define XFCLOSE fs_fclose
sPymbed 0:1387ff3eed4a 280 #define XSEEK_END FS_SEEK_END
sPymbed 0:1387ff3eed4a 281 #define XBADFILE NULL
sPymbed 0:1387ff3eed4a 282 #define XFGETS(b,s,f) -2 /* Not ported yet */
sPymbed 0:1387ff3eed4a 283 #elif defined(WOLFSSL_NUCLEUS_1_2)
sPymbed 0:1387ff3eed4a 284 #include "fal/inc/fal.h"
sPymbed 0:1387ff3eed4a 285 #define XFILE FILE*
sPymbed 0:1387ff3eed4a 286 #define XFOPEN fopen
sPymbed 0:1387ff3eed4a 287 #define XFSEEK fseek
sPymbed 0:1387ff3eed4a 288 #define XFTELL ftell
sPymbed 0:1387ff3eed4a 289 #define XREWIND rewind
sPymbed 0:1387ff3eed4a 290 #define XFREAD fread
sPymbed 0:1387ff3eed4a 291 #define XFWRITE fwrite
sPymbed 0:1387ff3eed4a 292 #define XFCLOSE fclose
sPymbed 0:1387ff3eed4a 293 #define XSEEK_END PSEEK_END
sPymbed 0:1387ff3eed4a 294 #define XBADFILE NULL
sPymbed 0:1387ff3eed4a 295 #else
sPymbed 0:1387ff3eed4a 296 /* stdio, default case */
sPymbed 0:1387ff3eed4a 297 #include <stdio.h>
sPymbed 0:1387ff3eed4a 298 #define XFILE FILE*
sPymbed 0:1387ff3eed4a 299 #if defined(WOLFSSL_MDK_ARM)
sPymbed 0:1387ff3eed4a 300 extern FILE * wolfSSL_fopen(const char *name, const char *mode) ;
sPymbed 0:1387ff3eed4a 301 #define XFOPEN wolfSSL_fopen
sPymbed 0:1387ff3eed4a 302 #else
sPymbed 0:1387ff3eed4a 303 #define XFOPEN fopen
sPymbed 0:1387ff3eed4a 304 #endif
sPymbed 0:1387ff3eed4a 305 #define XFSEEK fseek
sPymbed 0:1387ff3eed4a 306 #define XFTELL ftell
sPymbed 0:1387ff3eed4a 307 #define XREWIND rewind
sPymbed 0:1387ff3eed4a 308 #define XFREAD fread
sPymbed 0:1387ff3eed4a 309 #define XFWRITE fwrite
sPymbed 0:1387ff3eed4a 310 #define XFCLOSE fclose
sPymbed 0:1387ff3eed4a 311 #define XSEEK_END SEEK_END
sPymbed 0:1387ff3eed4a 312 #define XBADFILE NULL
sPymbed 0:1387ff3eed4a 313 #define XFGETS fgets
sPymbed 0:1387ff3eed4a 314
sPymbed 0:1387ff3eed4a 315 #if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR)\
sPymbed 0:1387ff3eed4a 316 && !defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
sPymbed 0:1387ff3eed4a 317 #include <dirent.h>
sPymbed 0:1387ff3eed4a 318 #include <unistd.h>
sPymbed 0:1387ff3eed4a 319 #include <sys/stat.h>
sPymbed 0:1387ff3eed4a 320 #endif
sPymbed 0:1387ff3eed4a 321 #endif
sPymbed 0:1387ff3eed4a 322
sPymbed 0:1387ff3eed4a 323 #ifndef MAX_FILENAME_SZ
sPymbed 0:1387ff3eed4a 324 #define MAX_FILENAME_SZ 256 /* max file name length */
sPymbed 0:1387ff3eed4a 325 #endif
sPymbed 0:1387ff3eed4a 326 #ifndef MAX_PATH
sPymbed 0:1387ff3eed4a 327 #define MAX_PATH 256
sPymbed 0:1387ff3eed4a 328 #endif
sPymbed 0:1387ff3eed4a 329
sPymbed 0:1387ff3eed4a 330 #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_NUCLEUS) && \
sPymbed 0:1387ff3eed4a 331 !defined(WOLFSSL_NUCLEUS_1_2)
sPymbed 0:1387ff3eed4a 332 typedef struct ReadDirCtx {
sPymbed 0:1387ff3eed4a 333 #ifdef USE_WINDOWS_API
sPymbed 0:1387ff3eed4a 334 WIN32_FIND_DATAA FindFileData;
sPymbed 0:1387ff3eed4a 335 HANDLE hFind;
sPymbed 0:1387ff3eed4a 336 #else
sPymbed 0:1387ff3eed4a 337 struct dirent* entry;
sPymbed 0:1387ff3eed4a 338 DIR* dir;
sPymbed 0:1387ff3eed4a 339 struct stat s;
sPymbed 0:1387ff3eed4a 340 #endif
sPymbed 0:1387ff3eed4a 341 char name[MAX_FILENAME_SZ];
sPymbed 0:1387ff3eed4a 342 } ReadDirCtx;
sPymbed 0:1387ff3eed4a 343
sPymbed 0:1387ff3eed4a 344 WOLFSSL_API int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name);
sPymbed 0:1387ff3eed4a 345 WOLFSSL_API int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name);
sPymbed 0:1387ff3eed4a 346 WOLFSSL_API void wc_ReadDirClose(ReadDirCtx* ctx);
sPymbed 0:1387ff3eed4a 347 #endif /* !NO_WOLFSSL_DIR */
sPymbed 0:1387ff3eed4a 348
sPymbed 0:1387ff3eed4a 349 #endif /* !NO_FILESYSTEM */
sPymbed 0:1387ff3eed4a 350
sPymbed 0:1387ff3eed4a 351 /* Windows API defines its own min() macro. */
sPymbed 0:1387ff3eed4a 352 #if defined(USE_WINDOWS_API)
sPymbed 0:1387ff3eed4a 353 #if defined(min) || defined(WOLFSSL_MYSQL_COMPATIBLE)
sPymbed 0:1387ff3eed4a 354 #define WOLFSSL_HAVE_MIN
sPymbed 0:1387ff3eed4a 355 #endif /* min */
sPymbed 0:1387ff3eed4a 356 #if defined(max) || defined(WOLFSSL_MYSQL_COMPATIBLE)
sPymbed 0:1387ff3eed4a 357 #define WOLFSSL_HAVE_MAX
sPymbed 0:1387ff3eed4a 358 #endif /* max */
sPymbed 0:1387ff3eed4a 359 #endif /* USE_WINDOWS_API */
sPymbed 0:1387ff3eed4a 360
sPymbed 0:1387ff3eed4a 361 /* Time functions */
sPymbed 0:1387ff3eed4a 362 #ifndef NO_ASN_TIME
sPymbed 0:1387ff3eed4a 363 #if defined(USER_TIME)
sPymbed 0:1387ff3eed4a 364 /* Use our gmtime and time_t/struct tm types.
sPymbed 0:1387ff3eed4a 365 Only needs seconds since EPOCH using XTIME function.
sPymbed 0:1387ff3eed4a 366 time_t XTIME(time_t * timer) {}
sPymbed 0:1387ff3eed4a 367 */
sPymbed 0:1387ff3eed4a 368 #define WOLFSSL_GMTIME
sPymbed 0:1387ff3eed4a 369 #define USE_WOLF_TM
sPymbed 0:1387ff3eed4a 370 #define USE_WOLF_TIME_T
sPymbed 0:1387ff3eed4a 371
sPymbed 0:1387ff3eed4a 372 #elif defined(TIME_OVERRIDES)
sPymbed 0:1387ff3eed4a 373 /* Override XTIME() and XGMTIME() functionality.
sPymbed 0:1387ff3eed4a 374 Requires user to provide these functions:
sPymbed 0:1387ff3eed4a 375 time_t XTIME(time_t * timer) {}
sPymbed 0:1387ff3eed4a 376 struct tm* XGMTIME(const time_t* timer, struct tm* tmp) {}
sPymbed 0:1387ff3eed4a 377 */
sPymbed 0:1387ff3eed4a 378 #ifndef HAVE_TIME_T_TYPE
sPymbed 0:1387ff3eed4a 379 #define USE_WOLF_TIME_T
sPymbed 0:1387ff3eed4a 380 #endif
sPymbed 0:1387ff3eed4a 381 #ifndef HAVE_TM_TYPE
sPymbed 0:1387ff3eed4a 382 #define USE_WOLF_TM
sPymbed 0:1387ff3eed4a 383 #endif
sPymbed 0:1387ff3eed4a 384 #define NEED_TMP_TIME
sPymbed 0:1387ff3eed4a 385
sPymbed 0:1387ff3eed4a 386 #elif defined(HAVE_RTP_SYS)
sPymbed 0:1387ff3eed4a 387 #include "os.h" /* dc_rtc_api needs */
sPymbed 0:1387ff3eed4a 388 #include "dc_rtc_api.h" /* to get current time */
sPymbed 0:1387ff3eed4a 389
sPymbed 0:1387ff3eed4a 390 /* uses parital <time.h> structures */
sPymbed 0:1387ff3eed4a 391 #define XTIME(tl) (0)
sPymbed 0:1387ff3eed4a 392 #define XGMTIME(c, t) rtpsys_gmtime((c))
sPymbed 0:1387ff3eed4a 393
sPymbed 0:1387ff3eed4a 394 #elif defined(MICRIUM)
sPymbed 0:1387ff3eed4a 395 #include <clk.h>
sPymbed 0:1387ff3eed4a 396 #include <time.h>
sPymbed 0:1387ff3eed4a 397 #define XTIME(t1) micrium_time((t1))
sPymbed 0:1387ff3eed4a 398 #define WOLFSSL_GMTIME
sPymbed 0:1387ff3eed4a 399
sPymbed 0:1387ff3eed4a 400 #elif defined(MICROCHIP_TCPIP_V5) || defined(MICROCHIP_TCPIP)
sPymbed 0:1387ff3eed4a 401 #include <time.h>
sPymbed 0:1387ff3eed4a 402 #define XTIME(t1) pic32_time((t1))
sPymbed 0:1387ff3eed4a 403 #define XGMTIME(c, t) gmtime((c))
sPymbed 0:1387ff3eed4a 404
sPymbed 0:1387ff3eed4a 405 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
sPymbed 0:1387ff3eed4a 406 #ifdef FREESCALE_MQX_4_0
sPymbed 0:1387ff3eed4a 407 #include <time.h>
sPymbed 0:1387ff3eed4a 408 extern time_t mqx_time(time_t* timer);
sPymbed 0:1387ff3eed4a 409 #else
sPymbed 0:1387ff3eed4a 410 #define HAVE_GMTIME_R
sPymbed 0:1387ff3eed4a 411 #endif
sPymbed 0:1387ff3eed4a 412 #define XTIME(t1) mqx_time((t1))
sPymbed 0:1387ff3eed4a 413
sPymbed 0:1387ff3eed4a 414 #elif defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS) || defined(FREESCALE_KSDK_FREERTOS)
sPymbed 0:1387ff3eed4a 415 #include <time.h>
sPymbed 0:1387ff3eed4a 416 #ifndef XTIME
sPymbed 0:1387ff3eed4a 417 /*extern time_t ksdk_time(time_t* timer);*/
sPymbed 0:1387ff3eed4a 418 #define XTIME(t1) ksdk_time((t1))
sPymbed 0:1387ff3eed4a 419 #endif
sPymbed 0:1387ff3eed4a 420 #define XGMTIME(c, t) gmtime((c))
sPymbed 0:1387ff3eed4a 421
sPymbed 0:1387ff3eed4a 422 #elif defined(WOLFSSL_ATMEL)
sPymbed 0:1387ff3eed4a 423 #define XTIME(t1) atmel_get_curr_time_and_date((t1))
sPymbed 0:1387ff3eed4a 424 #define WOLFSSL_GMTIME
sPymbed 0:1387ff3eed4a 425 #define USE_WOLF_TM
sPymbed 0:1387ff3eed4a 426 #define USE_WOLF_TIME_T
sPymbed 0:1387ff3eed4a 427
sPymbed 0:1387ff3eed4a 428 #elif defined(IDIRECT_DEV_TIME)
sPymbed 0:1387ff3eed4a 429 /*Gets the timestamp from cloak software owned by VT iDirect
sPymbed 0:1387ff3eed4a 430 in place of time() from <time.h> */
sPymbed 0:1387ff3eed4a 431 #include <time.h>
sPymbed 0:1387ff3eed4a 432 #define XTIME(t1) idirect_time((t1))
sPymbed 0:1387ff3eed4a 433 #define XGMTIME(c, t) gmtime((c))
sPymbed 0:1387ff3eed4a 434
sPymbed 0:1387ff3eed4a 435 #elif defined(_WIN32_WCE)
sPymbed 0:1387ff3eed4a 436 #include <windows.h>
sPymbed 0:1387ff3eed4a 437 #define XTIME(t1) windows_time((t1))
sPymbed 0:1387ff3eed4a 438 #define WOLFSSL_GMTIME
sPymbed 0:1387ff3eed4a 439
sPymbed 0:1387ff3eed4a 440 #else
sPymbed 0:1387ff3eed4a 441 /* default */
sPymbed 0:1387ff3eed4a 442 /* uses complete <time.h> facility */
sPymbed 0:1387ff3eed4a 443 #include <time.h>
sPymbed 0:1387ff3eed4a 444 #if defined(HAVE_SYS_TIME_H)
sPymbed 0:1387ff3eed4a 445 #include <sys/time.h>
sPymbed 0:1387ff3eed4a 446 #endif
sPymbed 0:1387ff3eed4a 447
sPymbed 0:1387ff3eed4a 448 /* PowerPC time_t is int */
sPymbed 0:1387ff3eed4a 449 #ifdef __PPC__
sPymbed 0:1387ff3eed4a 450 #define TIME_T_NOT_LONG
sPymbed 0:1387ff3eed4a 451 #endif
sPymbed 0:1387ff3eed4a 452 #endif
sPymbed 0:1387ff3eed4a 453
sPymbed 0:1387ff3eed4a 454
sPymbed 0:1387ff3eed4a 455 /* Map default time functions */
sPymbed 0:1387ff3eed4a 456 #if !defined(XTIME) && !defined(TIME_OVERRIDES) && !defined(USER_TIME)
sPymbed 0:1387ff3eed4a 457 #define XTIME(tl) time((tl))
sPymbed 0:1387ff3eed4a 458 #endif
sPymbed 0:1387ff3eed4a 459 #if !defined(XGMTIME) && !defined(TIME_OVERRIDES)
sPymbed 0:1387ff3eed4a 460 #if defined(WOLFSSL_GMTIME) || !defined(HAVE_GMTIME_R) || defined(WOLF_C99)
sPymbed 0:1387ff3eed4a 461 #define XGMTIME(c, t) gmtime((c))
sPymbed 0:1387ff3eed4a 462 #else
sPymbed 0:1387ff3eed4a 463 #define XGMTIME(c, t) gmtime_r((c), (t))
sPymbed 0:1387ff3eed4a 464 #define NEED_TMP_TIME
sPymbed 0:1387ff3eed4a 465 #endif
sPymbed 0:1387ff3eed4a 466 #endif
sPymbed 0:1387ff3eed4a 467 #if !defined(XVALIDATE_DATE) && !defined(HAVE_VALIDATE_DATE)
sPymbed 0:1387ff3eed4a 468 #define USE_WOLF_VALIDDATE
sPymbed 0:1387ff3eed4a 469 #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
sPymbed 0:1387ff3eed4a 470 #endif
sPymbed 0:1387ff3eed4a 471
sPymbed 0:1387ff3eed4a 472 /* wolf struct tm and time_t */
sPymbed 0:1387ff3eed4a 473 #if defined(USE_WOLF_TM)
sPymbed 0:1387ff3eed4a 474 struct tm {
sPymbed 0:1387ff3eed4a 475 int tm_sec; /* seconds after the minute [0-60] */
sPymbed 0:1387ff3eed4a 476 int tm_min; /* minutes after the hour [0-59] */
sPymbed 0:1387ff3eed4a 477 int tm_hour; /* hours since midnight [0-23] */
sPymbed 0:1387ff3eed4a 478 int tm_mday; /* day of the month [1-31] */
sPymbed 0:1387ff3eed4a 479 int tm_mon; /* months since January [0-11] */
sPymbed 0:1387ff3eed4a 480 int tm_year; /* years since 1900 */
sPymbed 0:1387ff3eed4a 481 int tm_wday; /* days since Sunday [0-6] */
sPymbed 0:1387ff3eed4a 482 int tm_yday; /* days since January 1 [0-365] */
sPymbed 0:1387ff3eed4a 483 int tm_isdst; /* Daylight Savings Time flag */
sPymbed 0:1387ff3eed4a 484 long tm_gmtoff; /* offset from CUT in seconds */
sPymbed 0:1387ff3eed4a 485 char *tm_zone; /* timezone abbreviation */
sPymbed 0:1387ff3eed4a 486 };
sPymbed 0:1387ff3eed4a 487 #endif /* USE_WOLF_TM */
sPymbed 0:1387ff3eed4a 488 #if defined(USE_WOLF_TIME_T)
sPymbed 0:1387ff3eed4a 489 typedef long time_t;
sPymbed 0:1387ff3eed4a 490 #endif
sPymbed 0:1387ff3eed4a 491 #if defined(USE_WOLF_SUSECONDS_T)
sPymbed 0:1387ff3eed4a 492 typedef long suseconds_t;
sPymbed 0:1387ff3eed4a 493 #endif
sPymbed 0:1387ff3eed4a 494 #if defined(USE_WOLF_TIMEVAL_T)
sPymbed 0:1387ff3eed4a 495 struct timeval
sPymbed 0:1387ff3eed4a 496 {
sPymbed 0:1387ff3eed4a 497 time_t tv_sec;
sPymbed 0:1387ff3eed4a 498 suseconds_t tv_usec;
sPymbed 0:1387ff3eed4a 499 };
sPymbed 0:1387ff3eed4a 500 #endif
sPymbed 0:1387ff3eed4a 501
sPymbed 0:1387ff3eed4a 502 /* forward declarations */
sPymbed 0:1387ff3eed4a 503 #if defined(USER_TIME)
sPymbed 0:1387ff3eed4a 504 struct tm* gmtime(const time_t* timer);
sPymbed 0:1387ff3eed4a 505 extern time_t XTIME(time_t * timer);
sPymbed 0:1387ff3eed4a 506
sPymbed 0:1387ff3eed4a 507 #ifdef STACK_TRAP
sPymbed 0:1387ff3eed4a 508 /* for stack trap tracking, don't call os gmtime on OS X/linux,
sPymbed 0:1387ff3eed4a 509 uses a lot of stack spce */
sPymbed 0:1387ff3eed4a 510 extern time_t time(time_t * timer);
sPymbed 0:1387ff3eed4a 511 #define XTIME(tl) time((tl))
sPymbed 0:1387ff3eed4a 512 #endif /* STACK_TRAP */
sPymbed 0:1387ff3eed4a 513
sPymbed 0:1387ff3eed4a 514 #elif defined(TIME_OVERRIDES)
sPymbed 0:1387ff3eed4a 515 extern time_t XTIME(time_t * timer);
sPymbed 0:1387ff3eed4a 516 extern struct tm* XGMTIME(const time_t* timer, struct tm* tmp);
sPymbed 0:1387ff3eed4a 517 #elif defined(WOLFSSL_GMTIME)
sPymbed 0:1387ff3eed4a 518 struct tm* gmtime(const time_t* timer);
sPymbed 0:1387ff3eed4a 519 #endif
sPymbed 0:1387ff3eed4a 520 #endif /* NO_ASN_TIME */
sPymbed 0:1387ff3eed4a 521
sPymbed 0:1387ff3eed4a 522 #ifndef WOLFSSL_LEANPSK
sPymbed 0:1387ff3eed4a 523 char* mystrnstr(const char* s1, const char* s2, unsigned int n);
sPymbed 0:1387ff3eed4a 524 #endif
sPymbed 0:1387ff3eed4a 525
sPymbed 0:1387ff3eed4a 526 #ifndef FILE_BUFFER_SIZE
sPymbed 0:1387ff3eed4a 527 #define FILE_BUFFER_SIZE 1024 /* default static file buffer size for input,
sPymbed 0:1387ff3eed4a 528 will use dynamic buffer if not big enough */
sPymbed 0:1387ff3eed4a 529 #endif
sPymbed 0:1387ff3eed4a 530
sPymbed 0:1387ff3eed4a 531
sPymbed 0:1387ff3eed4a 532 #ifdef __cplusplus
sPymbed 0:1387ff3eed4a 533 } /* extern "C" */
sPymbed 0:1387ff3eed4a 534 #endif
sPymbed 0:1387ff3eed4a 535
sPymbed 0:1387ff3eed4a 536 #endif /* WOLF_CRYPT_PORT_H */
sPymbed 0:1387ff3eed4a 537
sPymbed 0:1387ff3eed4a 538