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.
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 #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN) 00042 /* On WinCE winsock2.h must be included before windows.h */ 00043 #include <winsock2.h> 00044 #endif 00045 #include <windows.h> 00046 #endif 00047 #elif defined(THREADX) 00048 #ifndef SINGLE_THREADED 00049 #include "tx_api.h" 00050 #endif 00051 #elif defined(MICRIUM) 00052 /* do nothing, just don't pick Unix */ 00053 #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS) 00054 /* do nothing */ 00055 #elif defined(EBSNET) 00056 /* do nothing */ 00057 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) 00058 /* do nothing */ 00059 #elif defined(FREESCALE_FREE_RTOS) 00060 #include "fsl_os_abstraction.h" 00061 #elif defined(WOLFSSL_uITRON4) 00062 #include "kernel.h" 00063 #elif defined(WOLFSSL_uTKERNEL2) 00064 #include "tk/tkernel.h" 00065 #elif defined(WOLFSSL_MDK_ARM) 00066 #if defined(WOLFSSL_MDK5) 00067 #include "cmsis_os.h" 00068 #else 00069 #include <rtl.h> 00070 #endif 00071 #elif defined(WOLFSSL_CMSIS_RTOS) 00072 #include "cmsis_os.h" 00073 #elif defined(WOLFSSL_TIRTOS) 00074 #include <ti/sysbios/BIOS.h> 00075 #include <ti/sysbios/knl/Semaphore.h> 00076 #else 00077 #ifndef SINGLE_THREADED 00078 #define WOLFSSL_PTHREADS 00079 #include <pthread.h> 00080 #endif 00081 #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS) 00082 #include <unistd.h> /* for close of BIO */ 00083 #endif 00084 #endif 00085 00086 00087 #ifdef SINGLE_THREADED 00088 typedef int wolfSSL_Mutex; 00089 #else /* MULTI_THREADED */ 00090 /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */ 00091 #if defined(FREERTOS) 00092 typedef xSemaphoreHandle wolfSSL_Mutex; 00093 #elif defined(FREERTOS_TCP) 00094 #include "FreeRTOS.h" 00095 #include "semphr.h" 00096 typedef SemaphoreHandle_t wolfSSL_Mutex; 00097 #elif defined(WOLFSSL_SAFERTOS) 00098 typedef struct wolfSSL_Mutex { 00099 signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES]; 00100 xSemaphoreHandle mutex; 00101 } wolfSSL_Mutex; 00102 #elif defined(USE_WINDOWS_API) 00103 typedef CRITICAL_SECTION wolfSSL_Mutex; 00104 #elif defined(WOLFSSL_PTHREADS) 00105 typedef pthread_mutex_t wolfSSL_Mutex; 00106 #elif defined(THREADX) 00107 typedef TX_MUTEX wolfSSL_Mutex; 00108 #elif defined(MICRIUM) 00109 typedef OS_MUTEX wolfSSL_Mutex; 00110 #elif defined(EBSNET) 00111 typedef RTP_MUTEX wolfSSL_Mutex; 00112 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) 00113 typedef MUTEX_STRUCT wolfSSL_Mutex; 00114 #elif defined(FREESCALE_FREE_RTOS) 00115 typedef mutex_t wolfSSL_Mutex; 00116 #elif defined(WOLFSSL_uITRON4) 00117 typedef struct wolfSSL_Mutex { 00118 T_CSEM sem ; 00119 ID id ; 00120 } wolfSSL_Mutex; 00121 #elif defined(WOLFSSL_uTKERNEL2) 00122 typedef struct wolfSSL_Mutex { 00123 T_CSEM sem ; 00124 ID id ; 00125 } wolfSSL_Mutex; 00126 #elif defined(WOLFSSL_MDK_ARM) 00127 #if defined(WOLFSSL_CMSIS_RTOS) 00128 typedef osMutexId wolfSSL_Mutex; 00129 #else 00130 typedef OS_MUT wolfSSL_Mutex; 00131 #endif 00132 #elif defined(WOLFSSL_CMSIS_RTOS) 00133 typedef osMutexId wolfSSL_Mutex; 00134 #elif defined(WOLFSSL_TIRTOS) 00135 typedef ti_sysbios_knl_Semaphore_Handle wolfSSL_Mutex; 00136 #else 00137 #error Need a mutex type in multithreaded mode 00138 #endif /* USE_WINDOWS_API */ 00139 #endif /* SINGLE_THREADED */ 00140 00141 /* Enable crypt HW mutex for Freescale MMCAU */ 00142 #if defined(FREESCALE_MMCAU) 00143 #ifndef WOLFSSL_CRYPT_HW_MUTEX 00144 #define WOLFSSL_CRYPT_HW_MUTEX 1 00145 #endif 00146 #endif /* FREESCALE_MMCAU */ 00147 00148 #ifndef WOLFSSL_CRYPT_HW_MUTEX 00149 #define WOLFSSL_CRYPT_HW_MUTEX 0 00150 #endif 00151 00152 #if WOLFSSL_CRYPT_HW_MUTEX 00153 /* wolfSSL_CryptHwMutexInit is called on first wolfSSL_CryptHwMutexLock, 00154 however it's recommended to call this directly on Hw init to avoid possible 00155 race condition where two calls to wolfSSL_CryptHwMutexLock are made at 00156 the same time. */ 00157 int wolfSSL_CryptHwMutexInit(void); 00158 int wolfSSL_CryptHwMutexLock(void); 00159 int wolfSSL_CryptHwMutexUnLock(void); 00160 #else 00161 /* Define stubs, since HW mutex is disabled */ 00162 #define wolfSSL_CryptHwMutexInit() 0 /* Success */ 00163 #define wolfSSL_CryptHwMutexLock() 0 /* Success */ 00164 #define wolfSSL_CryptHwMutexUnLock() 0 /* Success */ 00165 #endif /* WOLFSSL_CRYPT_HW_MUTEX */ 00166 00167 /* Mutex functions */ 00168 WOLFSSL_LOCAL int InitMutex(wolfSSL_Mutex*); 00169 WOLFSSL_LOCAL int FreeMutex(wolfSSL_Mutex*); 00170 WOLFSSL_LOCAL int LockMutex(wolfSSL_Mutex*); 00171 WOLFSSL_LOCAL int UnLockMutex(wolfSSL_Mutex*); 00172 00173 /* main crypto initialization function */ 00174 WOLFSSL_API int wolfCrypt_Init(void); 00175 00176 /* filesystem abstraction layer, used by ssl.c */ 00177 #ifndef NO_FILESYSTEM 00178 00179 #if defined(EBSNET) 00180 #define XFILE int 00181 #define XFOPEN(NAME, MODE) vf_open((const char *)NAME, VO_RDONLY, 0); 00182 #define XFSEEK vf_lseek 00183 #define XFTELL vf_tell 00184 #define XREWIND vf_rewind 00185 #define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT) 00186 #define XFWRITE(BUF, SZ, AMT, FD) vf_write(FD, BUF, SZ*AMT) 00187 #define XFCLOSE vf_close 00188 #define XSEEK_END VSEEK_END 00189 #define XBADFILE -1 00190 #elif defined(LSR_FS) 00191 #include <fs.h> 00192 #define XFILE struct fs_file* 00193 #define XFOPEN(NAME, MODE) fs_open((char*)NAME); 00194 #define XFSEEK(F, O, W) (void)F 00195 #define XFTELL(F) (F)->len 00196 #define XREWIND(F) (void)F 00197 #define XFREAD(BUF, SZ, AMT, F) fs_read(F, (char*)BUF, SZ*AMT) 00198 #define XFWRITE(BUF, SZ, AMT, F) fs_write(F, (char*)BUF, SZ*AMT) 00199 #define XFCLOSE fs_close 00200 #define XSEEK_END 0 00201 #define XBADFILE NULL 00202 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) 00203 #define XFILE MQX_FILE_PTR 00204 #define XFOPEN fopen 00205 #define XFSEEK fseek 00206 #define XFTELL ftell 00207 #define XREWIND(F) fseek(F, 0, IO_SEEK_SET) 00208 #define XFREAD fread 00209 #define XFWRITE fwrite 00210 #define XFCLOSE fclose 00211 #define XSEEK_END IO_SEEK_END 00212 #define XBADFILE NULL 00213 #elif defined(MICRIUM) 00214 #include <fs.h> 00215 #define XFILE FS_FILE* 00216 #define XFOPEN fs_fopen 00217 #define XFSEEK fs_fseek 00218 #define XFTELL fs_ftell 00219 #define XREWIND fs_rewind 00220 #define XFREAD fs_fread 00221 #define XFWRITE fs_fwrite 00222 #define XFCLOSE fs_fclose 00223 #define XSEEK_END FS_SEEK_END 00224 #define XBADFILE NULL 00225 #else 00226 /* stdio, default case */ 00227 #define XFILE FILE* 00228 #if defined(WOLFSSL_MDK_ARM) 00229 #include <stdio.h> 00230 extern FILE * wolfSSL_fopen(const char *name, const char *mode) ; 00231 #define XFOPEN wolfSSL_fopen 00232 #else 00233 #define XFOPEN fopen 00234 #endif 00235 #define XFSEEK fseek 00236 #define XFTELL ftell 00237 #define XREWIND rewind 00238 #define XFREAD fread 00239 #define XFWRITE fwrite 00240 #define XFCLOSE fclose 00241 #define XSEEK_END SEEK_END 00242 #define XBADFILE NULL 00243 #endif 00244 00245 #endif /* NO_FILESYSTEM */ 00246 00247 00248 /* Windows API defines its own min() macro. */ 00249 #if defined(USE_WINDOWS_API) 00250 #ifdef min 00251 #define WOLFSSL_HAVE_MIN 00252 #endif /* min */ 00253 #ifdef max 00254 #define WOLFSSL_HAVE_MAX 00255 #endif /* max */ 00256 #endif /* USE_WINDOWS_API */ 00257 00258 00259 #ifdef __cplusplus 00260 } /* extern "C" */ 00261 #endif 00262 00263 #endif /* WOLF_CRYPT_PORT_H */ 00264 00265
Generated on Tue Jul 12 2022 15:55:23 by
1.7.2