[457] | 1 | /* wc_port.h
|
---|
| 2 | *
|
---|
| 3 | * Copyright (C) 2006-2020 wolfSSL Inc.
|
---|
| 4 | *
|
---|
| 5 | * This file is part of wolfSSL.
|
---|
| 6 | *
|
---|
| 7 | * wolfSSL is free software; you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * wolfSSL is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with this program; if not, write to the Free Software
|
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | /*!
|
---|
| 23 | \file wolfssl/wolfcrypt/wc_port.h
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | #ifndef WOLF_CRYPT_PORT_H
|
---|
| 27 | #define WOLF_CRYPT_PORT_H
|
---|
| 28 |
|
---|
| 29 | #include <wolfssl/wolfcrypt/settings.h>
|
---|
| 30 | #include <wolfssl/wolfcrypt/visibility.h>
|
---|
| 31 |
|
---|
| 32 | #ifdef __cplusplus
|
---|
| 33 | extern "C" {
|
---|
| 34 | #endif
|
---|
| 35 |
|
---|
| 36 | /* Detect if compiler supports C99. "NO_WOLF_C99" can be defined in
|
---|
| 37 | * user_settings.h to disable checking for C99 support. */
|
---|
| 38 | #if !defined(WOLF_C99) && defined(__STDC_VERSION__) && \
|
---|
| 39 | !defined(WOLFSSL_ARDUINO) && !defined(NO_WOLF_C99)
|
---|
| 40 | #if __STDC_VERSION__ >= 199901L
|
---|
| 41 | #define WOLF_C99
|
---|
| 42 | #endif
|
---|
| 43 | #endif
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | /* GENERIC INCLUDE SECTION */
|
---|
| 47 | #if defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
|
---|
| 48 | #include <mqx.h>
|
---|
| 49 | #if (defined(MQX_USE_IO_OLD) && MQX_USE_IO_OLD) || \
|
---|
| 50 | defined(FREESCALE_MQX_5_0)
|
---|
| 51 | #include <fio.h>
|
---|
| 52 | #else
|
---|
| 53 | #include <nio.h>
|
---|
| 54 | #endif
|
---|
| 55 | #endif
|
---|
| 56 |
|
---|
[464] | 57 | #ifdef WOLFSSL_LINUXKM
|
---|
| 58 | #ifdef HAVE_CONFIG_H
|
---|
| 59 | #ifndef PACKAGE_NAME
|
---|
| 60 | #error wc_port.h included before config.h
|
---|
| 61 | #endif
|
---|
| 62 | /* config.h is autogenerated without gating, and is subject to repeat
|
---|
| 63 | * inclusions, so gate it out here to keep autodetection masking
|
---|
| 64 | * intact:
|
---|
| 65 | */
|
---|
| 66 | #undef HAVE_CONFIG_H
|
---|
| 67 | #endif
|
---|
[457] | 68 |
|
---|
[464] | 69 | #ifdef BUILDING_WOLFSSL
|
---|
| 70 |
|
---|
| 71 | _Pragma("GCC diagnostic push");
|
---|
| 72 |
|
---|
| 73 | /* we include all the needed kernel headers with these masked out. else
|
---|
| 74 | * there are profuse warnings.
|
---|
| 75 | */
|
---|
| 76 | _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"");
|
---|
| 77 | _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"");
|
---|
| 78 | _Pragma("GCC diagnostic ignored \"-Wshadow\"");
|
---|
| 79 | _Pragma("GCC diagnostic ignored \"-Wnested-externs\"");
|
---|
| 80 | _Pragma("GCC diagnostic ignored \"-Wredundant-decls\"");
|
---|
| 81 | _Pragma("GCC diagnostic ignored \"-Wsign-compare\"");
|
---|
| 82 | _Pragma("GCC diagnostic ignored \"-Wpointer-sign\"");
|
---|
| 83 | _Pragma("GCC diagnostic ignored \"-Wbad-function-cast\"");
|
---|
| 84 | _Pragma("GCC diagnostic ignored \"-Wdiscarded-qualifiers\"");
|
---|
| 85 |
|
---|
| 86 | #include <linux/kconfig.h>
|
---|
| 87 | #include <linux/kernel.h>
|
---|
| 88 | #include <linux/version.h>
|
---|
| 89 | #include <linux/ctype.h>
|
---|
| 90 | #include <linux/init.h>
|
---|
| 91 | #include <linux/module.h>
|
---|
| 92 | #include <linux/mm.h>
|
---|
| 93 | #ifndef SINGLE_THREADED
|
---|
| 94 | #include <linux/kthread.h>
|
---|
| 95 | #endif
|
---|
| 96 | #include <linux/net.h>
|
---|
| 97 | #include <linux/slab.h>
|
---|
| 98 | #if defined(WOLFSSL_AESNI) || defined(USE_INTEL_SPEEDUP)
|
---|
| 99 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
|
---|
| 100 | #include <asm/i387.h>
|
---|
| 101 | #else
|
---|
| 102 | #include <asm/simd.h>
|
---|
| 103 | #endif
|
---|
| 104 | #ifndef SAVE_VECTOR_REGISTERS
|
---|
| 105 | #define SAVE_VECTOR_REGISTERS() kernel_fpu_begin()
|
---|
| 106 | #endif
|
---|
| 107 | #ifndef RESTORE_VECTOR_REGISTERS
|
---|
| 108 | #define RESTORE_VECTOR_REGISTERS() kernel_fpu_end()
|
---|
| 109 | #endif
|
---|
| 110 | #elif defined(WOLFSSL_ARMASM)
|
---|
| 111 | #include <asm/fpsimd.h>
|
---|
| 112 | #ifndef SAVE_VECTOR_REGISTERS
|
---|
| 113 | #define SAVE_VECTOR_REGISTERS() ({ preempt_disable(); fpsimd_preserve_current_state(); })
|
---|
| 114 | #endif
|
---|
| 115 | #ifndef RESTORE_VECTOR_REGISTERS
|
---|
| 116 | #define RESTORE_VECTOR_REGISTERS() ({ fpsimd_restore_current_state(); preempt_enable(); })
|
---|
| 117 | #endif
|
---|
| 118 | #else
|
---|
| 119 | #ifndef SAVE_VECTOR_REGISTERS
|
---|
| 120 | #define SAVE_VECTOR_REGISTERS() ({})
|
---|
| 121 | #endif
|
---|
| 122 | #ifndef RESTORE_VECTOR_REGISTERS
|
---|
| 123 | #define RESTORE_VECTOR_REGISTERS() ({})
|
---|
| 124 | #endif
|
---|
| 125 | #endif
|
---|
| 126 |
|
---|
| 127 | _Pragma("GCC diagnostic pop");
|
---|
| 128 |
|
---|
| 129 | /* Linux headers define these using C expressions, but we need
|
---|
| 130 | * them to be evaluable by the preprocessor, for use in sp_int.h.
|
---|
| 131 | */
|
---|
| 132 | _Static_assert(sizeof(ULONG_MAX) == 8, "WOLFSSL_LINUXKM supported only on targets with 64 bit long words.");
|
---|
| 133 | #undef UCHAR_MAX
|
---|
| 134 | #define UCHAR_MAX 255
|
---|
| 135 | #undef USHRT_MAX
|
---|
| 136 | #define USHRT_MAX 65535
|
---|
| 137 | #undef UINT_MAX
|
---|
| 138 | #define UINT_MAX 4294967295U
|
---|
| 139 | #undef ULONG_MAX
|
---|
| 140 | #define ULONG_MAX 18446744073709551615UL
|
---|
| 141 | #undef ULLONG_MAX
|
---|
| 142 | #define ULLONG_MAX ULONG_MAX
|
---|
| 143 | #undef INT_MAX
|
---|
| 144 | #define INT_MAX 2147483647
|
---|
| 145 | #undef LONG_MAX
|
---|
| 146 | #define LONG_MAX 9223372036854775807L
|
---|
| 147 | #undef LLONG_MAX
|
---|
| 148 | #define LLONG_MAX LONG_MAX
|
---|
| 149 |
|
---|
| 150 | /* remove this multifariously conflicting macro, picked up from
|
---|
| 151 | * Linux arch/<arch>/include/asm/current.h.
|
---|
| 152 | */
|
---|
| 153 | #undef current
|
---|
| 154 |
|
---|
| 155 | /* prevent gcc's mm_malloc.h from being included, since it unconditionally
|
---|
| 156 | * includes stdlib.h, which is kernel-incompatible.
|
---|
| 157 | */
|
---|
| 158 | #define _MM_MALLOC_H_INCLUDED
|
---|
| 159 |
|
---|
| 160 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
|
---|
| 161 | /* kvmalloc()/kvfree() and friends added in linux commit a7c3e901 */
|
---|
| 162 | #define malloc(x) kvmalloc(x, GFP_KERNEL)
|
---|
| 163 | #define free(x) kvfree(x)
|
---|
| 164 | void *lkm_realloc(void *ptr, size_t newsize);
|
---|
| 165 | #define realloc(x, y) lkm_realloc(x, y)
|
---|
| 166 | #else
|
---|
| 167 | #define malloc(x) kmalloc(x, GFP_KERNEL)
|
---|
| 168 | #define free(x) kfree(x)
|
---|
| 169 | #define realloc(x,y) krealloc(x, y, GFP_KERNEL)
|
---|
| 170 | #endif
|
---|
| 171 |
|
---|
| 172 | /* min() and max() in linux/kernel.h over-aggressively type-check, producing
|
---|
| 173 | * myriad spurious -Werrors throughout the codebase.
|
---|
| 174 | */
|
---|
| 175 | #undef min
|
---|
| 176 | #undef max
|
---|
| 177 |
|
---|
| 178 | /* work around namespace conflict between wolfssl/internal.h (enum HandShakeType)
|
---|
| 179 | * and linux/key.h (extern int()).
|
---|
| 180 | */
|
---|
| 181 | #define key_update wc_key_update
|
---|
| 182 |
|
---|
| 183 | #define lkm_printf(format, args...) printk(KERN_INFO "wolfssl: %s(): " format, __func__, ## args)
|
---|
| 184 | #define printf(...) lkm_printf(__VA_ARGS__)
|
---|
| 185 |
|
---|
| 186 | #endif /* BUILDING_WOLFSSL */
|
---|
| 187 |
|
---|
| 188 | /* needed to suppress inclusion of stdio.h in wolfssl/wolfcrypt/types.h */
|
---|
| 189 | #define XSNPRINTF snprintf
|
---|
| 190 |
|
---|
| 191 | /* the rigmarole around kstrtol() here is to accommodate its warn-unused-result attribute. */
|
---|
| 192 | #define XATOI(s) ({ \
|
---|
| 193 | long _xatoi_res = 0; \
|
---|
| 194 | int _xatoi_ret = kstrtol(s, 10, &_xatoi_res); \
|
---|
| 195 | if (_xatoi_ret != 0) { \
|
---|
| 196 | _xatoi_res = 0; \
|
---|
| 197 | } \
|
---|
| 198 | (int)_xatoi_res; \
|
---|
| 199 | })
|
---|
| 200 |
|
---|
| 201 | #else /* ! WOLFSSL_LINUXKM */
|
---|
| 202 |
|
---|
| 203 | #ifndef SAVE_VECTOR_REGISTERS
|
---|
| 204 | #define SAVE_VECTOR_REGISTERS() do{}while(0)
|
---|
| 205 | #endif
|
---|
| 206 | #ifndef RESTORE_VECTOR_REGISTERS
|
---|
| 207 | #define RESTORE_VECTOR_REGISTERS() do{}while(0)
|
---|
| 208 | #endif
|
---|
| 209 |
|
---|
| 210 | #endif /* WOLFSSL_LINUXKM */
|
---|
| 211 |
|
---|
[457] | 212 | /* THREADING/MUTEX SECTION */
|
---|
| 213 | #ifdef USE_WINDOWS_API
|
---|
| 214 | #ifdef WOLFSSL_GAME_BUILD
|
---|
| 215 | #include "system/xtl.h"
|
---|
| 216 | #else
|
---|
| 217 | #ifndef WIN32_LEAN_AND_MEAN
|
---|
| 218 | #define WIN32_LEAN_AND_MEAN
|
---|
| 219 | #endif
|
---|
| 220 | #ifndef WOLFSSL_SGX
|
---|
| 221 | #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
|
---|
| 222 | /* On WinCE winsock2.h must be included before windows.h */
|
---|
| 223 | #include <winsock2.h>
|
---|
| 224 | #endif
|
---|
| 225 | #include <windows.h>
|
---|
| 226 | #endif /* WOLFSSL_SGX */
|
---|
| 227 | #endif
|
---|
| 228 | #elif defined(THREADX)
|
---|
| 229 | #ifndef SINGLE_THREADED
|
---|
| 230 | #ifdef NEED_THREADX_TYPES
|
---|
| 231 | #include <types.h>
|
---|
| 232 | #endif
|
---|
| 233 | #include <tx_api.h>
|
---|
| 234 | #endif
|
---|
| 235 | #elif defined(WOLFSSL_DEOS)
|
---|
| 236 | #include "mutexapi.h"
|
---|
| 237 | #elif defined(MICRIUM)
|
---|
| 238 | /* do nothing, just don't pick Unix */
|
---|
| 239 | #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS)
|
---|
| 240 | /* do nothing */
|
---|
[464] | 241 | #elif defined(RTTHREAD)
|
---|
| 242 | /* do nothing */
|
---|
[457] | 243 | #elif defined(EBSNET)
|
---|
| 244 | /* do nothing */
|
---|
| 245 | #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
|
---|
| 246 | /* do nothing */
|
---|
| 247 | #elif defined(FREESCALE_FREE_RTOS)
|
---|
| 248 | #include "fsl_os_abstraction.h"
|
---|
| 249 | #elif defined(WOLFSSL_VXWORKS)
|
---|
| 250 | #include <semLib.h>
|
---|
| 251 | #elif defined(WOLFSSL_uITRON4)
|
---|
| 252 | #include "stddef.h"
|
---|
| 253 | #include "kernel.h"
|
---|
| 254 | #elif defined(WOLFSSL_uTKERNEL2)
|
---|
| 255 | #include "tk/tkernel.h"
|
---|
| 256 | #elif defined(WOLFSSL_CMSIS_RTOS)
|
---|
| 257 | #include "cmsis_os.h"
|
---|
| 258 | #elif defined(WOLFSSL_CMSIS_RTOSv2)
|
---|
| 259 | #include "cmsis_os2.h"
|
---|
| 260 | #elif defined(WOLFSSL_MDK_ARM)
|
---|
| 261 | #if defined(WOLFSSL_MDK5)
|
---|
| 262 | #include "cmsis_os.h"
|
---|
| 263 | #else
|
---|
| 264 | #include <rtl.h>
|
---|
| 265 | #endif
|
---|
| 266 | #elif defined(WOLFSSL_CMSIS_RTOS)
|
---|
| 267 | #include "cmsis_os.h"
|
---|
| 268 | #elif defined(WOLFSSL_TIRTOS)
|
---|
| 269 | #include <ti/sysbios/BIOS.h>
|
---|
| 270 | #include <ti/sysbios/knl/Semaphore.h>
|
---|
| 271 | #elif defined(WOLFSSL_FROSTED)
|
---|
| 272 | #include <semaphore.h>
|
---|
| 273 | #elif defined(INTIME_RTOS)
|
---|
| 274 | #include <rt.h>
|
---|
| 275 | #include <io.h>
|
---|
| 276 | #elif defined(WOLFSSL_NUCLEUS_1_2)
|
---|
| 277 | /* NU_DEBUG needed struct access in nucleus_realloc */
|
---|
| 278 | #define NU_DEBUG
|
---|
| 279 | #include "plus/nucleus.h"
|
---|
| 280 | #include "nucleus.h"
|
---|
| 281 | #elif defined(WOLFSSL_APACHE_MYNEWT)
|
---|
| 282 | /* do nothing */
|
---|
| 283 | #elif defined(WOLFSSL_ZEPHYR)
|
---|
| 284 | #ifndef SINGLE_THREADED
|
---|
| 285 | #include <kernel.h>
|
---|
| 286 | #endif
|
---|
| 287 | #elif defined(WOLFSSL_TELIT_M2MB)
|
---|
| 288 |
|
---|
| 289 | /* Telit SDK uses C++ compile option (--cpp), which causes link issue
|
---|
| 290 | to API's if wrapped in extern "C" */
|
---|
| 291 | #ifdef __cplusplus
|
---|
| 292 | } /* extern "C" */
|
---|
| 293 | #endif
|
---|
| 294 |
|
---|
| 295 | #include "m2mb_types.h"
|
---|
| 296 | #include "m2mb_os_types.h"
|
---|
| 297 | #include "m2mb_os_api.h"
|
---|
| 298 | #include "m2mb_os.h"
|
---|
| 299 | #include "m2mb_os_mtx.h"
|
---|
| 300 | #ifndef NO_ASN_TIME
|
---|
| 301 | #include "m2mb_rtc.h"
|
---|
| 302 | #endif
|
---|
| 303 | #ifndef NO_FILESYSTEM
|
---|
| 304 | #include "m2mb_fs_posix.h"
|
---|
| 305 | #endif
|
---|
| 306 |
|
---|
| 307 | #undef kB /* eliminate conflict in asn.h */
|
---|
| 308 |
|
---|
| 309 | #ifdef __cplusplus
|
---|
| 310 | extern "C" {
|
---|
| 311 | #endif
|
---|
| 312 |
|
---|
| 313 | #else
|
---|
| 314 | #ifndef SINGLE_THREADED
|
---|
[464] | 315 | #ifndef WOLFSSL_USER_MUTEX
|
---|
| 316 | #if defined(WOLFSSL_LINUXKM)
|
---|
| 317 | #define WOLFSSL_KTHREADS
|
---|
| 318 | #else
|
---|
| 319 | #define WOLFSSL_PTHREADS
|
---|
| 320 | #include <pthread.h>
|
---|
| 321 | #endif
|
---|
| 322 | #endif
|
---|
[457] | 323 | #endif
|
---|
| 324 | #if (defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)) && \
|
---|
| 325 | !defined(NO_FILESYSTEM)
|
---|
[464] | 326 | #ifdef FUSION_RTOS
|
---|
| 327 | #include <fclunistd.h>
|
---|
| 328 | #else
|
---|
| 329 | #include <unistd.h> /* for close of BIO */
|
---|
| 330 | #endif
|
---|
[457] | 331 | #endif
|
---|
| 332 | #endif
|
---|
| 333 |
|
---|
| 334 | /* For FIPS keep the function names the same */
|
---|
| 335 | #ifdef HAVE_FIPS
|
---|
| 336 | #define wc_InitMutex InitMutex
|
---|
| 337 | #define wc_FreeMutex FreeMutex
|
---|
| 338 | #define wc_LockMutex LockMutex
|
---|
| 339 | #define wc_UnLockMutex UnLockMutex
|
---|
| 340 | #endif /* HAVE_FIPS */
|
---|
| 341 |
|
---|
| 342 | #ifdef SINGLE_THREADED
|
---|
| 343 | typedef int wolfSSL_Mutex;
|
---|
| 344 | #else /* MULTI_THREADED */
|
---|
| 345 | /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */
|
---|
| 346 | #if defined(FREERTOS)
|
---|
| 347 | typedef xSemaphoreHandle wolfSSL_Mutex;
|
---|
| 348 | #elif defined(FREERTOS_TCP)
|
---|
| 349 | #include "FreeRTOS.h"
|
---|
| 350 | #include "semphr.h"
|
---|
| 351 | typedef SemaphoreHandle_t wolfSSL_Mutex;
|
---|
[464] | 352 | #elif defined (RTTHREAD)
|
---|
| 353 | #include "rtthread.h"
|
---|
| 354 | typedef rt_mutex_t wolfSSL_Mutex;
|
---|
[457] | 355 | #elif defined(WOLFSSL_SAFERTOS)
|
---|
| 356 | typedef struct wolfSSL_Mutex {
|
---|
| 357 | signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES];
|
---|
| 358 | xSemaphoreHandle mutex;
|
---|
| 359 | } wolfSSL_Mutex;
|
---|
| 360 | #elif defined(USE_WINDOWS_API)
|
---|
| 361 | typedef CRITICAL_SECTION wolfSSL_Mutex;
|
---|
| 362 | #elif defined(WOLFSSL_PTHREADS)
|
---|
| 363 | typedef pthread_mutex_t wolfSSL_Mutex;
|
---|
[464] | 364 | #elif defined(WOLFSSL_KTHREADS)
|
---|
| 365 | typedef struct mutex wolfSSL_Mutex;
|
---|
[457] | 366 | #elif defined(THREADX)
|
---|
| 367 | typedef TX_MUTEX wolfSSL_Mutex;
|
---|
| 368 | #elif defined(WOLFSSL_DEOS)
|
---|
| 369 | typedef mutex_handle_t wolfSSL_Mutex;
|
---|
| 370 | #elif defined(MICRIUM)
|
---|
| 371 | typedef OS_MUTEX wolfSSL_Mutex;
|
---|
| 372 | #elif defined(EBSNET)
|
---|
| 373 | typedef RTP_MUTEX wolfSSL_Mutex;
|
---|
| 374 | #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
|
---|
| 375 | typedef MUTEX_STRUCT wolfSSL_Mutex;
|
---|
| 376 | #elif defined(FREESCALE_FREE_RTOS)
|
---|
| 377 | typedef mutex_t wolfSSL_Mutex;
|
---|
| 378 | #elif defined(WOLFSSL_VXWORKS)
|
---|
| 379 | typedef SEM_ID wolfSSL_Mutex;
|
---|
| 380 | #elif defined(WOLFSSL_uITRON4)
|
---|
| 381 | typedef struct wolfSSL_Mutex {
|
---|
| 382 | T_CSEM sem ;
|
---|
| 383 | ID id ;
|
---|
| 384 | } wolfSSL_Mutex;
|
---|
| 385 | #elif defined(WOLFSSL_uTKERNEL2)
|
---|
| 386 | typedef struct wolfSSL_Mutex {
|
---|
| 387 | T_CSEM sem ;
|
---|
| 388 | ID id ;
|
---|
| 389 | } wolfSSL_Mutex;
|
---|
| 390 | #elif defined(WOLFSSL_MDK_ARM)
|
---|
| 391 | #if defined(WOLFSSL_CMSIS_RTOS)
|
---|
| 392 | typedef osMutexId wolfSSL_Mutex;
|
---|
| 393 | #else
|
---|
| 394 | typedef OS_MUT wolfSSL_Mutex;
|
---|
| 395 | #endif
|
---|
| 396 | #elif defined(WOLFSSL_CMSIS_RTOS)
|
---|
| 397 | typedef osMutexId wolfSSL_Mutex;
|
---|
| 398 | #elif defined(WOLFSSL_CMSIS_RTOSv2)
|
---|
| 399 | typedef osMutexId_t wolfSSL_Mutex;
|
---|
| 400 | #elif defined(WOLFSSL_TIRTOS)
|
---|
| 401 | typedef ti_sysbios_knl_Semaphore_Handle wolfSSL_Mutex;
|
---|
| 402 | #elif defined(WOLFSSL_FROSTED)
|
---|
| 403 | typedef mutex_t * wolfSSL_Mutex;
|
---|
| 404 | #elif defined(INTIME_RTOS)
|
---|
| 405 | typedef RTHANDLE wolfSSL_Mutex;
|
---|
| 406 | #elif defined(WOLFSSL_NUCLEUS_1_2)
|
---|
| 407 | typedef NU_SEMAPHORE wolfSSL_Mutex;
|
---|
| 408 | #elif defined(WOLFSSL_ZEPHYR)
|
---|
| 409 | typedef struct k_mutex wolfSSL_Mutex;
|
---|
| 410 | #elif defined(WOLFSSL_TELIT_M2MB)
|
---|
| 411 | typedef M2MB_OS_MTX_HANDLE wolfSSL_Mutex;
|
---|
[464] | 412 | #elif defined(WOLFSSL_USER_MUTEX)
|
---|
| 413 | /* typedef User_Mutex wolfSSL_Mutex; */
|
---|
| 414 | #elif defined(WOLFSSL_LINUXKM)
|
---|
| 415 | typedef struct mutex wolfSSL_Mutex;
|
---|
[457] | 416 | #else
|
---|
| 417 | #error Need a mutex type in multithreaded mode
|
---|
| 418 | #endif /* USE_WINDOWS_API */
|
---|
| 419 | #endif /* SINGLE_THREADED */
|
---|
| 420 |
|
---|
| 421 | /* Enable crypt HW mutex for Freescale MMCAU, PIC32MZ or STM32 */
|
---|
| 422 | #if defined(FREESCALE_MMCAU) || defined(WOLFSSL_MICROCHIP_PIC32MZ) || \
|
---|
[464] | 423 | defined(STM32_CRYPTO) || defined(STM32_HASH) || defined(STM32_RNG)
|
---|
[457] | 424 | #ifndef WOLFSSL_CRYPT_HW_MUTEX
|
---|
| 425 | #define WOLFSSL_CRYPT_HW_MUTEX 1
|
---|
| 426 | #endif
|
---|
| 427 | #endif /* FREESCALE_MMCAU */
|
---|
| 428 |
|
---|
| 429 | #ifndef WOLFSSL_CRYPT_HW_MUTEX
|
---|
| 430 | #define WOLFSSL_CRYPT_HW_MUTEX 0
|
---|
| 431 | #endif
|
---|
| 432 |
|
---|
| 433 | #if WOLFSSL_CRYPT_HW_MUTEX
|
---|
| 434 | /* wolfSSL_CryptHwMutexInit is called on first wolfSSL_CryptHwMutexLock,
|
---|
| 435 | however it's recommended to call this directly on Hw init to avoid possible
|
---|
| 436 | race condition where two calls to wolfSSL_CryptHwMutexLock are made at
|
---|
| 437 | the same time. */
|
---|
| 438 | int wolfSSL_CryptHwMutexInit(void);
|
---|
| 439 | int wolfSSL_CryptHwMutexLock(void);
|
---|
| 440 | int wolfSSL_CryptHwMutexUnLock(void);
|
---|
| 441 | #else
|
---|
| 442 | /* Define stubs, since HW mutex is disabled */
|
---|
| 443 | #define wolfSSL_CryptHwMutexInit() 0 /* Success */
|
---|
| 444 | #define wolfSSL_CryptHwMutexLock() 0 /* Success */
|
---|
| 445 | #define wolfSSL_CryptHwMutexUnLock() (void)0 /* Success */
|
---|
| 446 | #endif /* WOLFSSL_CRYPT_HW_MUTEX */
|
---|
| 447 |
|
---|
| 448 | /* Mutex functions */
|
---|
| 449 | WOLFSSL_API int wc_InitMutex(wolfSSL_Mutex*);
|
---|
| 450 | WOLFSSL_API wolfSSL_Mutex* wc_InitAndAllocMutex(void);
|
---|
| 451 | WOLFSSL_API int wc_FreeMutex(wolfSSL_Mutex*);
|
---|
| 452 | WOLFSSL_API int wc_LockMutex(wolfSSL_Mutex*);
|
---|
| 453 | WOLFSSL_API int wc_UnLockMutex(wolfSSL_Mutex*);
|
---|
| 454 | #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
|
---|
| 455 | /* dynamically set which mutex to use. unlock / lock is controlled by flag */
|
---|
| 456 | typedef void (mutex_cb)(int flag, int type, const char* file, int line);
|
---|
| 457 |
|
---|
| 458 | WOLFSSL_API int wc_LockMutex_ex(int flag, int type, const char* file, int line);
|
---|
| 459 | WOLFSSL_API int wc_SetMutexCb(mutex_cb* cb);
|
---|
| 460 | #endif
|
---|
| 461 |
|
---|
| 462 | /* main crypto initialization function */
|
---|
| 463 | WOLFSSL_API int wolfCrypt_Init(void);
|
---|
| 464 | WOLFSSL_API int wolfCrypt_Cleanup(void);
|
---|
| 465 |
|
---|
[464] | 466 | #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
|
---|
| 467 | WOLFSSL_API long wolfCrypt_heap_peakAllocs_checkpoint(void);
|
---|
| 468 | WOLFSSL_API long wolfCrypt_heap_peakBytes_checkpoint(void);
|
---|
| 469 | #endif
|
---|
[457] | 470 |
|
---|
[464] | 471 |
|
---|
[457] | 472 | /* FILESYSTEM SECTION */
|
---|
| 473 | /* filesystem abstraction layer, used by ssl.c */
|
---|
| 474 | #ifndef NO_FILESYSTEM
|
---|
| 475 |
|
---|
| 476 | #if defined(EBSNET)
|
---|
| 477 | #include "vfapi.h"
|
---|
| 478 | #include "vfile.h"
|
---|
| 479 |
|
---|
| 480 | int ebsnet_fseek(int a, long b, int c); /* Not prototyped in vfile.h per
|
---|
| 481 | * EBSnet feedback */
|
---|
| 482 |
|
---|
| 483 | #define XFILE int
|
---|
| 484 | #define XFOPEN(NAME, MODE) vf_open((const char *)NAME, VO_RDONLY, 0);
|
---|
| 485 | #define XFSEEK ebsnet_fseek
|
---|
| 486 | #define XFTELL vf_tell
|
---|
| 487 | #define XREWIND vf_rewind
|
---|
| 488 | #define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT)
|
---|
| 489 | #define XFWRITE(BUF, SZ, AMT, FD) vf_write(FD, BUF, SZ*AMT)
|
---|
| 490 | #define XFCLOSE vf_close
|
---|
| 491 | #define XSEEK_END VSEEK_END
|
---|
| 492 | #define XBADFILE -1
|
---|
| 493 | #define XFGETS(b,s,f) -2 /* Not ported yet */
|
---|
[464] | 494 |
|
---|
[457] | 495 | #elif defined(LSR_FS)
|
---|
| 496 | #include <fs.h>
|
---|
| 497 | #define XFILE struct fs_file*
|
---|
| 498 | #define XFOPEN(NAME, MODE) fs_open((char*)NAME);
|
---|
| 499 | #define XFSEEK(F, O, W) (void)F
|
---|
| 500 | #define XFTELL(F) (F)->len
|
---|
| 501 | #define XREWIND(F) (void)F
|
---|
| 502 | #define XFREAD(BUF, SZ, AMT, F) fs_read(F, (char*)BUF, SZ*AMT)
|
---|
| 503 | #define XFWRITE(BUF, SZ, AMT, F) fs_write(F, (char*)BUF, SZ*AMT)
|
---|
| 504 | #define XFCLOSE fs_close
|
---|
| 505 | #define XSEEK_END 0
|
---|
| 506 | #define XBADFILE NULL
|
---|
[464] | 507 | #define XFGETS(b,s,f) -2 /* Not ported yet */
|
---|
| 508 |
|
---|
[457] | 509 | #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
|
---|
| 510 | #define XFILE MQX_FILE_PTR
|
---|
| 511 | #define XFOPEN fopen
|
---|
| 512 | #define XFSEEK fseek
|
---|
| 513 | #define XFTELL ftell
|
---|
| 514 | #define XREWIND(F) fseek(F, 0, IO_SEEK_SET)
|
---|
| 515 | #define XFREAD fread
|
---|
| 516 | #define XFWRITE fwrite
|
---|
| 517 | #define XFCLOSE fclose
|
---|
| 518 | #define XSEEK_END IO_SEEK_END
|
---|
| 519 | #define XBADFILE NULL
|
---|
| 520 | #define XFGETS fgets
|
---|
[464] | 521 |
|
---|
[457] | 522 | #elif defined(WOLFSSL_DEOS)
|
---|
| 523 | #define NO_FILESYSTEM
|
---|
| 524 | #warning "TODO - DDC-I Certifiable Fast File System for Deos is not integrated"
|
---|
[464] | 525 | /* #define XFILE bfd * */
|
---|
[457] | 526 |
|
---|
| 527 | #elif defined(MICRIUM)
|
---|
| 528 | #include <fs_api.h>
|
---|
| 529 | #define XFILE FS_FILE*
|
---|
| 530 | #define XFOPEN fs_fopen
|
---|
| 531 | #define XFSEEK fs_fseek
|
---|
| 532 | #define XFTELL fs_ftell
|
---|
| 533 | #define XREWIND fs_rewind
|
---|
| 534 | #define XFREAD fs_fread
|
---|
| 535 | #define XFWRITE fs_fwrite
|
---|
| 536 | #define XFCLOSE fs_fclose
|
---|
| 537 | #define XSEEK_END FS_SEEK_END
|
---|
| 538 | #define XBADFILE NULL
|
---|
| 539 | #define XFGETS(b,s,f) -2 /* Not ported yet */
|
---|
[464] | 540 |
|
---|
[457] | 541 | #elif defined(WOLFSSL_NUCLEUS_1_2)
|
---|
| 542 | #include "fal/inc/fal.h"
|
---|
| 543 | #define XFILE FILE*
|
---|
| 544 | #define XFOPEN fopen
|
---|
| 545 | #define XFSEEK fseek
|
---|
| 546 | #define XFTELL ftell
|
---|
| 547 | #define XREWIND rewind
|
---|
| 548 | #define XFREAD fread
|
---|
| 549 | #define XFWRITE fwrite
|
---|
| 550 | #define XFCLOSE fclose
|
---|
| 551 | #define XSEEK_END PSEEK_END
|
---|
| 552 | #define XBADFILE NULL
|
---|
[464] | 553 |
|
---|
[457] | 554 | #elif defined(WOLFSSL_APACHE_MYNEWT)
|
---|
| 555 | #include <fs/fs.h>
|
---|
| 556 | #define XFILE struct fs_file*
|
---|
| 557 |
|
---|
| 558 | #define XFOPEN mynewt_fopen
|
---|
| 559 | #define XFSEEK mynewt_fseek
|
---|
| 560 | #define XFTELL mynewt_ftell
|
---|
| 561 | #define XREWIND mynewt_rewind
|
---|
| 562 | #define XFREAD mynewt_fread
|
---|
| 563 | #define XFWRITE mynewt_fwrite
|
---|
| 564 | #define XFCLOSE mynewt_fclose
|
---|
| 565 | #define XSEEK_END 2
|
---|
| 566 | #define XBADFILE NULL
|
---|
| 567 | #define XFGETS(b,s,f) -2 /* Not ported yet */
|
---|
[464] | 568 |
|
---|
[457] | 569 | #elif defined(WOLFSSL_ZEPHYR)
|
---|
| 570 | #include <fs.h>
|
---|
| 571 |
|
---|
| 572 | #define XFILE struct fs_file_t*
|
---|
| 573 | #define STAT struct fs_dirent
|
---|
| 574 |
|
---|
| 575 | XFILE z_fs_open(const char* filename, const char* perm);
|
---|
| 576 | int z_fs_close(XFILE file);
|
---|
| 577 |
|
---|
| 578 | #define XFOPEN z_fs_open
|
---|
| 579 | #define XFCLOSE z_fs_close
|
---|
| 580 | #define XFSEEK fs_seek
|
---|
| 581 | #define XFTELL fs_tell
|
---|
| 582 | #define XFREWIND fs_rewind
|
---|
| 583 | #define XREWIND(F) fs_seek(F, 0, FS_SEEK_SET)
|
---|
| 584 | #define XFREAD(P,S,N,F) fs_read(F, P, S*N)
|
---|
| 585 | #define XFWRITE(P,S,N,F) fs_write(F, P, S*N)
|
---|
| 586 | #define XSEEK_END FS_SEEK_END
|
---|
| 587 | #define XBADFILE NULL
|
---|
| 588 | #define XFGETS(b,s,f) -2 /* Not ported yet */
|
---|
| 589 |
|
---|
| 590 | #elif defined(WOLFSSL_TELIT_M2MB)
|
---|
| 591 | #define XFILE INT32
|
---|
| 592 | #define XFOPEN(NAME, MODE) m2mb_fs_open((NAME), 0, (MODE))
|
---|
| 593 | #define XFSEEK(F, O, W) m2mb_fs_lseek((F), (O), (W))
|
---|
| 594 | #define XFTELL(F) m2mb_fs_lseek((F), 0, M2MB_SEEK_END)
|
---|
| 595 | #define XREWIND(F) (void)F
|
---|
| 596 | #define XFREAD(BUF, SZ, AMT, F) m2mb_fs_read((F), (BUF), (SZ)*(AMT))
|
---|
| 597 | #define XFWRITE(BUF, SZ, AMT, F) m2mb_fs_write((F), (BUF), (SZ)*(AMT))
|
---|
| 598 | #define XFCLOSE m2mb_fs_close
|
---|
| 599 | #define XSEEK_END M2MB_SEEK_END
|
---|
| 600 | #define XBADFILE -1
|
---|
| 601 | #define XFGETS(b,s,f) -2 /* Not ported yet */
|
---|
| 602 |
|
---|
[464] | 603 | #elif defined (WOLFSSL_XILINX)
|
---|
| 604 | #include "xsdps.h"
|
---|
| 605 | #include "ff.h"
|
---|
| 606 |
|
---|
| 607 | /* workaround to declare variable and provide type */
|
---|
| 608 | #define XFILE FIL curFile; FIL*
|
---|
| 609 | #define XFOPEN(NAME, MODE) ({ FRESULT res; res = f_open(&curFile, (NAME), (FA_OPEN_ALWAYS | FA_WRITE | FA_READ)); (res == FR_OK) ? &curFile : NULL; })
|
---|
| 610 | #define XFSEEK(F, O, W) f_lseek((F), (O))
|
---|
| 611 | #define XFTELL(F) f_tell((F))
|
---|
| 612 | #define XREWIND(F) f_rewind((F))
|
---|
| 613 | #define XFREAD(BUF, SZ, AMT, F) ({ FRESULT res; UINT br; res = f_read((F), (BUF), (SZ)*(AMT), &br); (void)br; res; })
|
---|
| 614 | #define XFWRITE(BUF, SZ, AMT, F) ({ FRESULT res; UINT written; res = f_write((F), (BUF), (SZ)*(AMT), &written); (void)written; res; })
|
---|
| 615 | #define XFCLOSE(F) f_close((F))
|
---|
| 616 | #define XSEEK_END 0
|
---|
| 617 | #define XBADFILE NULL
|
---|
| 618 | #define XFGETS(b,s,f) f_gets((b), (s), (f))
|
---|
| 619 |
|
---|
| 620 | #elif defined(FUSION_RTOS)
|
---|
| 621 | #include <fclstdio.h>
|
---|
| 622 | #include <fclunistd.h>
|
---|
| 623 | #include <fcldirent.h>
|
---|
| 624 | #include <sys/fclstat.h>
|
---|
| 625 | #include <fclstring.h>
|
---|
| 626 | #include <fcl_os.h>
|
---|
| 627 | #define XFILE FCL_FILE*
|
---|
| 628 | #define XFOPEN FCL_FOPEN
|
---|
| 629 | #define XFSEEK FCL_FSEEK
|
---|
| 630 | #define XFTELL FCL_FTELL
|
---|
| 631 | #define XREWIND FCL_REWIND
|
---|
| 632 | #define XFREAD FCL_FREAD
|
---|
| 633 | #define XFWRITE FCL_FWRITE
|
---|
| 634 | #define XFCLOSE FCL_FCLOSE
|
---|
| 635 | #define XSEEK_END SEEK_END
|
---|
| 636 | #define XBADFILE NULL
|
---|
| 637 | #define XFGETS FCL_FGETS
|
---|
| 638 | #define XFPUTS FCL_FPUTS
|
---|
| 639 | #define XFPRINTF FCL_FPRINTF
|
---|
| 640 | #define XVFPRINTF FCL_VFPRINTF
|
---|
| 641 | #define XVSNPRINTF FCL_VSNPRINTF
|
---|
| 642 | #define XSNPRINTF FCL_SNPRINTF
|
---|
| 643 | #define XSPRINTF FCL_SPRINTF
|
---|
| 644 | #define DIR FCL_DIR
|
---|
| 645 | #define stat FCL_STAT
|
---|
| 646 | #define opendir FCL_OPENDIR
|
---|
| 647 | #define closedir FCL_CLOSEDIR
|
---|
| 648 | #define readdir FCL_READDIR
|
---|
| 649 | #define dirent fclDirent
|
---|
| 650 | #define strncasecmp FCL_STRNCASECMP
|
---|
| 651 |
|
---|
| 652 | /* FUSION SPECIFIC ERROR CODE */
|
---|
| 653 | #define FUSION_IO_SEND_E 63
|
---|
| 654 |
|
---|
[457] | 655 | #elif defined(WOLFSSL_USER_FILESYSTEM)
|
---|
| 656 | /* To be defined in user_settings.h */
|
---|
| 657 | #else
|
---|
| 658 | /* stdio, default case */
|
---|
| 659 | #include <stdio.h>
|
---|
| 660 | #define XFILE FILE*
|
---|
| 661 | #if defined(WOLFSSL_MDK_ARM)
|
---|
| 662 | extern FILE * wolfSSL_fopen(const char *name, const char *mode) ;
|
---|
| 663 | #define XFOPEN wolfSSL_fopen
|
---|
| 664 | #else
|
---|
| 665 | #define XFOPEN fopen
|
---|
| 666 | #endif
|
---|
[464] | 667 | #define XFDOPEN fdopen
|
---|
[457] | 668 | #define XFSEEK fseek
|
---|
| 669 | #define XFTELL ftell
|
---|
| 670 | #define XREWIND rewind
|
---|
| 671 | #define XFREAD fread
|
---|
| 672 | #define XFWRITE fwrite
|
---|
| 673 | #define XFCLOSE fclose
|
---|
| 674 | #define XSEEK_END SEEK_END
|
---|
| 675 | #define XBADFILE NULL
|
---|
| 676 | #define XFGETS fgets
|
---|
[464] | 677 | #define XFPRINTF fprintf
|
---|
[457] | 678 |
|
---|
| 679 | #if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR)\
|
---|
| 680 | && !defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
|
---|
| 681 | #include <dirent.h>
|
---|
| 682 | #include <unistd.h>
|
---|
| 683 | #include <sys/stat.h>
|
---|
[464] | 684 | #define XWRITE write
|
---|
| 685 | #define XREAD read
|
---|
| 686 | #define XCLOSE close
|
---|
[457] | 687 | #endif
|
---|
| 688 | #endif
|
---|
| 689 |
|
---|
[464] | 690 | /* Defaults, user may over-ride with user_settings.h or in a porting section
|
---|
| 691 | * above
|
---|
| 692 | */
|
---|
| 693 | #ifndef XVFPRINTF
|
---|
| 694 | #define XVFPRINTF vfprintf
|
---|
| 695 | #endif
|
---|
| 696 | #ifndef XVSNPRINTF
|
---|
| 697 | #define XVSNPRINTF vsnprintf
|
---|
| 698 | #endif
|
---|
| 699 | #ifndef XFPUTS
|
---|
| 700 | #define XFPUTS fputs
|
---|
| 701 | #endif
|
---|
| 702 | #ifndef XSPRINTF
|
---|
| 703 | #define XSPRINTF sprintf
|
---|
| 704 | #endif
|
---|
| 705 |
|
---|
[457] | 706 | #ifndef MAX_FILENAME_SZ
|
---|
| 707 | #define MAX_FILENAME_SZ 256 /* max file name length */
|
---|
| 708 | #endif
|
---|
| 709 | #ifndef MAX_PATH
|
---|
| 710 | #define MAX_PATH 256
|
---|
| 711 | #endif
|
---|
| 712 |
|
---|
[464] | 713 | WOLFSSL_LOCAL int wc_FileLoad(const char* fname, unsigned char** buf,
|
---|
| 714 | size_t* bufLen, void* heap);
|
---|
| 715 |
|
---|
[457] | 716 | #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_NUCLEUS) && \
|
---|
| 717 | !defined(WOLFSSL_NUCLEUS_1_2)
|
---|
| 718 | typedef struct ReadDirCtx {
|
---|
| 719 | #ifdef USE_WINDOWS_API
|
---|
| 720 | WIN32_FIND_DATAA FindFileData;
|
---|
| 721 | HANDLE hFind;
|
---|
| 722 | #elif defined(WOLFSSL_ZEPHYR)
|
---|
| 723 | struct fs_dirent entry;
|
---|
| 724 | struct fs_dir_t dir;
|
---|
| 725 | struct fs_dirent s;
|
---|
| 726 | struct fs_dir_t* dirp;
|
---|
| 727 |
|
---|
| 728 | #elif defined(WOLFSSL_TELIT_M2MB)
|
---|
| 729 | M2MB_DIR_T* dir;
|
---|
| 730 | struct M2MB_DIRENT* entry;
|
---|
| 731 | struct M2MB_STAT s;
|
---|
| 732 | #else
|
---|
| 733 | struct dirent* entry;
|
---|
| 734 | DIR* dir;
|
---|
| 735 | struct stat s;
|
---|
| 736 | #endif
|
---|
| 737 | char name[MAX_FILENAME_SZ];
|
---|
| 738 | } ReadDirCtx;
|
---|
| 739 |
|
---|
| 740 | #define WC_READDIR_NOFILE -1
|
---|
| 741 |
|
---|
| 742 | WOLFSSL_API int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name);
|
---|
| 743 | WOLFSSL_API int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name);
|
---|
| 744 | WOLFSSL_API void wc_ReadDirClose(ReadDirCtx* ctx);
|
---|
| 745 | #endif /* !NO_WOLFSSL_DIR */
|
---|
| 746 |
|
---|
| 747 | #endif /* !NO_FILESYSTEM */
|
---|
| 748 |
|
---|
| 749 |
|
---|
| 750 | /* MIN/MAX MACRO SECTION */
|
---|
| 751 | /* Windows API defines its own min() macro. */
|
---|
| 752 | #if defined(USE_WINDOWS_API)
|
---|
| 753 | #if defined(min) || defined(WOLFSSL_MYSQL_COMPATIBLE)
|
---|
| 754 | #define WOLFSSL_HAVE_MIN
|
---|
| 755 | #endif /* min */
|
---|
| 756 | #if defined(max) || defined(WOLFSSL_MYSQL_COMPATIBLE)
|
---|
| 757 | #define WOLFSSL_HAVE_MAX
|
---|
| 758 | #endif /* max */
|
---|
| 759 | #endif /* USE_WINDOWS_API */
|
---|
| 760 |
|
---|
| 761 |
|
---|
| 762 | /* TIME SECTION */
|
---|
| 763 | /* Time functions */
|
---|
| 764 | #ifndef NO_ASN_TIME
|
---|
| 765 | #if defined(USER_TIME)
|
---|
| 766 | /* Use our gmtime and time_t/struct tm types.
|
---|
| 767 | Only needs seconds since EPOCH using XTIME function.
|
---|
| 768 | time_t XTIME(time_t * timer) {}
|
---|
| 769 | */
|
---|
| 770 | #define WOLFSSL_GMTIME
|
---|
| 771 | #ifndef HAVE_TM_TYPE
|
---|
| 772 | #define USE_WOLF_TM
|
---|
| 773 | #endif
|
---|
| 774 | #ifndef HAVE_TIME_T_TYPE
|
---|
| 775 | #define USE_WOLF_TIME_T
|
---|
| 776 | #endif
|
---|
| 777 |
|
---|
| 778 | #elif defined(TIME_OVERRIDES)
|
---|
| 779 | /* Override XTIME() and XGMTIME() functionality.
|
---|
| 780 | Requires user to provide these functions:
|
---|
| 781 | time_t XTIME(time_t * timer) {}
|
---|
| 782 | struct tm* XGMTIME(const time_t* timer, struct tm* tmp) {}
|
---|
| 783 | */
|
---|
| 784 | #ifndef HAVE_TIME_T_TYPE
|
---|
| 785 | #define USE_WOLF_TIME_T
|
---|
| 786 | #endif
|
---|
| 787 | #ifndef HAVE_TM_TYPE
|
---|
| 788 | #define USE_WOLF_TM
|
---|
| 789 | #endif
|
---|
| 790 | #define NEED_TMP_TIME
|
---|
| 791 |
|
---|
| 792 | #elif defined(WOLFSSL_XILINX)
|
---|
[464] | 793 | #ifndef XTIME
|
---|
| 794 | #define XTIME(t1) xilinx_time((t1))
|
---|
| 795 | #endif
|
---|
[457] | 796 | #include <time.h>
|
---|
| 797 |
|
---|
| 798 | #elif defined(HAVE_RTP_SYS)
|
---|
| 799 | #include "os.h" /* dc_rtc_api needs */
|
---|
| 800 | #include "dc_rtc_api.h" /* to get current time */
|
---|
| 801 |
|
---|
| 802 | /* uses parital <time.h> structures */
|
---|
| 803 | #define XTIME(tl) (0)
|
---|
| 804 | #define XGMTIME(c, t) rtpsys_gmtime((c))
|
---|
| 805 |
|
---|
| 806 | #elif defined(WOLFSSL_DEOS)
|
---|
| 807 | #define XTIME(t1) deos_time((t1))
|
---|
| 808 | #define WOLFSSL_GMTIME
|
---|
| 809 | #define USE_WOLF_TM
|
---|
| 810 | #define USE_WOLF_TIME_T
|
---|
| 811 |
|
---|
| 812 | #elif defined(MICRIUM)
|
---|
| 813 | #include <clk.h>
|
---|
| 814 | #include <time.h>
|
---|
| 815 | #define XTIME(t1) micrium_time((t1))
|
---|
| 816 | #define WOLFSSL_GMTIME
|
---|
| 817 |
|
---|
| 818 | #elif defined(MICROCHIP_TCPIP_V5) || defined(MICROCHIP_TCPIP)
|
---|
| 819 | #include <time.h>
|
---|
[464] | 820 | extern time_t pic32_time(time_t* timer);
|
---|
[457] | 821 | #define XTIME(t1) pic32_time((t1))
|
---|
| 822 | #define XGMTIME(c, t) gmtime((c))
|
---|
| 823 |
|
---|
| 824 | #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
|
---|
| 825 | #ifdef FREESCALE_MQX_4_0
|
---|
| 826 | #include <time.h>
|
---|
| 827 | extern time_t mqx_time(time_t* timer);
|
---|
| 828 | #else
|
---|
| 829 | #define HAVE_GMTIME_R
|
---|
| 830 | #endif
|
---|
| 831 | #define XTIME(t1) mqx_time((t1))
|
---|
| 832 |
|
---|
| 833 | #elif defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS) || defined(FREESCALE_KSDK_FREERTOS)
|
---|
| 834 | #include <time.h>
|
---|
| 835 | #ifndef XTIME
|
---|
| 836 | /*extern time_t ksdk_time(time_t* timer);*/
|
---|
| 837 | #define XTIME(t1) ksdk_time((t1))
|
---|
| 838 | #endif
|
---|
| 839 | #define XGMTIME(c, t) gmtime((c))
|
---|
| 840 |
|
---|
| 841 | #elif defined(WOLFSSL_ATMEL) && defined(WOLFSSL_ATMEL_TIME)
|
---|
| 842 | #define XTIME(t1) atmel_get_curr_time_and_date((t1))
|
---|
| 843 | #define WOLFSSL_GMTIME
|
---|
| 844 | #define USE_WOLF_TM
|
---|
| 845 | #define USE_WOLF_TIME_T
|
---|
| 846 |
|
---|
| 847 | #elif defined(WOLFSSL_WICED)
|
---|
| 848 | #include <time.h>
|
---|
| 849 | time_t wiced_pseudo_unix_epoch_time(time_t * timer);
|
---|
| 850 | #define XTIME(t1) wiced_pseudo_unix_epoch_time((t1))
|
---|
| 851 | #define HAVE_GMTIME_R
|
---|
| 852 |
|
---|
| 853 | #elif defined(IDIRECT_DEV_TIME)
|
---|
| 854 | /*Gets the timestamp from cloak software owned by VT iDirect
|
---|
| 855 | in place of time() from <time.h> */
|
---|
| 856 | #include <time.h>
|
---|
| 857 | #define XTIME(t1) idirect_time((t1))
|
---|
| 858 | #define XGMTIME(c, t) gmtime((c))
|
---|
| 859 |
|
---|
| 860 | #elif defined(_WIN32_WCE)
|
---|
| 861 | #include <windows.h>
|
---|
| 862 | #define XTIME(t1) windows_time((t1))
|
---|
| 863 | #define WOLFSSL_GMTIME
|
---|
| 864 |
|
---|
| 865 | #elif defined(WOLFSSL_APACHE_MYNEWT)
|
---|
| 866 | #include "os/os_time.h"
|
---|
| 867 | #define XTIME(t1) mynewt_time((t1))
|
---|
| 868 | #define WOLFSSL_GMTIME
|
---|
| 869 | #define USE_WOLF_TM
|
---|
| 870 | #define USE_WOLF_TIME_T
|
---|
| 871 |
|
---|
| 872 | #elif defined(WOLFSSL_ZEPHYR)
|
---|
| 873 | #ifndef _POSIX_C_SOURCE
|
---|
| 874 | #include <posix/time.h>
|
---|
| 875 | #else
|
---|
| 876 | #include <sys/time.h>
|
---|
| 877 | #endif
|
---|
| 878 |
|
---|
| 879 | typedef signed int time_t;
|
---|
| 880 |
|
---|
| 881 | time_t z_time(time_t *timer);
|
---|
| 882 |
|
---|
| 883 | #define XTIME(tl) z_time((tl))
|
---|
| 884 | #define XGMTIME(c, t) gmtime((c))
|
---|
| 885 | #define WOLFSSL_GMTIME
|
---|
| 886 |
|
---|
| 887 | #define USE_WOLF_TM
|
---|
| 888 |
|
---|
| 889 | #elif defined(WOLFSSL_TELIT_M2MB)
|
---|
| 890 | typedef long time_t;
|
---|
| 891 | extern time_t m2mb_xtime(time_t * timer);
|
---|
| 892 | #define XTIME(tl) m2mb_xtime((tl))
|
---|
| 893 | #ifdef WOLFSSL_TLS13
|
---|
| 894 | extern time_t m2mb_xtime_ms(time_t * timer);
|
---|
| 895 | #define XTIME_MS(tl) m2mb_xtime_ms((tl))
|
---|
| 896 | #endif
|
---|
| 897 | #ifndef NO_CRYPT_BENCHMARK
|
---|
| 898 | extern double m2mb_xtime_bench(int reset);
|
---|
| 899 | #define WOLFSSL_CURRTIME_REMAP m2mb_xtime_bench
|
---|
| 900 | #endif
|
---|
| 901 | #define XGMTIME(c, t) gmtime((c))
|
---|
| 902 | #define WOLFSSL_GMTIME
|
---|
| 903 | #define USE_WOLF_TM
|
---|
| 904 |
|
---|
[464] | 905 |
|
---|
| 906 | #elif defined(WOLFSSL_LINUXKM)
|
---|
| 907 | #ifdef BUILDING_WOLFSSL
|
---|
| 908 |
|
---|
| 909 | /* includes are all above, with incompatible warnings masked out. */
|
---|
| 910 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 5, 0)
|
---|
| 911 | typedef __kernel_time_t time_t;
|
---|
| 912 | #else
|
---|
| 913 | typedef __kernel_time64_t time_t;
|
---|
| 914 | #endif
|
---|
| 915 | extern time_t time(time_t * timer);
|
---|
| 916 | #define XTIME time
|
---|
| 917 | #define WOLFSSL_GMTIME
|
---|
| 918 | #define XGMTIME(c, t) gmtime(c)
|
---|
| 919 | #define NO_TIMEVAL 1
|
---|
| 920 |
|
---|
| 921 | #endif /* BUILDING_WOLFSSL */
|
---|
| 922 |
|
---|
[457] | 923 | #else
|
---|
| 924 | /* default */
|
---|
| 925 | /* uses complete <time.h> facility */
|
---|
| 926 | #include <time.h>
|
---|
| 927 | #if defined(HAVE_SYS_TIME_H)
|
---|
| 928 | #include <sys/time.h>
|
---|
| 929 | #endif
|
---|
| 930 |
|
---|
| 931 | /* PowerPC time_t is int */
|
---|
| 932 | #ifdef __PPC__
|
---|
| 933 | #define TIME_T_NOT_64BIT
|
---|
| 934 | #endif
|
---|
| 935 | #endif
|
---|
| 936 |
|
---|
| 937 | #ifdef SIZEOF_TIME_T
|
---|
| 938 | /* check if size of time_t from autoconf is less than 8 bytes (64bits) */
|
---|
| 939 | #if SIZEOF_TIME_T < 8
|
---|
| 940 | #undef TIME_T_NOT_64BIT
|
---|
| 941 | #define TIME_T_NOT_64BIT
|
---|
| 942 | #endif
|
---|
| 943 | #endif
|
---|
| 944 | #ifdef TIME_T_NOT_LONG
|
---|
| 945 | /* one old reference to TIME_T_NOT_LONG in GCC-ARM example README
|
---|
| 946 | * this keeps support for the old macro name */
|
---|
| 947 | #undef TIME_T_NOT_64BIT
|
---|
| 948 | #define TIME_T_NOT_64BIT
|
---|
| 949 | #endif
|
---|
| 950 |
|
---|
| 951 | /* Map default time functions */
|
---|
| 952 | #if !defined(XTIME) && !defined(TIME_OVERRIDES) && !defined(USER_TIME)
|
---|
| 953 | #ifdef TEST_BEFORE_DATE
|
---|
| 954 | #define XTIME(tl) (946681200UL) /* Jan 1, 2000 */
|
---|
| 955 | #else
|
---|
| 956 | #define XTIME(tl) time((tl))
|
---|
| 957 | #endif
|
---|
| 958 | #endif
|
---|
| 959 | #if !defined(XGMTIME) && !defined(TIME_OVERRIDES)
|
---|
[464] | 960 | /* Always use gmtime_r if available. */
|
---|
| 961 | #if defined(HAVE_GMTIME_R)
|
---|
[457] | 962 | #define XGMTIME(c, t) gmtime_r((c), (t))
|
---|
| 963 | #define NEED_TMP_TIME
|
---|
[464] | 964 | #else
|
---|
| 965 | #define XGMTIME(c, t) gmtime((c))
|
---|
[457] | 966 | #endif
|
---|
| 967 | #endif
|
---|
| 968 | #if !defined(XVALIDATE_DATE) && !defined(HAVE_VALIDATE_DATE)
|
---|
| 969 | #define USE_WOLF_VALIDDATE
|
---|
[464] | 970 | #define XVALIDATE_DATE(d, f, t) wc_ValidateDate((d), (f), (t))
|
---|
[457] | 971 | #endif
|
---|
| 972 |
|
---|
| 973 | /* wolf struct tm and time_t */
|
---|
| 974 | #if defined(USE_WOLF_TM)
|
---|
| 975 | struct tm {
|
---|
| 976 | int tm_sec; /* seconds after the minute [0-60] */
|
---|
| 977 | int tm_min; /* minutes after the hour [0-59] */
|
---|
| 978 | int tm_hour; /* hours since midnight [0-23] */
|
---|
| 979 | int tm_mday; /* day of the month [1-31] */
|
---|
| 980 | int tm_mon; /* months since January [0-11] */
|
---|
| 981 | int tm_year; /* years since 1900 */
|
---|
| 982 | int tm_wday; /* days since Sunday [0-6] */
|
---|
| 983 | int tm_yday; /* days since January 1 [0-365] */
|
---|
| 984 | int tm_isdst; /* Daylight Savings Time flag */
|
---|
| 985 | long tm_gmtoff; /* offset from CUT in seconds */
|
---|
| 986 | char *tm_zone; /* timezone abbreviation */
|
---|
| 987 | };
|
---|
| 988 | #endif /* USE_WOLF_TM */
|
---|
| 989 | #if defined(USE_WOLF_TIME_T)
|
---|
| 990 | typedef long time_t;
|
---|
| 991 | #endif
|
---|
| 992 | #if defined(USE_WOLF_SUSECONDS_T)
|
---|
| 993 | typedef long suseconds_t;
|
---|
| 994 | #endif
|
---|
| 995 | #if defined(USE_WOLF_TIMEVAL_T)
|
---|
| 996 | struct timeval
|
---|
| 997 | {
|
---|
| 998 | time_t tv_sec;
|
---|
| 999 | suseconds_t tv_usec;
|
---|
| 1000 | };
|
---|
| 1001 | #endif
|
---|
| 1002 |
|
---|
| 1003 | /* forward declarations */
|
---|
| 1004 | #if defined(USER_TIME)
|
---|
| 1005 | struct tm* gmtime(const time_t* timer);
|
---|
| 1006 | extern time_t XTIME(time_t * timer);
|
---|
| 1007 |
|
---|
| 1008 | #ifdef STACK_TRAP
|
---|
| 1009 | /* for stack trap tracking, don't call os gmtime on OS X/linux,
|
---|
| 1010 | uses a lot of stack spce */
|
---|
| 1011 | extern time_t time(time_t * timer);
|
---|
| 1012 | #define XTIME(tl) time((tl))
|
---|
| 1013 | #endif /* STACK_TRAP */
|
---|
| 1014 |
|
---|
| 1015 | #elif defined(TIME_OVERRIDES)
|
---|
| 1016 | extern time_t XTIME(time_t * timer);
|
---|
| 1017 | extern struct tm* XGMTIME(const time_t* timer, struct tm* tmp);
|
---|
| 1018 | #elif defined(WOLFSSL_GMTIME)
|
---|
| 1019 | struct tm* gmtime(const time_t* timer);
|
---|
| 1020 | #endif
|
---|
| 1021 | #endif /* NO_ASN_TIME */
|
---|
| 1022 |
|
---|
| 1023 |
|
---|
| 1024 | #ifndef WOLFSSL_LEANPSK
|
---|
| 1025 | char* mystrnstr(const char* s1, const char* s2, unsigned int n);
|
---|
| 1026 | #endif
|
---|
| 1027 |
|
---|
| 1028 | #ifndef FILE_BUFFER_SIZE
|
---|
[464] | 1029 | #define FILE_BUFFER_SIZE 1024 /* default static file buffer size for input, \
|
---|
[457] | 1030 | will use dynamic buffer if not big enough */
|
---|
| 1031 | #endif
|
---|
| 1032 |
|
---|
| 1033 | #ifdef HAVE_CAVIUM_OCTEON_SYNC
|
---|
| 1034 | /* By default, the OCTEON's global variables are all thread local. This
|
---|
| 1035 | * tag allows them to be shared between threads. */
|
---|
| 1036 | #include "cvmx-platform.h"
|
---|
| 1037 | #define WOLFSSL_GLOBAL CVMX_SHARED
|
---|
| 1038 | #else
|
---|
| 1039 | #define WOLFSSL_GLOBAL
|
---|
| 1040 | #endif
|
---|
| 1041 |
|
---|
| 1042 | #ifdef WOLFSSL_DSP
|
---|
| 1043 | #include "wolfssl_dsp.h"
|
---|
| 1044 |
|
---|
| 1045 | /* callbacks for setting handle */
|
---|
| 1046 | typedef int (*wolfSSL_DSP_Handle_cb)(remote_handle64 *handle, int finished,
|
---|
| 1047 | void *ctx);
|
---|
| 1048 | WOLFSSL_API int wolfSSL_GetHandleCbSet();
|
---|
| 1049 | WOLFSSL_API int wolfSSL_SetHandleCb(wolfSSL_DSP_Handle_cb in);
|
---|
| 1050 | WOLFSSL_LOCAL int wolfSSL_InitHandle();
|
---|
| 1051 | WOLFSSL_LOCAL void wolfSSL_CleanupHandle();
|
---|
| 1052 | #endif
|
---|
| 1053 |
|
---|
| 1054 | #ifdef WOLFSSL_SCE
|
---|
| 1055 | #ifndef WOLFSSL_SCE_GSCE_HANDLE
|
---|
| 1056 | #define WOLFSSL_SCE_GSCE_HANDLE g_sce
|
---|
| 1057 | #endif
|
---|
| 1058 | #endif
|
---|
| 1059 |
|
---|
| 1060 | #ifdef __cplusplus
|
---|
| 1061 | } /* extern "C" */
|
---|
| 1062 | #endif
|
---|
| 1063 |
|
---|
| 1064 | #endif /* WOLF_CRYPT_PORT_H */
|
---|