types.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /* types.h
  2. *
  3. * Copyright (C) 2006-2017 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. #ifndef WOLF_CRYPT_TYPES_H
  22. #define WOLF_CRYPT_TYPES_H
  23. #include <wolfssl/wolfcrypt/settings.h>
  24. #include <wolfssl/wolfcrypt/wc_port.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #if defined(WORDS_BIGENDIAN)
  29. #define BIG_ENDIAN_ORDER
  30. #endif
  31. #ifndef BIG_ENDIAN_ORDER
  32. #define LITTLE_ENDIAN_ORDER
  33. #endif
  34. #ifndef WOLFSSL_TYPES
  35. #ifndef byte
  36. typedef unsigned char byte;
  37. #endif
  38. typedef unsigned short word16;
  39. typedef unsigned int word32;
  40. typedef byte word24[3];
  41. #endif
  42. /* try to set SIZEOF_LONG or LONG_LONG if user didn't */
  43. #if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__) && !defined(__EMSCRIPTEN__)
  44. #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG)
  45. #if (defined(__alpha__) || defined(__ia64__) || \
  46. defined(_ARCH_PPC64) || defined(__mips64) || \
  47. defined(__x86_64__) || \
  48. ((defined(sun) || defined(__sun)) && \
  49. (defined(LP64) || defined(_LP64))))
  50. /* long should be 64bit */
  51. #define SIZEOF_LONG 8
  52. #elif defined(__i386__) || defined(__CORTEX_M3__)
  53. /* long long should be 64bit */
  54. #define SIZEOF_LONG_LONG 8
  55. #endif
  56. #endif
  57. #endif
  58. #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
  59. #define WORD64_AVAILABLE
  60. #define W64LIT(x) x##ui64
  61. typedef unsigned __int64 word64;
  62. #elif defined(__EMSCRIPTEN__)
  63. #define WORD64_AVAILABLE
  64. #define W64LIT(x) x##ull
  65. typedef unsigned long long word64;
  66. #elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8
  67. #define WORD64_AVAILABLE
  68. #define W64LIT(x) x##LL
  69. typedef unsigned long word64;
  70. #elif defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG == 8
  71. #define WORD64_AVAILABLE
  72. #define W64LIT(x) x##LL
  73. typedef unsigned long long word64;
  74. #elif defined(__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 8
  75. #define WORD64_AVAILABLE
  76. #define W64LIT(x) x##LL
  77. typedef unsigned long long word64;
  78. #endif
  79. #if !defined(NO_64BIT) && defined(WORD64_AVAILABLE)
  80. /* These platforms have 64-bit CPU registers. */
  81. #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
  82. defined(__mips64) || defined(__x86_64__) || defined(_M_X64)) || \
  83. defined(__aarch64__) || defined(__sparc64__)
  84. typedef word64 wolfssl_word;
  85. #define WC_64BIT_CPU
  86. #elif (defined(sun) || defined(__sun)) && \
  87. (defined(LP64) || defined(_LP64))
  88. /* LP64 with GNU GCC compiler is reserved for when long int is 64 bits
  89. * and int uses 32 bits. When using Solaris Studio sparc and __sparc are
  90. * avialable for 32 bit detection but __sparc64__ could be missed. This
  91. * uses LP64 for checking 64 bit CPU arch. */
  92. typedef word64 wolfssl_word;
  93. #define WC_64BIT_CPU
  94. #else
  95. typedef word32 wolfssl_word;
  96. #ifdef WORD64_AVAILABLE
  97. #define WOLFCRYPT_SLOW_WORD64
  98. #endif
  99. #endif
  100. #else
  101. #undef WORD64_AVAILABLE
  102. typedef word32 wolfssl_word;
  103. #define MP_16BIT /* for mp_int, mp_word needs to be twice as big as
  104. mp_digit, no 64 bit type so make mp_digit 16 bit */
  105. #endif
  106. enum {
  107. WOLFSSL_WORD_SIZE = sizeof(wolfssl_word),
  108. WOLFSSL_BIT_SIZE = 8,
  109. WOLFSSL_WORD_BITS = WOLFSSL_WORD_SIZE * WOLFSSL_BIT_SIZE
  110. };
  111. #define WOLFSSL_MAX_16BIT 0xffffU
  112. /* use inlining if compiler allows */
  113. #ifndef INLINE
  114. #ifndef NO_INLINE
  115. #ifdef _MSC_VER
  116. #define INLINE __inline
  117. #elif defined(__GNUC__)
  118. #ifdef WOLFSSL_VXWORKS
  119. #define INLINE __inline__
  120. #else
  121. #define INLINE inline
  122. #endif
  123. #elif defined(__IAR_SYSTEMS_ICC__)
  124. #define INLINE inline
  125. #elif defined(THREADX)
  126. #define INLINE _Inline
  127. #else
  128. #define INLINE
  129. #endif
  130. #else
  131. #define INLINE
  132. #endif
  133. #endif
  134. /* set up rotate style */
  135. #if (defined(_MSC_VER) || defined(__BCPLUSPLUS__)) && \
  136. !defined(WOLFSSL_SGX) && !defined(INTIME_RTOS)
  137. #define INTEL_INTRINSICS
  138. #define FAST_ROTATE
  139. #elif defined(__MWERKS__) && TARGET_CPU_PPC
  140. #define PPC_INTRINSICS
  141. #define FAST_ROTATE
  142. #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
  143. /* GCC does peephole optimizations which should result in using rotate
  144. instructions */
  145. #define FAST_ROTATE
  146. #endif
  147. /* set up thread local storage if available */
  148. #ifdef HAVE_THREAD_LS
  149. #if defined(_MSC_VER)
  150. #define THREAD_LS_T __declspec(thread)
  151. /* Thread local storage only in FreeRTOS v8.2.1 and higher */
  152. #elif defined(FREERTOS)
  153. #define THREAD_LS_T
  154. #else
  155. #define THREAD_LS_T __thread
  156. #endif
  157. #else
  158. #define THREAD_LS_T
  159. #endif
  160. /* GCC 7 has new switch() fall-through detection */
  161. #if defined(__GNUC__)
  162. #if ((__GNUC__ > 7) || ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 1)))
  163. #define FALL_THROUGH __attribute__ ((fallthrough));
  164. #endif
  165. #endif
  166. #ifndef FALL_THROUGH
  167. #define FALL_THROUGH
  168. #endif
  169. /* Micrium will use Visual Studio for compilation but not the Win32 API */
  170. #if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && \
  171. !defined(FREERTOS_TCP) && !defined(EBSNET) && \
  172. !defined(WOLFSSL_UTASKER) && !defined(INTIME_RTOS)
  173. #define USE_WINDOWS_API
  174. #endif
  175. /* idea to add global alloc override by Moises Guimaraes */
  176. /* default to libc stuff */
  177. /* XREALLOC is used once in normal math lib, not in fast math lib */
  178. /* XFREE on some embeded systems doesn't like free(0) so test */
  179. #if defined(HAVE_IO_POOL)
  180. WOLFSSL_API void* XMALLOC(size_t n, void* heap, int type);
  181. WOLFSSL_API void* XREALLOC(void *p, size_t n, void* heap, int type);
  182. WOLFSSL_API void XFREE(void *p, void* heap, int type);
  183. #elif defined(WOLFSSL_ASYNC_CRYPT) && defined(HAVE_INTEL_QA)
  184. #include <wolfssl/wolfcrypt/port/intel/quickassist_mem.h>
  185. #undef USE_WOLFSSL_MEMORY
  186. #ifdef WOLFSSL_DEBUG_MEMORY
  187. #define XMALLOC(s, h, t) IntelQaMalloc((s), (h), (t), __func__, __LINE__)
  188. #define XFREE(p, h, t) IntelQaFree((p), (h), (t), __func__, __LINE__)
  189. #define XREALLOC(p, n, h, t) IntelQaRealloc((p), (n), (h), (t), __func__, __LINE__)
  190. #else
  191. #define XMALLOC(s, h, t) IntelQaMalloc((s), (h), (t))
  192. #define XFREE(p, h, t) IntelQaFree((p), (h), (t))
  193. #define XREALLOC(p, n, h, t) IntelQaRealloc((p), (n), (h), (t))
  194. #endif /* WOLFSSL_DEBUG_MEMORY */
  195. #elif defined(XMALLOC_USER)
  196. /* prototypes for user heap override functions */
  197. #include <stddef.h> /* for size_t */
  198. extern void *XMALLOC(size_t n, void* heap, int type);
  199. extern void *XREALLOC(void *p, size_t n, void* heap, int type);
  200. extern void XFREE(void *p, void* heap, int type);
  201. #elif defined(XMALLOC_OVERRIDE)
  202. /* override the XMALLOC, XFREE and XREALLOC macros */
  203. #elif defined(NO_WOLFSSL_MEMORY)
  204. /* just use plain C stdlib stuff if desired */
  205. #include <stdlib.h>
  206. #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s)))
  207. #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
  208. #define XREALLOC(p, n, h, t) realloc((p), (n))
  209. #elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) \
  210. && !defined(WOLFSSL_SAFERTOS) && !defined(FREESCALE_MQX) \
  211. && !defined(FREESCALE_KSDK_MQX) && !defined(FREESCALE_FREE_RTOS) \
  212. && !defined(WOLFSSL_LEANPSK) && !defined(FREERTOS) && !defined(FREERTOS_TCP)\
  213. && !defined(WOLFSSL_uITRON4)
  214. /* default C runtime, can install different routines at runtime via cbs */
  215. #include <wolfssl/wolfcrypt/memory.h>
  216. #ifdef WOLFSSL_STATIC_MEMORY
  217. #ifdef WOLFSSL_DEBUG_MEMORY
  218. #define XMALLOC(s, h, t) wolfSSL_Malloc((s), (h), (t), __func__, __LINE__)
  219. #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), (h), (t), __func__, __LINE__);}
  220. #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), (h), (t), __func__, __LINE__)
  221. #else
  222. #define XMALLOC(s, h, t) wolfSSL_Malloc((s), (h), (t))
  223. #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), (h), (t));}
  224. #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), (h), (t))
  225. #endif /* WOLFSSL_DEBUG_MEMORY */
  226. #else
  227. #ifdef WOLFSSL_DEBUG_MEMORY
  228. #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s), __func__, __LINE__))
  229. #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), __func__, __LINE__);}
  230. #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), __func__, __LINE__)
  231. #else
  232. #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s)))
  233. #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));}
  234. #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))
  235. #endif /* WOLFSSL_DEBUG_MEMORY */
  236. #endif /* WOLFSSL_STATIC_MEMORY */
  237. #endif
  238. /* declare/free variable handling for async */
  239. #ifdef WOLFSSL_ASYNC_CRYPT
  240. #define DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
  241. VAR_TYPE* VAR_NAME = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, HEAP, DYNAMIC_TYPE_WOLF_BIGINT);
  242. #define DECLARE_VAR_INIT(VAR_NAME, VAR_TYPE, VAR_SIZE, INIT_VALUE, HEAP) \
  243. VAR_TYPE* VAR_NAME = ({ \
  244. VAR_TYPE* ptr = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, HEAP, DYNAMIC_TYPE_WOLF_BIGINT); \
  245. if (ptr && INIT_VALUE) { \
  246. XMEMCPY(ptr, INIT_VALUE, sizeof(VAR_TYPE) * VAR_SIZE); \
  247. } \
  248. ptr; \
  249. })
  250. #define DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
  251. VAR_TYPE* VAR_NAME[VAR_ITEMS]; \
  252. int idx##VAR_NAME; \
  253. for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \
  254. VAR_NAME[idx##VAR_NAME] = (VAR_TYPE*)XMALLOC(VAR_SIZE, HEAP, DYNAMIC_TYPE_WOLF_BIGINT); \
  255. }
  256. #define FREE_VAR(VAR_NAME, HEAP) \
  257. XFREE(VAR_NAME, HEAP, DYNAMIC_TYPE_WOLF_BIGINT);
  258. #define FREE_ARRAY(VAR_NAME, VAR_ITEMS, HEAP) \
  259. for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \
  260. XFREE(VAR_NAME[idx##VAR_NAME], HEAP, DYNAMIC_TYPE_WOLF_BIGINT); \
  261. }
  262. #else
  263. #define DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
  264. VAR_TYPE VAR_NAME[VAR_SIZE]
  265. #define DECLARE_VAR_INIT(VAR_NAME, VAR_TYPE, VAR_SIZE, INIT_VALUE, HEAP) \
  266. VAR_TYPE* VAR_NAME = (VAR_TYPE*)INIT_VALUE
  267. #define DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
  268. VAR_TYPE VAR_NAME[VAR_ITEMS][VAR_SIZE]
  269. #define FREE_VAR(VAR_NAME, HEAP) /* nothing to free, its stack */
  270. #define FREE_ARRAY(VAR_NAME, VAR_ITEMS, HEAP) /* nothing to free, its stack */
  271. #endif
  272. #ifndef WOLFSSL_LEANPSK
  273. char* mystrnstr(const char* s1, const char* s2, unsigned int n);
  274. #endif
  275. #ifndef STRING_USER
  276. #include <string.h>
  277. #define XMEMCPY(d,s,l) memcpy((d),(s),(l))
  278. #define XMEMSET(b,c,l) memset((b),(c),(l))
  279. #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
  280. #define XMEMMOVE(d,s,l) memmove((d),(s),(l))
  281. #define XSTRLEN(s1) strlen((s1))
  282. #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
  283. /* strstr, strncmp, and strncat only used by wolfSSL proper,
  284. * not required for wolfCrypt only */
  285. #define XSTRSTR(s1,s2) strstr((s1),(s2))
  286. #define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n))
  287. #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
  288. #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
  289. #if defined(MICROCHIP_PIC32) || defined(WOLFSSL_TIRTOS)
  290. /* XC32 does not support strncasecmp, so use case sensitive one */
  291. #define XSTRNCASECMP(s1,s2,n) strncmp((s1),(s2),(n))
  292. #elif defined(USE_WINDOWS_API)
  293. #define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
  294. #else
  295. #define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
  296. #endif
  297. /* snprintf is used in asn.c for GetTimeString, PKCS7 test, and when
  298. debugging is turned on */
  299. #ifndef USE_WINDOWS_API
  300. #if defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  301. !defined(NO_STDIO_FILESYSTEM)
  302. /* case where stdio is not included else where but is needed for
  303. * snprintf */
  304. #include <stdio.h>
  305. #endif
  306. #define XSNPRINTF snprintf
  307. #else
  308. #define XSNPRINTF _snprintf
  309. #endif
  310. #if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
  311. /* use only Thread Safe version of strtok */
  312. #if defined(__MINGW32__) || defined(WOLFSSL_TIRTOS) || \
  313. defined(USE_WOLF_STRTOK)
  314. #ifndef USE_WOLF_STRTOK
  315. #define USE_WOLF_STRTOK
  316. #endif
  317. #define XSTRTOK wc_strtok
  318. #elif defined(USE_WINDOWS_API) || defined(INTIME_RTOS)
  319. #define XSTRTOK strtok_s
  320. #else
  321. #define XSTRTOK strtok_r
  322. #endif
  323. #endif
  324. #endif
  325. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  326. !defined(NO_STDIO_FILESYSTEM)
  327. #ifndef XGETENV
  328. #include <stdlib.h>
  329. #define XGETENV getenv
  330. #endif
  331. #endif /* OPENSSL_EXTRA */
  332. #ifndef CTYPE_USER
  333. #include <ctype.h>
  334. #if defined(HAVE_ECC) || defined(HAVE_OCSP) || \
  335. defined(WOLFSSL_KEY_GEN) || !defined(NO_DSA)
  336. #define XTOUPPER(c) toupper((c))
  337. #define XISALPHA(c) isalpha((c))
  338. #endif
  339. /* needed by wolfSSL_check_domain_name() */
  340. #define XTOLOWER(c) tolower((c))
  341. #endif
  342. /* memory allocation types for user hints */
  343. enum {
  344. DYNAMIC_TYPE_CA = 1,
  345. DYNAMIC_TYPE_CERT = 2,
  346. DYNAMIC_TYPE_KEY = 3,
  347. DYNAMIC_TYPE_FILE = 4,
  348. DYNAMIC_TYPE_SUBJECT_CN = 5,
  349. DYNAMIC_TYPE_PUBLIC_KEY = 6,
  350. DYNAMIC_TYPE_SIGNER = 7,
  351. DYNAMIC_TYPE_NONE = 8,
  352. DYNAMIC_TYPE_BIGINT = 9,
  353. DYNAMIC_TYPE_RSA = 10,
  354. DYNAMIC_TYPE_METHOD = 11,
  355. DYNAMIC_TYPE_OUT_BUFFER = 12,
  356. DYNAMIC_TYPE_IN_BUFFER = 13,
  357. DYNAMIC_TYPE_INFO = 14,
  358. DYNAMIC_TYPE_DH = 15,
  359. DYNAMIC_TYPE_DOMAIN = 16,
  360. DYNAMIC_TYPE_SSL = 17,
  361. DYNAMIC_TYPE_CTX = 18,
  362. DYNAMIC_TYPE_WRITEV = 19,
  363. DYNAMIC_TYPE_OPENSSL = 20,
  364. DYNAMIC_TYPE_DSA = 21,
  365. DYNAMIC_TYPE_CRL = 22,
  366. DYNAMIC_TYPE_REVOKED = 23,
  367. DYNAMIC_TYPE_CRL_ENTRY = 24,
  368. DYNAMIC_TYPE_CERT_MANAGER = 25,
  369. DYNAMIC_TYPE_CRL_MONITOR = 26,
  370. DYNAMIC_TYPE_OCSP_STATUS = 27,
  371. DYNAMIC_TYPE_OCSP_ENTRY = 28,
  372. DYNAMIC_TYPE_ALTNAME = 29,
  373. DYNAMIC_TYPE_SUITES = 30,
  374. DYNAMIC_TYPE_CIPHER = 31,
  375. DYNAMIC_TYPE_RNG = 32,
  376. DYNAMIC_TYPE_ARRAYS = 33,
  377. DYNAMIC_TYPE_DTLS_POOL = 34,
  378. DYNAMIC_TYPE_SOCKADDR = 35,
  379. DYNAMIC_TYPE_LIBZ = 36,
  380. DYNAMIC_TYPE_ECC = 37,
  381. DYNAMIC_TYPE_TMP_BUFFER = 38,
  382. DYNAMIC_TYPE_DTLS_MSG = 39,
  383. DYNAMIC_TYPE_X509 = 40,
  384. DYNAMIC_TYPE_TLSX = 41,
  385. DYNAMIC_TYPE_OCSP = 42,
  386. DYNAMIC_TYPE_SIGNATURE = 43,
  387. DYNAMIC_TYPE_HASHES = 44,
  388. DYNAMIC_TYPE_SRP = 45,
  389. DYNAMIC_TYPE_COOKIE_PWD = 46,
  390. DYNAMIC_TYPE_USER_CRYPTO = 47,
  391. DYNAMIC_TYPE_OCSP_REQUEST = 48,
  392. DYNAMIC_TYPE_X509_EXT = 49,
  393. DYNAMIC_TYPE_X509_STORE = 50,
  394. DYNAMIC_TYPE_X509_CTX = 51,
  395. DYNAMIC_TYPE_URL = 52,
  396. DYNAMIC_TYPE_DTLS_FRAG = 53,
  397. DYNAMIC_TYPE_DTLS_BUFFER = 54,
  398. DYNAMIC_TYPE_SESSION_TICK = 55,
  399. DYNAMIC_TYPE_PKCS = 56,
  400. DYNAMIC_TYPE_MUTEX = 57,
  401. DYNAMIC_TYPE_PKCS7 = 58,
  402. DYNAMIC_TYPE_AES_BUFFER = 59,
  403. DYNAMIC_TYPE_WOLF_BIGINT = 60,
  404. DYNAMIC_TYPE_ASN1 = 61,
  405. DYNAMIC_TYPE_LOG = 62,
  406. DYNAMIC_TYPE_WRITEDUP = 63,
  407. DYNAMIC_TYPE_PRIVATE_KEY = 64,
  408. DYNAMIC_TYPE_HMAC = 65,
  409. DYNAMIC_TYPE_ASYNC = 66,
  410. DYNAMIC_TYPE_ASYNC_NUMA = 67,
  411. DYNAMIC_TYPE_ASYNC_NUMA64 = 68,
  412. DYNAMIC_TYPE_CURVE25519 = 69,
  413. DYNAMIC_TYPE_ED25519 = 70,
  414. DYNAMIC_TYPE_SECRET = 71,
  415. DYNAMIC_TYPE_DIGEST = 72,
  416. DYNAMIC_TYPE_RSA_BUFFER = 73,
  417. DYNAMIC_TYPE_DCERT = 74,
  418. DYNAMIC_TYPE_STRING = 75,
  419. DYNAMIC_TYPE_PEM = 76,
  420. DYNAMIC_TYPE_DER = 77,
  421. DYNAMIC_TYPE_CERT_EXT = 78,
  422. DYNAMIC_TYPE_ALPN = 79,
  423. DYNAMIC_TYPE_ENCRYPTEDINFO= 80,
  424. DYNAMIC_TYPE_DIRCTX = 81,
  425. DYNAMIC_TYPE_HASHCTX = 82,
  426. DYNAMIC_TYPE_SEED = 83,
  427. DYNAMIC_TYPE_SYMETRIC_KEY = 84,
  428. DYNAMIC_TYPE_ECC_BUFFER = 85,
  429. DYNAMIC_TYPE_QSH = 86,
  430. DYNAMIC_TYPE_SALT = 87,
  431. DYNAMIC_TYPE_HASH_TMP = 88,
  432. DYNAMIC_TYPE_BLOB = 89,
  433. DYNAMIC_TYPE_NAME_ENTRY = 90,
  434. };
  435. /* max error buffer string size */
  436. #ifndef WOLFSSL_MAX_ERROR_SZ
  437. #define WOLFSSL_MAX_ERROR_SZ 80
  438. #endif
  439. /* stack protection */
  440. enum {
  441. MIN_STACK_BUFFER = 8
  442. };
  443. /* settings detection for compile vs runtime math incompatibilities */
  444. enum {
  445. #if !defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
  446. CTC_SETTINGS = 0x0
  447. #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
  448. CTC_SETTINGS = 0x1
  449. #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
  450. CTC_SETTINGS = 0x2
  451. #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
  452. CTC_SETTINGS = 0x4
  453. #elif defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
  454. CTC_SETTINGS = 0x8
  455. #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
  456. CTC_SETTINGS = 0x10
  457. #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
  458. CTC_SETTINGS = 0x20
  459. #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
  460. CTC_SETTINGS = 0x40
  461. #else
  462. #error "bad math long / long long settings"
  463. #endif
  464. };
  465. WOLFSSL_API word32 CheckRunTimeSettings(void);
  466. /* If user uses RSA, DH, DSA, or ECC math lib directly then fast math and long
  467. types need to match at compile time and run time, CheckCtcSettings will
  468. return 1 if a match otherwise 0 */
  469. #define CheckCtcSettings() (CTC_SETTINGS == CheckRunTimeSettings())
  470. /* invalid device id */
  471. #define INVALID_DEVID -2
  472. /* AESNI requires alignment and ARMASM gains some performance from it */
  473. #if defined(WOLFSSL_AESNI) || defined(WOLFSSL_ARMASM) || defined(USE_INTEL_SPEEDUP)
  474. #if !defined(ALIGN16)
  475. #if defined(__GNUC__)
  476. #define ALIGN16 __attribute__ ( (aligned (16)))
  477. #elif defined(_MSC_VER)
  478. /* disable align warning, we want alignment ! */
  479. #pragma warning(disable: 4324)
  480. #define ALIGN16 __declspec (align (16))
  481. #else
  482. #define ALIGN16
  483. #endif
  484. #endif /* !ALIGN16 */
  485. #if !defined (ALIGN32)
  486. #if defined (__GNUC__)
  487. #define ALIGN32 __attribute__ ( (aligned (32)))
  488. #elif defined(_MSC_VER)
  489. /* disable align warning, we want alignment ! */
  490. #pragma warning(disable: 4324)
  491. #define ALIGN32 __declspec (align (32))
  492. #else
  493. #define ALIGN32
  494. #endif
  495. #endif
  496. #if !defined(ALIGN32)
  497. #if defined(__GNUC__)
  498. #define ALIGN32 __attribute__ ( (aligned (32)))
  499. #elif defined(_MSC_VER)
  500. /* disable align warning, we want alignment ! */
  501. #pragma warning(disable: 4324)
  502. #define ALIGN32 __declspec (align (32))
  503. #else
  504. #define ALIGN32
  505. #endif
  506. #endif /* !ALIGN32 */
  507. #if defined(__GNUC__)
  508. #define ALIGN128 __attribute__ ( (aligned (128)))
  509. #elif defined(_MSC_VER)
  510. /* disable align warning, we want alignment ! */
  511. #pragma warning(disable: 4324)
  512. #define ALIGN128 __declspec (align (128))
  513. #else
  514. #define ALIGN128
  515. #endif
  516. #if defined(__GNUC__)
  517. #define ALIGN256 __attribute__ ( (aligned (256)))
  518. #elif defined(_MSC_VER)
  519. /* disable align warning, we want alignment ! */
  520. #pragma warning(disable: 4324)
  521. #define ALIGN256 __declspec (align (256))
  522. #else
  523. #define ALIGN256
  524. #endif
  525. #else
  526. #ifndef ALIGN16
  527. #define ALIGN16
  528. #endif
  529. #ifndef ALIGN32
  530. #define ALIGN32
  531. #endif
  532. #ifndef ALIGN128
  533. #define ALIGN128
  534. #endif
  535. #ifndef ALIGN256
  536. #define ALIGN256
  537. #endif
  538. #endif /* WOLFSSL_AESNI || WOLFSSL_ARMASM */
  539. #ifndef TRUE
  540. #define TRUE 1
  541. #endif
  542. #ifndef FALSE
  543. #define FALSE 0
  544. #endif
  545. #ifdef WOLFSSL_RIOT_OS
  546. #define EXIT_TEST(ret) exit(ret)
  547. #elif defined(HAVE_STACK_SIZE)
  548. #define EXIT_TEST(ret) return (void*)((size_t)(ret))
  549. #else
  550. #define EXIT_TEST(ret) return ret
  551. #endif
  552. #ifdef __cplusplus
  553. } /* extern "C" */
  554. #endif
  555. #endif /* WOLF_CRYPT_TYPES_H */