Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of wolfSSL by
wc_port.h
00001 /* wc_port.h 00002 * 00003 * Copyright (C) 2006-2016 wolfSSL Inc. 00004 * 00005 * This file is part of wolfSSL. 00006 * 00007 * wolfSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * wolfSSL is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 00020 */ 00021 00022 00023 00024 #ifndef WOLF_CRYPT_PORT_H 00025 #define WOLF_CRYPT_PORT_H 00026 00027 #include <wolfssl/wolfcrypt/visibility.h> 00028 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif 00032 00033 00034 #ifdef USE_WINDOWS_API 00035 #ifdef WOLFSSL_GAME_BUILD 00036 #include "system/xtl.h" 00037 #else 00038 #ifndef WIN32_LEAN_AND_MEAN 00039 #define WIN32_LEAN_AND_MEAN 00040 #endif 00041 #ifndef WOLFSSL_SGX 00042 #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN) 00043 /* On WinCE winsock2.h must be included before windows.h */ 00044 #include <winsock2.h> 00045 #endif 00046 #include <windows.h> 00047 #endif /* WOLFSSL_SGX */ 00048 #endif 00049 #elif defined(THREADX) 00050 #ifndef SINGLE_THREADED 00051 #include "tx_api.h" 00052 #endif 00053 #elif defined(MICRIUM) 00054 /* do nothing, just don't pick Unix */ 00055 #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS) 00056 /* do nothing */ 00057 #elif defined(EBSNET) 00058 /* do nothing */ 00059 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) 00060 /* do nothing */ 00061 #elif defined(FREESCALE_FREE_RTOS) 00062 #include "fsl_os_abstraction.h" 00063 #elif defined(WOLFSSL_uITRON4) 00064 #include "stddef.h" 00065 #include "kernel.h" 00066 #elif defined(WOLFSSL_uTKERNEL2) 00067 #include "tk/tkernel.h" 00068 #elif defined(WOLFSSL_MDK_ARM) 00069 #if defined(WOLFSSL_MDK5) 00070 #include "cmsis_os.h" 00071 #else 00072 #include <rtl.h> 00073 #endif 00074 #elif defined(WOLFSSL_CMSIS_RTOS) 00075 #include "cmsis_os.h" 00076 #elif defined(WOLFSSL_TIRTOS) 00077 #include <ti/sysbios/BIOS.h> 00078 #include <ti/sysbios/knl/Semaphore.h> 00079 #elif defined(WOLFSSL_FROSTED) 00080 #include <semaphore.h> 00081 #elif defined(INTIME_RTOS) 00082 #include <rt.h> 00083 #include <io.h> 00084 #else 00085 #ifndef SINGLE_THREADED 00086 #define WOLFSSL_PTHREADS 00087 #include <pthread.h> 00088 #endif 00089 #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS) 00090 #include <unistd.h> /* for close of BIO */ 00091 #endif 00092 #endif 00093 00094 /* For FIPS keep the function names the same */ 00095 #ifdef HAVE_FIPS 00096 #define wc_InitMutex InitMutex 00097 #define wc_FreeMutex FreeMutex 00098 #define wc_LockMutex LockMutex 00099 #define wc_UnLockMutex UnLockMutex 00100 #endif /* HAVE_FIPS */ 00101 00102 #ifdef SINGLE_THREADED 00103 typedef int wolfSSL_Mutex; 00104 #else /* MULTI_THREADED */ 00105 /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */ 00106 #if defined(FREERTOS) 00107 typedef xSemaphoreHandle wolfSSL_Mutex; 00108 #elif defined(FREERTOS_TCP) 00109 #include "FreeRTOS.h" 00110 #include "semphr.h" 00111 typedef SemaphoreHandle_t wolfSSL_Mutex; 00112 #elif defined(WOLFSSL_SAFERTOS) 00113 typedef struct wolfSSL_Mutex { 00114 signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES]; 00115 xSemaphoreHandle mutex; 00116 } wolfSSL_Mutex; 00117 #elif defined(USE_WINDOWS_API) 00118 typedef CRITICAL_SECTION wolfSSL_Mutex; 00119 #elif defined(WOLFSSL_PTHREADS) 00120 typedef pthread_mutex_t wolfSSL_Mutex; 00121 #elif defined(THREADX) 00122 typedef TX_MUTEX wolfSSL_Mutex; 00123 #elif defined(MICRIUM) 00124 typedef OS_MUTEX wolfSSL_Mutex; 00125 #elif defined(EBSNET) 00126 typedef RTP_MUTEX wolfSSL_Mutex; 00127 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) 00128 typedef MUTEX_STRUCT wolfSSL_Mutex; 00129 #elif defined(FREESCALE_FREE_RTOS) 00130 typedef mutex_t wolfSSL_Mutex; 00131 #elif defined(WOLFSSL_uITRON4) 00132 typedef struct wolfSSL_Mutex { 00133 T_CSEM sem ; 00134 ID id ; 00135 } wolfSSL_Mutex; 00136 #elif defined(WOLFSSL_uTKERNEL2) 00137 typedef struct wolfSSL_Mutex { 00138 T_CSEM sem ; 00139 ID id ; 00140 } wolfSSL_Mutex; 00141 #elif defined(WOLFSSL_MDK_ARM) 00142 #if defined(WOLFSSL_CMSIS_RTOS) 00143 typedef osMutexId wolfSSL_Mutex; 00144 #else 00145 typedef OS_MUT wolfSSL_Mutex; 00146 #endif 00147 #elif defined(WOLFSSL_CMSIS_RTOS) 00148 typedef osMutexId wolfSSL_Mutex; 00149 #elif defined(WOLFSSL_TIRTOS) 00150 typedef ti_sysbios_knl_Semaphore_Handle wolfSSL_Mutex; 00151 #elif defined(WOLFSSL_FROSTED) 00152 typedef mutex_t * wolfSSL_Mutex; 00153 #elif defined(INTIME_RTOS) 00154 typedef RTHANDLE wolfSSL_Mutex; 00155 #else 00156 #error Need a mutex type in multithreaded mode 00157 #endif /* USE_WINDOWS_API */ 00158 #endif /* SINGLE_THREADED */ 00159 00160 /* Enable crypt HW mutex for Freescale MMCAU */ 00161 #if defined(FREESCALE_MMCAU) 00162 #ifndef WOLFSSL_CRYPT_HW_MUTEX 00163 #define WOLFSSL_CRYPT_HW_MUTEX 1 00164 #endif 00165 #endif /* FREESCALE_MMCAU */ 00166 00167 #ifndef WOLFSSL_CRYPT_HW_MUTEX 00168 #define WOLFSSL_CRYPT_HW_MUTEX 0 00169 #endif 00170 00171 #if WOLFSSL_CRYPT_HW_MUTEX 00172 /* wolfSSL_CryptHwMutexInit is called on first wolfSSL_CryptHwMutexLock, 00173 however it's recommended to call this directly on Hw init to avoid possible 00174 race condition where two calls to wolfSSL_CryptHwMutexLock are made at 00175 the same time. */ 00176 int wolfSSL_CryptHwMutexInit(void); 00177 int wolfSSL_CryptHwMutexLock(void); 00178 int wolfSSL_CryptHwMutexUnLock(void); 00179 #else 00180 /* Define stubs, since HW mutex is disabled */ 00181 #define wolfSSL_CryptHwMutexInit() 0 /* Success */ 00182 #define wolfSSL_CryptHwMutexLock() 0 /* Success */ 00183 #define wolfSSL_CryptHwMutexUnLock() 0 /* Success */ 00184 #endif /* WOLFSSL_CRYPT_HW_MUTEX */ 00185 00186 /* Mutex functions */ 00187 WOLFSSL_API int wc_InitMutex(wolfSSL_Mutex*); 00188 WOLFSSL_API wolfSSL_Mutex* wc_InitAndAllocMutex(void); 00189 WOLFSSL_API int wc_FreeMutex(wolfSSL_Mutex*); 00190 WOLFSSL_API int wc_LockMutex(wolfSSL_Mutex*); 00191 WOLFSSL_API int wc_UnLockMutex(wolfSSL_Mutex*); 00192 00193 /* main crypto initialization function */ 00194 WOLFSSL_API int wolfCrypt_Init(void); 00195 WOLFSSL_API int wolfCrypt_Cleanup(void); 00196 00197 /* filesystem abstraction layer, used by ssl.c */ 00198 #ifndef NO_FILESYSTEM 00199 00200 #if defined(EBSNET) 00201 #include "vfapi.h" 00202 #include "vfile.h" 00203 00204 #define XFILE int 00205 #define XFOPEN(NAME, MODE) vf_open((const char *)NAME, VO_RDONLY, 0); 00206 #define XFSEEK vf_lseek 00207 #define XFTELL vf_tell 00208 #define XREWIND vf_rewind 00209 #define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT) 00210 #define XFWRITE(BUF, SZ, AMT, FD) vf_write(FD, BUF, SZ*AMT) 00211 #define XFCLOSE vf_close 00212 #define XSEEK_END VSEEK_END 00213 #define XBADFILE -1 00214 #define XFGETS(b,s,f) -2 /* Not ported yet */ 00215 #elif defined(LSR_FS) 00216 #include <fs.h> 00217 #define XFILE struct fs_file* 00218 #define XFOPEN(NAME, MODE) fs_open((char*)NAME); 00219 #define XFSEEK(F, O, W) (void)F 00220 #define XFTELL(F) (F)->len 00221 #define XREWIND(F) (void)F 00222 #define XFREAD(BUF, SZ, AMT, F) fs_read(F, (char*)BUF, SZ*AMT) 00223 #define XFWRITE(BUF, SZ, AMT, F) fs_write(F, (char*)BUF, SZ*AMT) 00224 #define XFCLOSE fs_close 00225 #define XSEEK_END 0 00226 #define XBADFILE NULL 00227 #define XFGETS(b,s,f) -2 /* Not ported yet */ 00228 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) 00229 #define XFILE MQX_FILE_PTR 00230 #define XFOPEN fopen 00231 #define XFSEEK fseek 00232 #define XFTELL ftell 00233 #define XREWIND(F) fseek(F, 0, IO_SEEK_SET) 00234 #define XFREAD fread 00235 #define XFWRITE fwrite 00236 #define XFCLOSE fclose 00237 #define XSEEK_END IO_SEEK_END 00238 #define XBADFILE NULL 00239 #define XFGETS fgets 00240 #elif defined(MICRIUM) 00241 #include <fs.h> 00242 #define XFILE FS_FILE* 00243 #define XFOPEN fs_fopen 00244 #define XFSEEK fs_fseek 00245 #define XFTELL fs_ftell 00246 #define XREWIND fs_rewind 00247 #define XFREAD fs_fread 00248 #define XFWRITE fs_fwrite 00249 #define XFCLOSE fs_fclose 00250 #define XSEEK_END FS_SEEK_END 00251 #define XBADFILE NULL 00252 #define XFGETS(b,s,f) -2 /* Not ported yet */ 00253 #else 00254 /* stdio, default case */ 00255 #include <stdio.h> 00256 #define XFILE FILE* 00257 #if defined(WOLFSSL_MDK_ARM) 00258 extern FILE * wolfSSL_fopen(const char *name, const char *mode) ; 00259 #define XFOPEN wolfSSL_fopen 00260 #else 00261 #define XFOPEN fopen 00262 #endif 00263 #define XFSEEK fseek 00264 #define XFTELL ftell 00265 #define XREWIND rewind 00266 #define XFREAD fread 00267 #define XFWRITE fwrite 00268 #define XFCLOSE fclose 00269 #define XSEEK_END SEEK_END 00270 #define XBADFILE NULL 00271 #define XFGETS fgets 00272 00273 #if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR) 00274 #include <dirent.h> 00275 #include <unistd.h> 00276 #include <sys/stat.h> 00277 #endif 00278 #endif 00279 00280 #ifndef MAX_FILENAME_SZ 00281 #define MAX_FILENAME_SZ 256 /* max file name length */ 00282 #endif 00283 #ifndef MAX_PATH 00284 #define MAX_PATH 256 00285 #endif 00286 00287 #if !defined(NO_WOLFSSL_DIR) 00288 typedef struct ReadDirCtx { 00289 #ifdef USE_WINDOWS_API 00290 WIN32_FIND_DATAA FindFileData; 00291 HANDLE hFind; 00292 #else 00293 struct dirent* entry; 00294 DIR* dir; 00295 struct stat s; 00296 #endif 00297 char name[MAX_FILENAME_SZ]; 00298 } ReadDirCtx; 00299 00300 WOLFSSL_API int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name); 00301 WOLFSSL_API int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name); 00302 WOLFSSL_API void wc_ReadDirClose(ReadDirCtx* ctx); 00303 #endif /* !NO_WOLFSSL_DIR */ 00304 00305 #endif /* !NO_FILESYSTEM */ 00306 00307 00308 /* Windows API defines its own min() macro. */ 00309 #if defined(USE_WINDOWS_API) 00310 #if defined(min) || defined(WOLFSSL_MYSQL_COMPATIBLE) 00311 #define WOLFSSL_HAVE_MIN 00312 #endif /* min */ 00313 #if defined(max) || defined(WOLFSSL_MYSQL_COMPATIBLE) 00314 #define WOLFSSL_HAVE_MAX 00315 #endif /* max */ 00316 #endif /* USE_WINDOWS_API */ 00317 00318 00319 #ifdef __cplusplus 00320 } /* extern "C" */ 00321 #endif 00322 00323 #endif /* WOLF_CRYPT_PORT_H */ 00324 00325
Generated on Tue Jul 12 2022 23:31:02 by
1.7.2
