wc_port.h 35 KB

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