source: azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfssl/wolfcrypt/types.h@ 464

Last change on this file since 464 was 464, checked in by coas-nagasima, 3 years ago

WolfSSLとAzure IoT SDKを更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 40.5 KB
Line 
1/* types.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/types.h
24*/
25/*
26DESCRIPTION
27This library defines the primitive data types and abstraction macros to
28decouple library dependencies with standard string, memory and so on.
29
30*/
31#ifndef WOLF_CRYPT_TYPES_H
32#define WOLF_CRYPT_TYPES_H
33
34 #include <wolfssl/wolfcrypt/settings.h>
35 #include <wolfssl/wolfcrypt/wc_port.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41
42 #define WOLFSSL_ABI
43 /* Tag for all the APIs that are a part of the fixed ABI. */
44
45 /*
46 * This struct is used multiple time by other structs and
47 * needs to be defined somwhere that all structs can import
48 * (with minimal depencencies).
49 */
50 #if defined(HAVE_EX_DATA) || defined(FORTRESS)
51 typedef struct WOLFSSL_CRYPTO_EX_DATA {
52 void* ex_data[MAX_EX_DATA];
53 } WOLFSSL_CRYPTO_EX_DATA;
54 #endif
55
56 #if defined(WORDS_BIGENDIAN)
57 #define BIG_ENDIAN_ORDER
58 #endif
59
60 #ifndef BIG_ENDIAN_ORDER
61 #define LITTLE_ENDIAN_ORDER
62 #endif
63
64 #ifndef WOLFSSL_TYPES
65 #ifndef byte
66 typedef unsigned char byte;
67 typedef signed char sword8;
68 typedef unsigned char word8;
69 #endif
70 #ifdef WC_16BIT_CPU
71 typedef int sword16;
72 typedef unsigned int word16;
73 typedef long sword32;
74 typedef unsigned long word32;
75 #else
76 typedef short sword16;
77 typedef unsigned short word16;
78 typedef int sword32;
79 typedef unsigned int word32;
80 #endif
81 typedef byte word24[3];
82 #endif
83
84
85 /* constant pointer to a constant char */
86 #ifdef WOLFSSL_NO_CONSTCHARCONST
87 typedef const char* wcchar;
88 #else
89 typedef const char* const wcchar;
90 #endif
91
92
93 /* try to set SIZEOF_LONG or SIZEOF_LONG_LONG if user didn't */
94 #if defined(_MSC_VER) || defined(HAVE_LIMITS_H)
95 #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG)
96 #include <limits.h>
97 #if defined(ULONG_MAX) && (ULONG_MAX == 0xffffffffUL)
98 #define SIZEOF_LONG 4
99 #endif
100 #if defined(ULLONG_MAX) && (ULLONG_MAX == 0xffffffffffffffffULL)
101 #define SIZEOF_LONG_LONG 8
102 #endif
103 #endif
104 #elif !defined(__BCPLUSPLUS__) && !defined(__EMSCRIPTEN__)
105 #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG)
106 #if (defined(__alpha__) || defined(__ia64__) || \
107 defined(_ARCH_PPC64) || defined(__mips64) || \
108 defined(__x86_64__) || defined(__s390x__ ) || \
109 ((defined(sun) || defined(__sun)) && \
110 (defined(LP64) || defined(_LP64))))
111 /* long should be 64bit */
112 #define SIZEOF_LONG 8
113 #elif defined(__i386__) || defined(__CORTEX_M3__)
114 /* long long should be 64bit */
115 #define SIZEOF_LONG_LONG 8
116 #endif
117 #endif
118 #endif
119
120 #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
121 #define WORD64_AVAILABLE
122 #define W64LIT(x) x##ui64
123 typedef __int64 sword64;
124 typedef unsigned __int64 word64;
125 #elif defined(__EMSCRIPTEN__)
126 #define WORD64_AVAILABLE
127 #define W64LIT(x) x##ull
128 typedef long long sword64;
129 typedef unsigned long long word64;
130 #elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8
131 #define WORD64_AVAILABLE
132 #define W64LIT(x) x##LL
133 typedef long sword64;
134 typedef unsigned long word64;
135 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG == 8
136 #define WORD64_AVAILABLE
137 #define W64LIT(x) x##LL
138 typedef long long sword64;
139 typedef unsigned long long word64;
140 #elif defined(__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 8
141 #define WORD64_AVAILABLE
142 #define W64LIT(x) x##LL
143 typedef long long sword64;
144 typedef unsigned long long word64;
145 #endif
146
147#if !defined(NO_64BIT) && defined(WORD64_AVAILABLE) && !defined(WC_16BIT_CPU)
148 /* These platforms have 64-bit CPU registers. */
149 #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
150 defined(__mips64) || defined(__x86_64__) || defined(_M_X64)) || \
151 defined(__aarch64__) || defined(__sparc64__) || defined(__s390x__ ) || \
152 (defined(__riscv_xlen) && (__riscv_xlen == 64))
153 typedef word64 wolfssl_word;
154 #define WC_64BIT_CPU
155 #elif (defined(sun) || defined(__sun)) && \
156 (defined(LP64) || defined(_LP64))
157 /* LP64 with GNU GCC compiler is reserved for when long int is 64 bits
158 * and int uses 32 bits. When using Solaris Studio sparc and __sparc are
159 * available for 32 bit detection but __sparc64__ could be missed. This
160 * uses LP64 for checking 64 bit CPU arch. */
161 typedef word64 wolfssl_word;
162 #define WC_64BIT_CPU
163 #else
164 typedef word32 wolfssl_word;
165 #ifdef WORD64_AVAILABLE
166 #define WOLFCRYPT_SLOW_WORD64
167 #endif
168 #define WC_32BIT_CPU
169 #endif
170
171#elif defined(WC_16BIT_CPU)
172 #undef WORD64_AVAILABLE
173 typedef word16 wolfssl_word;
174 #define MP_16BIT /* for mp_int, mp_word needs to be twice as big as
175 mp_digit, no 64 bit type so make mp_digit 16 bit */
176
177#else
178 #undef WORD64_AVAILABLE
179 typedef word32 wolfssl_word;
180 #define MP_16BIT /* for mp_int, mp_word needs to be twice as big as
181 mp_digit, no 64 bit type so make mp_digit 16 bit */
182 #define WC_32BIT_CPU
183#endif
184
185 enum {
186 WOLFSSL_WORD_SIZE = sizeof(wolfssl_word),
187 WOLFSSL_BIT_SIZE = 8,
188 WOLFSSL_WORD_BITS = WOLFSSL_WORD_SIZE * WOLFSSL_BIT_SIZE
189 };
190
191 #define WOLFSSL_MAX_16BIT 0xffffU
192
193 /* use inlining if compiler allows */
194 #ifndef WC_INLINE
195 #ifndef NO_INLINE
196 #ifdef _MSC_VER
197 #define WC_INLINE __inline
198 #elif defined(__GNUC__)
199 #ifdef WOLFSSL_VXWORKS
200 #define WC_INLINE __inline__
201 #else
202 #define WC_INLINE inline
203 #endif
204 #elif defined(__IAR_SYSTEMS_ICC__)
205 #define WC_INLINE inline
206 #elif defined(THREADX)
207 #define WC_INLINE _Inline
208 #elif defined(__ghc__)
209 #ifndef __cplusplus
210 #define WC_INLINE __inline
211 #else
212 #define WC_INLINE inline
213 #endif
214 #else
215 #define WC_INLINE
216 #endif
217 #else
218 #ifdef __GNUC__
219 #define WC_INLINE __attribute__((unused))
220 #else
221 #define WC_INLINE
222 #endif
223 #endif
224 #endif
225
226 #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
227 #define INLINE WC_INLINE
228 #endif
229
230
231 /* set up rotate style */
232 #if (defined(_MSC_VER) || defined(__BCPLUSPLUS__)) && \
233 !defined(WOLFSSL_SGX) && !defined(INTIME_RTOS)
234 #define INTEL_INTRINSICS
235 #define FAST_ROTATE
236 #elif defined(__MWERKS__) && TARGET_CPU_PPC
237 #define PPC_INTRINSICS
238 #define FAST_ROTATE
239 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
240 /* GCC does peephole optimizations which should result in using rotate
241 instructions */
242 #define FAST_ROTATE
243 #endif
244
245
246 /* set up thread local storage if available */
247 #ifdef HAVE_THREAD_LS
248 #if defined(_MSC_VER)
249 #define THREAD_LS_T __declspec(thread)
250 /* Thread local storage only in FreeRTOS v8.2.1 and higher */
251 #elif defined(FREERTOS) || defined(FREERTOS_TCP) || \
252 defined(WOLFSSL_ZEPHYR)
253 #define THREAD_LS_T
254 #else
255 #define THREAD_LS_T __thread
256 #endif
257 #else
258 #define THREAD_LS_T
259 #endif
260
261 /* GCC 7 has new switch() fall-through detection */
262 /* default to FALL_THROUGH stub */
263 #ifndef FALL_THROUGH
264 #define FALL_THROUGH
265
266 #if defined(__GNUC__)
267 #if ((__GNUC__ > 7) || ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 1)))
268 #undef FALL_THROUGH
269 #if defined(WOLFSSL_LINUXKM) && defined(fallthrough)
270 #define FALL_THROUGH fallthrough
271 #else
272 #define FALL_THROUGH __attribute__ ((fallthrough));
273 #endif
274 #endif
275 #endif
276 #endif /* FALL_THROUGH */
277
278 /* Micrium will use Visual Studio for compilation but not the Win32 API */
279 #if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && \
280 !defined(FREERTOS_TCP) && !defined(EBSNET) && \
281 !defined(WOLFSSL_UTASKER) && !defined(INTIME_RTOS)
282 #define USE_WINDOWS_API
283 #endif
284
285 #define XSTR_SIZEOF(x) (sizeof(x) - 1) /* -1 to not count the null char */
286
287 /* idea to add global alloc override by Moises Guimaraes */
288 /* default to libc stuff */
289 /* XREALLOC is used once in normal math lib, not in fast math lib */
290 /* XFREE on some embedded systems doesn't like free(0) so test */
291 #if defined(HAVE_IO_POOL)
292 WOLFSSL_API void* XMALLOC(size_t n, void* heap, int type);
293 WOLFSSL_API void* XREALLOC(void *p, size_t n, void* heap, int type);
294 WOLFSSL_API void XFREE(void *p, void* heap, int type);
295 #elif (defined(WOLFSSL_ASYNC_CRYPT) && defined(HAVE_INTEL_QA)) || \
296 defined(HAVE_INTEL_QA_SYNC)
297 #ifndef HAVE_INTEL_QA_SYNC
298 #include <wolfssl/wolfcrypt/port/intel/quickassist_mem.h>
299 #undef USE_WOLFSSL_MEMORY
300 #ifdef WOLFSSL_DEBUG_MEMORY
301 #define XMALLOC(s, h, t) IntelQaMalloc((s), (h), (t), __func__, __LINE__)
302 #define XFREE(p, h, t) IntelQaFree((p), (h), (t), __func__, __LINE__)
303 #define XREALLOC(p, n, h, t) IntelQaRealloc((p), (n), (h), (t), __func__, __LINE__)
304 #else
305 #define XMALLOC(s, h, t) IntelQaMalloc((s), (h), (t))
306 #define XFREE(p, h, t) IntelQaFree((p), (h), (t))
307 #define XREALLOC(p, n, h, t) IntelQaRealloc((p), (n), (h), (t))
308 #endif /* WOLFSSL_DEBUG_MEMORY */
309 #else
310 #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
311 #undef USE_WOLFSSL_MEMORY
312 #ifdef WOLFSSL_DEBUG_MEMORY
313 #define XMALLOC(s, h, t) wc_CryptoCb_IntelQaMalloc((s), (h), (t), __func__, __LINE__)
314 #define XFREE(p, h, t) wc_CryptoCb_IntelQaFree((p), (h), (t), __func__, __LINE__)
315 #define XREALLOC(p, n, h, t) wc_CryptoCb_IntelQaRealloc((p), (n), (h), (t), __func__, __LINE__)
316 #else
317 #define XMALLOC(s, h, t) wc_CryptoCb_IntelQaMalloc((s), (h), (t))
318 #define XFREE(p, h, t) wc_CryptoCb_IntelQaFree((p), (h), (t))
319 #define XREALLOC(p, n, h, t) wc_CryptoCb_IntelQaRealloc((p), (n), (h), (t))
320 #endif /* WOLFSSL_DEBUG_MEMORY */
321 #endif
322 #elif defined(XMALLOC_USER)
323 /* prototypes for user heap override functions */
324 #include <stddef.h> /* for size_t */
325 extern void *XMALLOC(size_t n, void* heap, int type);
326 extern void *XREALLOC(void *p, size_t n, void* heap, int type);
327 extern void XFREE(void *p, void* heap, int type);
328 #elif defined(WOLFSSL_MEMORY_LOG)
329 #define XMALLOC(n, h, t) xmalloc(n, h, t, __func__, __FILE__, __LINE__)
330 #define XREALLOC(p, n, h, t) xrealloc(p, n, h, t, __func__, __FILE__, __LINE__)
331 #define XFREE(p, h, t) xfree(p, h, t, __func__, __FILE__, __LINE__)
332
333 /* prototypes for user heap override functions */
334 #include <stddef.h> /* for size_t */
335 #include <stdlib.h>
336 WOLFSSL_API void *xmalloc(size_t n, void* heap, int type,
337 const char* func, const char* file, unsigned int line);
338 WOLFSSL_API void *xrealloc(void *p, size_t n, void* heap, int type,
339 const char* func, const char* file, unsigned int line);
340 WOLFSSL_API void xfree(void *p, void* heap, int type, const char* func,
341 const char* file, unsigned int line);
342 #elif defined(XMALLOC_OVERRIDE)
343 /* override the XMALLOC, XFREE and XREALLOC macros */
344 #elif defined(WOLFSSL_TELIT_M2MB)
345 /* Telit M2MB SDK requires use m2mb_os API's, not std malloc/free */
346 /* Use of malloc/free will cause CPU reboot */
347 #define XMALLOC(s, h, t) ((void)h, (void)t, m2mb_os_malloc((s)))
348 #define XFREE(p, h, t) {void* xp = (p); if((xp)) m2mb_os_free((xp));}
349 #define XREALLOC(p, n, h, t) m2mb_os_realloc((p), (n))
350
351 #elif defined(NO_WOLFSSL_MEMORY)
352 #ifdef WOLFSSL_NO_MALLOC
353 /* this platform does not support heap use */
354 #ifdef WOLFSSL_MALLOC_CHECK
355 #include <stdio.h>
356 static inline void* malloc_check(size_t sz) {
357 printf("wolfSSL_malloc failed");
358 return NULL;
359 };
360 #define XMALLOC(s, h, t) malloc_check((s))
361 #define XFREE(p, h, t)
362 #define XREALLOC(p, n, h, t) (NULL)
363 #else
364 #define XMALLOC(s, h, t) (NULL)
365 #define XFREE(p, h, t)
366 #define XREALLOC(p, n, h, t) (NULL)
367 #endif
368 #else
369 /* just use plain C stdlib stuff if desired */
370 #include <stdlib.h>
371 #define XMALLOC(s, h, t) malloc((size_t)(s))
372 #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
373 #define XREALLOC(p, n, h, t) realloc((p), (size_t)(n))
374 #endif
375
376 #elif defined(WOLFSSL_LINUXKM)
377 /* the requisite linux/slab.h is included in wc_port.h, with incompatible warnings masked out. */
378 #define XMALLOC(s, h, t) ({(void)(h); (void)(t); kmalloc(s, GFP_KERNEL);})
379 #define XFREE(p, h, t) ({void* _xp; (void)(h); _xp = (p); if(_xp) kfree(_xp);})
380 #define XREALLOC(p, n, h, t) ({(void)(h); (void)(t); krealloc((p), (n), GFP_KERNEL);})
381
382 #elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) \
383 && !defined(WOLFSSL_SAFERTOS) && !defined(FREESCALE_MQX) \
384 && !defined(FREESCALE_KSDK_MQX) && !defined(FREESCALE_FREE_RTOS) \
385 && !defined(WOLFSSL_LEANPSK) && !defined(WOLFSSL_uITRON4)
386 /* default C runtime, can install different routines at runtime via cbs */
387 #include <wolfssl/wolfcrypt/memory.h>
388 #ifdef WOLFSSL_STATIC_MEMORY
389 #ifdef WOLFSSL_DEBUG_MEMORY
390 #define XMALLOC(s, h, t) wolfSSL_Malloc((s), (h), (t), __func__, __LINE__)
391 #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), (h), (t), __func__, __LINE__);}
392 #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), (h), (t), __func__, __LINE__)
393 #else
394 #define XMALLOC(s, h, t) wolfSSL_Malloc((s), (h), (t))
395 #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), (h), (t));}
396 #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), (h), (t))
397 #endif /* WOLFSSL_DEBUG_MEMORY */
398 #elif !defined(FREERTOS) && !defined(FREERTOS_TCP)
399 #ifdef WOLFSSL_DEBUG_MEMORY
400 #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s), __func__, __LINE__))
401 #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), __func__, __LINE__);}
402 #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), __func__, __LINE__)
403 #else
404 #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s)))
405 #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));}
406 #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))
407 #endif /* WOLFSSL_DEBUG_MEMORY */
408 #endif /* WOLFSSL_STATIC_MEMORY */
409 #endif
410
411 /* declare/free variable handling for async and smallstack */
412 #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_SMALL_STACK)
413 #define DECLARE_VAR_IS_HEAP_ALLOC
414 #define DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
415 VAR_TYPE* VAR_NAME = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT)
416 #define DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
417 VAR_TYPE* VAR_NAME[VAR_ITEMS]; \
418 int idx##VAR_NAME, inner_idx_##VAR_NAME; \
419 for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \
420 VAR_NAME[idx##VAR_NAME] = (VAR_TYPE*)XMALLOC(VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \
421 if (VAR_NAME[idx##VAR_NAME] == NULL) { \
422 for (inner_idx_##VAR_NAME = 0; inner_idx_##VAR_NAME < idx##VAR_NAME; inner_idx_##VAR_NAME++) { \
423 XFREE(VAR_NAME[inner_idx_##VAR_NAME], HEAP, DYNAMIC_TYPE_WOLF_BIGINT); \
424 VAR_NAME[inner_idx_##VAR_NAME] = NULL; \
425 } \
426 for (inner_idx_##VAR_NAME = idx##VAR_NAME + 1; inner_idx_##VAR_NAME < VAR_ITEMS; inner_idx_##VAR_NAME++) { \
427 VAR_NAME[inner_idx_##VAR_NAME] = NULL; \
428 } \
429 break; \
430 } \
431 }
432 #define FREE_VAR(VAR_NAME, HEAP) \
433 XFREE(VAR_NAME, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT);
434 #define FREE_ARRAY(VAR_NAME, VAR_ITEMS, HEAP) \
435 for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \
436 XFREE(VAR_NAME[idx##VAR_NAME], (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \
437 }
438
439 #define DECLARE_ARRAY_DYNAMIC_DEC(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
440 DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP)
441 #define DECLARE_ARRAY_DYNAMIC_EXE(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP)
442 #define FREE_ARRAY_DYNAMIC(VAR_NAME, VAR_ITEMS, HEAP) \
443 FREE_ARRAY(VAR_NAME, VAR_ITEMS, HEAP)
444 #else
445 #undef DECLARE_VAR_IS_HEAP_ALLOC
446 #define DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
447 VAR_TYPE VAR_NAME[VAR_SIZE]
448 #define DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
449 VAR_TYPE VAR_NAME[VAR_ITEMS][VAR_SIZE]
450 #define FREE_VAR(VAR_NAME, HEAP) /* nothing to free, its stack */
451 #define FREE_ARRAY(VAR_NAME, VAR_ITEMS, HEAP) /* nothing to free, its stack */
452
453 #define DECLARE_ARRAY_DYNAMIC_DEC(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
454 VAR_TYPE* VAR_NAME[VAR_ITEMS]; \
455 int idx##VAR_NAME, inner_idx_##VAR_NAME;
456 #define DECLARE_ARRAY_DYNAMIC_EXE(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
457 for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \
458 VAR_NAME[idx##VAR_NAME] = (VAR_TYPE*)XMALLOC(VAR_SIZE, (HEAP), DYNAMIC_TYPE_TMP_BUFFER); \
459 if (VAR_NAME[idx##VAR_NAME] == NULL) { \
460 for (inner_idx_##VAR_NAME = 0; inner_idx_##VAR_NAME < idx##VAR_NAME; inner_idx_##VAR_NAME++) { \
461 XFREE(VAR_NAME[inner_idx_##VAR_NAME], HEAP, DYNAMIC_TYPE_TMP_BUFFER); \
462 VAR_NAME[inner_idx_##VAR_NAME] = NULL; \
463 } \
464 for (inner_idx_##VAR_NAME = idx##VAR_NAME + 1; inner_idx_##VAR_NAME < VAR_ITEMS; inner_idx_##VAR_NAME++) { \
465 VAR_NAME[inner_idx_##VAR_NAME] = NULL; \
466 } \
467 break; \
468 } \
469 }
470 #define FREE_ARRAY_DYNAMIC(VAR_NAME, VAR_ITEMS, HEAP) \
471 for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \
472 XFREE(VAR_NAME[idx##VAR_NAME], (HEAP), DYNAMIC_TYPE_TMP_BUFFER); \
473 }
474 #endif
475
476 #if !defined(USE_WOLF_STRTOK) && \
477 ((defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) || \
478 defined(WOLFSSL_TIRTOS) || defined(WOLF_C99))
479 #define USE_WOLF_STRTOK
480 #endif
481 #if !defined(USE_WOLF_STRSEP) && (defined(WOLF_C99))
482 #define USE_WOLF_STRSEP
483 #endif
484
485 #ifndef STRING_USER
486 #if defined(WOLFSSL_LINUXKM)
487 #include <linux/string.h>
488 #else
489 #include <string.h>
490 #endif
491
492 #define XMEMCPY(d,s,l) memcpy((d),(s),(l))
493 #define XMEMSET(b,c,l) memset((b),(c),(l))
494 #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
495 #define XMEMMOVE(d,s,l) memmove((d),(s),(l))
496
497 #define XSTRLEN(s1) strlen((s1))
498 #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
499 /* strstr, strncmp, strcmp, and strncat only used by wolfSSL proper,
500 * not required for wolfCrypt only */
501 #define XSTRSTR(s1,s2) strstr((s1),(s2))
502 #define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n))
503 #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
504 #define XSTRCMP(s1,s2) strcmp((s1),(s2))
505 #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
506
507 #ifdef USE_WOLF_STRSEP
508 #define XSTRSEP(s1,d) wc_strsep((s1),(d))
509 #else
510 #define XSTRSEP(s1,d) strsep((s1),(d))
511 #endif
512
513 #ifndef XSTRNCASECMP
514 #if defined(MICROCHIP_PIC32) || defined(WOLFSSL_TIRTOS) || \
515 defined(WOLFSSL_ZEPHYR)
516 /* XC32 does not support strncasecmp, so use case sensitive one */
517 #define XSTRNCASECMP(s1,s2,n) strncmp((s1),(s2),(n))
518 #elif defined(USE_WINDOWS_API) || defined(FREERTOS_TCP_WINSIM)
519 #define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
520 #else
521 #if defined(HAVE_STRINGS_H) && defined(WOLF_C99) && \
522 !defined(WOLFSSL_SGX)
523 #include <strings.h>
524 #endif
525 #if defined(WOLFSSL_DEOS)
526 #define XSTRNCASECMP(s1,s2,n) strnicmp((s1),(s2),(n))
527 #elif defined(WOLFSSL_CMSIS_RTOSv2)
528 #define XSTRNCASECMP(s1,s2,n) strncmp((s1),(s2),(n))
529 #else
530 #define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
531 #endif
532 #endif
533 #endif /* !XSTRNCASECMP */
534
535 /* snprintf is used in asn.c for GetTimeString, PKCS7 test, and when
536 debugging is turned on */
537 #ifndef USE_WINDOWS_API
538 #ifndef XSNPRINTF
539 #if defined(NO_FILESYSTEM) && (defined(OPENSSL_EXTRA) || \
540 defined(HAVE_PKCS7)) && !defined(NO_STDIO_FILESYSTEM)
541 /* case where stdio is not included else where but is needed
542 for snprintf */
543 #include <stdio.h>
544 #endif
545 #if defined(WOLFSSL_ESPIDF) && \
546 (!defined(NO_ASN_TIME) && defined(HAVE_PKCS7))
547 #include<stdarg.h>
548 /* later gcc than 7.1 introduces -Wformat-truncation */
549 /* In cases when truncation is expected the caller needs*/
550 /* to check the return value from the function so that */
551 /* compiler doesn't complain. */
552 /* xtensa-esp32-elf v8.2.0 warns trancation at */
553 /* GetAsnTimeString() */
554 static WC_INLINE
555 int _xsnprintf_(char *s, size_t n, const char *format, ...)
556 {
557 va_list ap;
558 int ret;
559
560 if ((int)n <= 0) return -1;
561
562 va_start(ap, format);
563
564 ret = vsnprintf(s, n, format, ap);
565 if (ret < 0)
566 ret = -1;
567
568 va_end(ap);
569
570 return ret;
571 }
572 #define XSNPRINTF _xsnprintf_
573 #else
574 #define XSNPRINTF snprintf
575 #endif
576 #endif
577 #else
578 #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__)
579 #if defined(_MSC_VER) && (_MSC_VER >= 1900)
580 /* Beginning with the UCRT in Visual Studio 2015 and
581 Windows 10, snprintf is no longer identical to
582 _snprintf. The snprintf function behavior is now
583 C99 standard compliant. */
584 #include <stdio.h>
585 #define XSNPRINTF snprintf
586 #else
587 /* 4996 warning to use MS extensions e.g., _sprintf_s
588 instead of _snprintf */
589 #if !defined(__MINGW32__)
590 #pragma warning(disable: 4996)
591 #endif
592 static WC_INLINE
593 int xsnprintf(char *buffer, size_t bufsize,
594 const char *format, ...) {
595 va_list ap;
596 int ret;
597
598 if ((int)bufsize <= 0) return -1;
599 va_start(ap, format);
600 ret = vsnprintf(buffer, bufsize, format, ap);
601 if (ret >= (int)bufsize)
602 ret = -1;
603 va_end(ap);
604 return ret;
605 }
606 #define XSNPRINTF xsnprintf
607 #endif /* (_MSC_VER >= 1900) */
608 #else
609 #define XSNPRINTF snprintf
610 #endif /* _MSC_VER */
611 #endif /* USE_WINDOWS_API */
612
613 #if defined(WOLFSSL_CERT_EXT) || defined(OPENSSL_EXTRA) \
614 || defined(HAVE_ALPN)
615 /* use only Thread Safe version of strtok */
616 #if defined(USE_WOLF_STRTOK)
617 #define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
618 #elif defined(USE_WINDOWS_API) || defined(INTIME_RTOS)
619 #define XSTRTOK(s1,d,ptr) strtok_s((s1),(d),(ptr))
620 #else
621 #define XSTRTOK(s1,d,ptr) strtok_r((s1),(d),(ptr))
622 #endif
623 #endif
624
625 #if defined(WOLFSSL_CERT_EXT) || defined(HAVE_OCSP) || \
626 defined(HAVE_CRL_IO) || defined(HAVE_HTTP_CLIENT) || \
627 !defined(NO_CRYPT_BENCHMARK)
628
629 #ifndef XATOI /* if custom XATOI is not already defined */
630 #include <stdlib.h>
631 #define XATOI(s) atoi((s))
632 #endif
633 #endif
634 #endif
635
636 #ifdef USE_WOLF_STRTOK
637 WOLFSSL_API char* wc_strtok(char *str, const char *delim, char **nextp);
638 #endif
639 #ifdef USE_WOLF_STRSEP
640 WOLFSSL_API char* wc_strsep(char **stringp, const char *delim);
641 #endif
642
643 #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
644 !defined(NO_STDIO_FILESYSTEM)
645 #ifndef XGETENV
646 #include <stdlib.h>
647 #define XGETENV getenv
648 #endif
649 #endif /* OPENSSL_EXTRA */
650
651 #ifndef CTYPE_USER
652 #ifndef WOLFSSL_LINUXKM
653 #include <ctype.h>
654 #endif
655 #if defined(HAVE_ECC) || defined(HAVE_OCSP) || \
656 defined(WOLFSSL_KEY_GEN) || !defined(NO_DSA) || \
657 defined(OPENSSL_EXTRA)
658 #define XTOUPPER(c) toupper((c))
659 #endif
660 #ifdef OPENSSL_ALL
661 #define XISALNUM(c) isalnum((c))
662 #endif
663 /* needed by wolfSSL_check_domain_name() */
664 #define XTOLOWER(c) tolower((c))
665 #endif
666
667
668 /* memory allocation types for user hints */
669 enum {
670 DYNAMIC_TYPE_CA = 1,
671 DYNAMIC_TYPE_CERT = 2,
672 DYNAMIC_TYPE_KEY = 3,
673 DYNAMIC_TYPE_FILE = 4,
674 DYNAMIC_TYPE_SUBJECT_CN = 5,
675 DYNAMIC_TYPE_PUBLIC_KEY = 6,
676 DYNAMIC_TYPE_SIGNER = 7,
677 DYNAMIC_TYPE_NONE = 8,
678 DYNAMIC_TYPE_BIGINT = 9,
679 DYNAMIC_TYPE_RSA = 10,
680 DYNAMIC_TYPE_METHOD = 11,
681 DYNAMIC_TYPE_OUT_BUFFER = 12,
682 DYNAMIC_TYPE_IN_BUFFER = 13,
683 DYNAMIC_TYPE_INFO = 14,
684 DYNAMIC_TYPE_DH = 15,
685 DYNAMIC_TYPE_DOMAIN = 16,
686 DYNAMIC_TYPE_SSL = 17,
687 DYNAMIC_TYPE_CTX = 18,
688 DYNAMIC_TYPE_WRITEV = 19,
689 DYNAMIC_TYPE_OPENSSL = 20,
690 DYNAMIC_TYPE_DSA = 21,
691 DYNAMIC_TYPE_CRL = 22,
692 DYNAMIC_TYPE_REVOKED = 23,
693 DYNAMIC_TYPE_CRL_ENTRY = 24,
694 DYNAMIC_TYPE_CERT_MANAGER = 25,
695 DYNAMIC_TYPE_CRL_MONITOR = 26,
696 DYNAMIC_TYPE_OCSP_STATUS = 27,
697 DYNAMIC_TYPE_OCSP_ENTRY = 28,
698 DYNAMIC_TYPE_ALTNAME = 29,
699 DYNAMIC_TYPE_SUITES = 30,
700 DYNAMIC_TYPE_CIPHER = 31,
701 DYNAMIC_TYPE_RNG = 32,
702 DYNAMIC_TYPE_ARRAYS = 33,
703 DYNAMIC_TYPE_DTLS_POOL = 34,
704 DYNAMIC_TYPE_SOCKADDR = 35,
705 DYNAMIC_TYPE_LIBZ = 36,
706 DYNAMIC_TYPE_ECC = 37,
707 DYNAMIC_TYPE_TMP_BUFFER = 38,
708 DYNAMIC_TYPE_DTLS_MSG = 39,
709 DYNAMIC_TYPE_X509 = 40,
710 DYNAMIC_TYPE_TLSX = 41,
711 DYNAMIC_TYPE_OCSP = 42,
712 DYNAMIC_TYPE_SIGNATURE = 43,
713 DYNAMIC_TYPE_HASHES = 44,
714 DYNAMIC_TYPE_SRP = 45,
715 DYNAMIC_TYPE_COOKIE_PWD = 46,
716 DYNAMIC_TYPE_USER_CRYPTO = 47,
717 DYNAMIC_TYPE_OCSP_REQUEST = 48,
718 DYNAMIC_TYPE_X509_EXT = 49,
719 DYNAMIC_TYPE_X509_STORE = 50,
720 DYNAMIC_TYPE_X509_CTX = 51,
721 DYNAMIC_TYPE_URL = 52,
722 DYNAMIC_TYPE_DTLS_FRAG = 53,
723 DYNAMIC_TYPE_DTLS_BUFFER = 54,
724 DYNAMIC_TYPE_SESSION_TICK = 55,
725 DYNAMIC_TYPE_PKCS = 56,
726 DYNAMIC_TYPE_MUTEX = 57,
727 DYNAMIC_TYPE_PKCS7 = 58,
728 DYNAMIC_TYPE_AES_BUFFER = 59,
729 DYNAMIC_TYPE_WOLF_BIGINT = 60,
730 DYNAMIC_TYPE_ASN1 = 61,
731 DYNAMIC_TYPE_LOG = 62,
732 DYNAMIC_TYPE_WRITEDUP = 63,
733 DYNAMIC_TYPE_PRIVATE_KEY = 64,
734 DYNAMIC_TYPE_HMAC = 65,
735 DYNAMIC_TYPE_ASYNC = 66,
736 DYNAMIC_TYPE_ASYNC_NUMA = 67,
737 DYNAMIC_TYPE_ASYNC_NUMA64 = 68,
738 DYNAMIC_TYPE_CURVE25519 = 69,
739 DYNAMIC_TYPE_ED25519 = 70,
740 DYNAMIC_TYPE_SECRET = 71,
741 DYNAMIC_TYPE_DIGEST = 72,
742 DYNAMIC_TYPE_RSA_BUFFER = 73,
743 DYNAMIC_TYPE_DCERT = 74,
744 DYNAMIC_TYPE_STRING = 75,
745 DYNAMIC_TYPE_PEM = 76,
746 DYNAMIC_TYPE_DER = 77,
747 DYNAMIC_TYPE_CERT_EXT = 78,
748 DYNAMIC_TYPE_ALPN = 79,
749 DYNAMIC_TYPE_ENCRYPTEDINFO= 80,
750 DYNAMIC_TYPE_DIRCTX = 81,
751 DYNAMIC_TYPE_HASHCTX = 82,
752 DYNAMIC_TYPE_SEED = 83,
753 DYNAMIC_TYPE_SYMMETRIC_KEY= 84,
754 DYNAMIC_TYPE_ECC_BUFFER = 85,
755 DYNAMIC_TYPE_QSH = 86,
756 DYNAMIC_TYPE_SALT = 87,
757 DYNAMIC_TYPE_HASH_TMP = 88,
758 DYNAMIC_TYPE_BLOB = 89,
759 DYNAMIC_TYPE_NAME_ENTRY = 90,
760 DYNAMIC_TYPE_CURVE448 = 91,
761 DYNAMIC_TYPE_ED448 = 92,
762 DYNAMIC_TYPE_AES = 93,
763 DYNAMIC_TYPE_CMAC = 94,
764 DYNAMIC_TYPE_SNIFFER_SERVER = 1000,
765 DYNAMIC_TYPE_SNIFFER_SESSION = 1001,
766 DYNAMIC_TYPE_SNIFFER_PB = 1002,
767 DYNAMIC_TYPE_SNIFFER_PB_BUFFER = 1003,
768 DYNAMIC_TYPE_SNIFFER_TICKET_ID = 1004,
769 DYNAMIC_TYPE_SNIFFER_NAMED_KEY = 1005,
770 };
771
772 /* max error buffer string size */
773 #ifndef WOLFSSL_MAX_ERROR_SZ
774 #define WOLFSSL_MAX_ERROR_SZ 80
775 #endif
776
777 /* stack protection */
778 enum {
779 MIN_STACK_BUFFER = 8
780 };
781
782
783 /* Algorithm Types */
784 enum wc_AlgoType {
785 WC_ALGO_TYPE_NONE = 0,
786 WC_ALGO_TYPE_HASH = 1,
787 WC_ALGO_TYPE_CIPHER = 2,
788 WC_ALGO_TYPE_PK = 3,
789 WC_ALGO_TYPE_RNG = 4,
790 WC_ALGO_TYPE_SEED = 5,
791 WC_ALGO_TYPE_HMAC = 6,
792
793 WC_ALGO_TYPE_MAX = WC_ALGO_TYPE_HMAC
794 };
795
796 /* hash types */
797 enum wc_HashType {
798 #if defined(HAVE_SELFTEST) || defined(HAVE_FIPS) && \
799 (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2))
800 /* In selftest build, WC_* types are not mapped to WC_HASH_TYPE types.
801 * Values here are based on old selftest hmac.h enum, with additions.
802 * These values are fixed for backwards FIPS compatibility */
803 WC_HASH_TYPE_NONE = 15,
804 WC_HASH_TYPE_MD2 = 16,
805 WC_HASH_TYPE_MD4 = 17,
806 WC_HASH_TYPE_MD5 = 0,
807 WC_HASH_TYPE_SHA = 1, /* SHA-1 (not old SHA-0) */
808 WC_HASH_TYPE_SHA224 = 8,
809 WC_HASH_TYPE_SHA256 = 2,
810 WC_HASH_TYPE_SHA384 = 5,
811 WC_HASH_TYPE_SHA512 = 4,
812 WC_HASH_TYPE_MD5_SHA = 18,
813 WC_HASH_TYPE_SHA3_224 = 10,
814 WC_HASH_TYPE_SHA3_256 = 11,
815 WC_HASH_TYPE_SHA3_384 = 12,
816 WC_HASH_TYPE_SHA3_512 = 13,
817 WC_HASH_TYPE_BLAKE2B = 14,
818 WC_HASH_TYPE_BLAKE2S = 19,
819
820 WC_HASH_TYPE_MAX = WC_HASH_TYPE_BLAKE2S
821 #else
822 WC_HASH_TYPE_NONE = 0,
823 WC_HASH_TYPE_MD2 = 1,
824 WC_HASH_TYPE_MD4 = 2,
825 WC_HASH_TYPE_MD5 = 3,
826 WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */
827 WC_HASH_TYPE_SHA224 = 5,
828 WC_HASH_TYPE_SHA256 = 6,
829 WC_HASH_TYPE_SHA384 = 7,
830 WC_HASH_TYPE_SHA512 = 8,
831 WC_HASH_TYPE_MD5_SHA = 9,
832 WC_HASH_TYPE_SHA3_224 = 10,
833 WC_HASH_TYPE_SHA3_256 = 11,
834 WC_HASH_TYPE_SHA3_384 = 12,
835 WC_HASH_TYPE_SHA3_512 = 13,
836 WC_HASH_TYPE_BLAKE2B = 14,
837 WC_HASH_TYPE_BLAKE2S = 15,
838
839 WC_HASH_TYPE_MAX = WC_HASH_TYPE_BLAKE2S
840 #endif /* HAVE_SELFTEST */
841 };
842
843 /* cipher types */
844 enum wc_CipherType {
845 WC_CIPHER_NONE = 0,
846 WC_CIPHER_AES = 1,
847 WC_CIPHER_AES_CBC = 2,
848 WC_CIPHER_AES_GCM = 3,
849 WC_CIPHER_AES_CTR = 4,
850 WC_CIPHER_AES_XTS = 5,
851 WC_CIPHER_AES_CFB = 6,
852 WC_CIPHER_DES3 = 7,
853 WC_CIPHER_DES = 8,
854 WC_CIPHER_CHACHA = 9,
855 WC_CIPHER_HC128 = 10,
856 WC_CIPHER_IDEA = 11,
857
858 WC_CIPHER_MAX = WC_CIPHER_HC128
859 };
860
861 /* PK=public key (asymmetric) based algorithms */
862 enum wc_PkType {
863 WC_PK_TYPE_NONE = 0,
864 WC_PK_TYPE_RSA = 1,
865 WC_PK_TYPE_DH = 2,
866 WC_PK_TYPE_ECDH = 3,
867 WC_PK_TYPE_ECDSA_SIGN = 4,
868 WC_PK_TYPE_ECDSA_VERIFY = 5,
869 WC_PK_TYPE_ED25519 = 6,
870 WC_PK_TYPE_CURVE25519 = 7,
871 WC_PK_TYPE_RSA_KEYGEN = 8,
872 WC_PK_TYPE_EC_KEYGEN = 9,
873 WC_PK_TYPE_RSA_CHECK_PRIV_KEY = 10,
874 WC_PK_TYPE_EC_CHECK_PRIV_KEY = 11,
875
876 WC_PK_TYPE_MAX = WC_PK_TYPE_EC_CHECK_PRIV_KEY
877 };
878
879
880 /* settings detection for compile vs runtime math incompatibilities */
881 enum {
882 #if !defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
883 CTC_SETTINGS = 0x0
884 #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
885 CTC_SETTINGS = 0x1
886 #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
887 CTC_SETTINGS = 0x2
888 #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
889 CTC_SETTINGS = 0x4
890 #elif defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
891 CTC_SETTINGS = 0x8
892 #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
893 CTC_SETTINGS = 0x10
894 #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
895 CTC_SETTINGS = 0x20
896 #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
897 CTC_SETTINGS = 0x40
898 #else
899 #error "bad math long / long long settings"
900 #endif
901 };
902
903
904 WOLFSSL_API word32 CheckRunTimeSettings(void);
905
906 /* If user uses RSA, DH, DSA, or ECC math lib directly then fast math and long
907 types need to match at compile time and run time, CheckCtcSettings will
908 return 1 if a match otherwise 0 */
909 #define CheckCtcSettings() (CTC_SETTINGS == CheckRunTimeSettings())
910
911 /* invalid device id */
912 #define INVALID_DEVID -2
913
914
915 /* AESNI requires alignment and ARMASM gains some performance from it
916 * Xilinx RSA operations require alignment */
917 #if defined(WOLFSSL_AESNI) || defined(WOLFSSL_ARMASM) || \
918 defined(USE_INTEL_SPEEDUP) || defined(WOLFSSL_AFALG_XILINX)
919 #if !defined(ALIGN16)
920 #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
921 #define ALIGN16 __attribute__ ( (aligned (16)))
922 #elif defined(_MSC_VER)
923 /* disable align warning, we want alignment ! */
924 #pragma warning(disable: 4324)
925 #define ALIGN16 __declspec (align (16))
926 #else
927 #define ALIGN16
928 #endif
929 #endif /* !ALIGN16 */
930
931 #if !defined (ALIGN32)
932 #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
933 #define ALIGN32 __attribute__ ( (aligned (32)))
934 #elif defined(_MSC_VER)
935 /* disable align warning, we want alignment ! */
936 #pragma warning(disable: 4324)
937 #define ALIGN32 __declspec (align (32))
938 #else
939 #define ALIGN32
940 #endif
941 #endif /* !ALIGN32 */
942
943 #if !defined(ALIGN64)
944 #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
945 #define ALIGN64 __attribute__ ( (aligned (64)))
946 #elif defined(_MSC_VER)
947 /* disable align warning, we want alignment ! */
948 #pragma warning(disable: 4324)
949 #define ALIGN64 __declspec (align (64))
950 #else
951 #define ALIGN64
952 #endif
953 #endif /* !ALIGN64 */
954
955 #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
956 #define ALIGN128 __attribute__ ( (aligned (128)))
957 #elif defined(_MSC_VER)
958 /* disable align warning, we want alignment ! */
959 #pragma warning(disable: 4324)
960 #define ALIGN128 __declspec (align (128))
961 #else
962 #define ALIGN128
963 #endif
964
965 #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
966 #define ALIGN256 __attribute__ ( (aligned (256)))
967 #elif defined(_MSC_VER)
968 /* disable align warning, we want alignment ! */
969 #pragma warning(disable: 4324)
970 #define ALIGN256 __declspec (align (256))
971 #else
972 #define ALIGN256
973 #endif
974
975 #else
976 #ifndef ALIGN16
977 #define ALIGN16
978 #endif
979 #ifndef ALIGN32
980 #define ALIGN32
981 #endif
982 #ifndef ALIGN64
983 #define ALIGN64
984 #endif
985 #ifndef ALIGN128
986 #define ALIGN128
987 #endif
988 #ifndef ALIGN256
989 #define ALIGN256
990 #endif
991 #endif /* WOLFSSL_AESNI || WOLFSSL_ARMASM */
992
993
994 #ifndef TRUE
995 #define TRUE 1
996 #endif
997 #ifndef FALSE
998 #define FALSE 0
999 #endif
1000
1001
1002 #if defined(HAVE_STACK_SIZE)
1003 #define EXIT_TEST(ret) return (void*)((size_t)(ret))
1004 #else
1005 #define EXIT_TEST(ret) return ret
1006 #endif
1007
1008
1009 #if (defined(__IAR_SYSTEMS_ICC__) && (__IAR_SYSTEMS_ICC__ > 8)) || \
1010 defined(__GNUC__)
1011 #define WOLFSSL_PACK __attribute__ ((packed))
1012 #else
1013 #define WOLFSSL_PACK
1014 #endif
1015
1016 #ifndef __GNUC_PREREQ
1017 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
1018 #define __GNUC_PREREQ(maj, min) \
1019 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
1020 #else
1021 #define __GNUC_PREREQ(maj, min) (0) /* not GNUC */
1022 #endif
1023 #endif
1024
1025 #if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
1026 #define WC_NORETURN __attribute__((noreturn))
1027 #else
1028 #define WC_NORETURN
1029 #endif
1030
1031 #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) || \
1032 defined(WOLFSSL_DEBUG_MATH) || defined(DEBUG_WOLFSSL) || \
1033 defined(WOLFSSL_PUBLIC_MP) || defined(OPENSSL_EXTRA) || \
1034 (defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT))
1035 #undef WC_MP_TO_RADIX
1036 #define WC_MP_TO_RADIX
1037 #endif
1038
1039 #ifdef __cplusplus
1040 } /* extern "C" */
1041 #endif
1042
1043#endif /* WOLF_CRYPT_TYPES_H */
Note: See TracBrowser for help on using the repository browser.