source: azure_iot_hub/trunk/wolfssl-3.15.7/wolfssl/wolfcrypt/types.h@ 389

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

ビルドが通るよう更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 27.5 KB
Line 
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
22/*!
23 \file wolfssl/wolfcrypt/types.h
24*/
25
26#ifndef WOLF_CRYPT_TYPES_H
27#define WOLF_CRYPT_TYPES_H
28
29 #include <wolfssl/wolfcrypt/settings.h>
30 #include <wolfssl/wolfcrypt/wc_port.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36
37 #if defined(WORDS_BIGENDIAN)
38 #define BIG_ENDIAN_ORDER
39 #endif
40
41 #ifndef BIG_ENDIAN_ORDER
42 #define LITTLE_ENDIAN_ORDER
43 #endif
44
45 #ifndef WOLFSSL_TYPES
46 #ifndef byte
47 typedef unsigned char byte;
48 #endif
49 typedef unsigned short word16;
50 typedef unsigned int word32;
51 typedef byte word24[3];
52 #endif
53
54
55 /* try to set SIZEOF_LONG or LONG_LONG if user didn't */
56 #if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__) && !defined(__EMSCRIPTEN__)
57 #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG)
58 #if (defined(__alpha__) || defined(__ia64__) || \
59 defined(_ARCH_PPC64) || defined(__mips64) || \
60 defined(__x86_64__) || \
61 ((defined(sun) || defined(__sun)) && \
62 (defined(LP64) || defined(_LP64))))
63 /* long should be 64bit */
64 #define SIZEOF_LONG 8
65 #elif defined(__i386__) || defined(__CORTEX_M3__)
66 /* long long should be 64bit */
67 #define SIZEOF_LONG_LONG 8
68 #endif
69 #endif
70 #endif
71
72 #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
73 #define WORD64_AVAILABLE
74 #define W64LIT(x) x##ui64
75 typedef unsigned __int64 word64;
76 #elif defined(__EMSCRIPTEN__)
77 #define WORD64_AVAILABLE
78 #define W64LIT(x) x##ull
79 typedef unsigned long long word64;
80 #elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8
81 #define WORD64_AVAILABLE
82 #define W64LIT(x) x##LL
83 typedef unsigned long word64;
84 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG == 8
85 #define WORD64_AVAILABLE
86 #define W64LIT(x) x##LL
87 typedef unsigned long long word64;
88 #elif defined(__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 8
89 #define WORD64_AVAILABLE
90 #define W64LIT(x) x##LL
91 typedef unsigned long long word64;
92 #endif
93
94#if !defined(NO_64BIT) && defined(WORD64_AVAILABLE)
95 /* These platforms have 64-bit CPU registers. */
96 #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
97 defined(__mips64) || defined(__x86_64__) || defined(_M_X64)) || \
98 defined(__aarch64__) || defined(__sparc64__)
99 typedef word64 wolfssl_word;
100 #define WC_64BIT_CPU
101 #elif (defined(sun) || defined(__sun)) && \
102 (defined(LP64) || defined(_LP64))
103 /* LP64 with GNU GCC compiler is reserved for when long int is 64 bits
104 * and int uses 32 bits. When using Solaris Studio sparc and __sparc are
105 * available for 32 bit detection but __sparc64__ could be missed. This
106 * uses LP64 for checking 64 bit CPU arch. */
107 typedef word64 wolfssl_word;
108 #define WC_64BIT_CPU
109 #else
110 typedef word32 wolfssl_word;
111 #ifdef WORD64_AVAILABLE
112 #define WOLFCRYPT_SLOW_WORD64
113 #endif
114 #endif
115#else
116 #undef WORD64_AVAILABLE
117 typedef word32 wolfssl_word;
118 #define MP_16BIT /* for mp_int, mp_word needs to be twice as big as
119 mp_digit, no 64 bit type so make mp_digit 16 bit */
120#endif
121
122 enum {
123 WOLFSSL_WORD_SIZE = sizeof(wolfssl_word),
124 WOLFSSL_BIT_SIZE = 8,
125 WOLFSSL_WORD_BITS = WOLFSSL_WORD_SIZE * WOLFSSL_BIT_SIZE
126 };
127
128 #define WOLFSSL_MAX_16BIT 0xffffU
129
130 /* use inlining if compiler allows */
131 #ifndef WC_INLINE
132 #ifndef NO_INLINE
133 #ifdef _MSC_VER
134 #define WC_INLINE __inline
135 #elif defined(__GNUC__)
136 #ifdef WOLFSSL_VXWORKS
137 #define WC_INLINE __inline__
138 #else
139 #define WC_INLINE inline
140 #endif
141 #elif defined(__IAR_SYSTEMS_ICC__)
142 #define WC_INLINE inline
143 #elif defined(THREADX)
144 #define WC_INLINE _Inline
145 #else
146 #define WC_INLINE
147 #endif
148 #else
149 #define WC_INLINE
150 #endif
151 #endif
152
153 #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
154 #define INLINE WC_INLINE
155 #endif
156
157
158 /* set up rotate style */
159 #if (defined(_MSC_VER) || defined(__BCPLUSPLUS__)) && \
160 !defined(WOLFSSL_SGX) && !defined(INTIME_RTOS)
161 #define INTEL_INTRINSICS
162 #define FAST_ROTATE
163 #elif defined(__MWERKS__) && TARGET_CPU_PPC
164 #define PPC_INTRINSICS
165 #define FAST_ROTATE
166 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
167 /* GCC does peephole optimizations which should result in using rotate
168 instructions */
169 #define FAST_ROTATE
170 #endif
171
172
173 /* set up thread local storage if available */
174 #ifdef HAVE_THREAD_LS
175 #if defined(_MSC_VER)
176 #define THREAD_LS_T __declspec(thread)
177 /* Thread local storage only in FreeRTOS v8.2.1 and higher */
178 #elif defined(FREERTOS) || defined(FREERTOS_TCP)
179 #define THREAD_LS_T
180 #else
181 #define THREAD_LS_T __thread
182 #endif
183 #else
184 #define THREAD_LS_T
185 #endif
186
187 /* GCC 7 has new switch() fall-through detection */
188 #if defined(__GNUC__)
189 #if ((__GNUC__ > 7) || ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 1)))
190 #define FALL_THROUGH __attribute__ ((fallthrough))
191 #endif
192 #endif
193 #ifndef FALL_THROUGH
194 #define FALL_THROUGH
195 #endif
196
197 /* Micrium will use Visual Studio for compilation but not the Win32 API */
198 #if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && \
199 !defined(FREERTOS_TCP) && !defined(EBSNET) && \
200 !defined(WOLFSSL_UTASKER) && !defined(INTIME_RTOS)
201 #define USE_WINDOWS_API
202 #endif
203
204
205 /* idea to add global alloc override by Moises Guimaraes */
206 /* default to libc stuff */
207 /* XREALLOC is used once in normal math lib, not in fast math lib */
208 /* XFREE on some embedded systems doesn't like free(0) so test */
209 #if defined(HAVE_IO_POOL)
210 WOLFSSL_API void* XMALLOC(size_t n, void* heap, int type);
211 WOLFSSL_API void* XREALLOC(void *p, size_t n, void* heap, int type);
212 WOLFSSL_API void XFREE(void *p, void* heap, int type);
213 #elif defined(WOLFSSL_ASYNC_CRYPT) && defined(HAVE_INTEL_QA)
214 #include <wolfssl/wolfcrypt/port/intel/quickassist_mem.h>
215 #undef USE_WOLFSSL_MEMORY
216 #ifdef WOLFSSL_DEBUG_MEMORY
217 #define XMALLOC(s, h, t) IntelQaMalloc((s), (h), (t), __func__, __LINE__)
218 #define XFREE(p, h, t) IntelQaFree((p), (h), (t), __func__, __LINE__)
219 #define XREALLOC(p, n, h, t) IntelQaRealloc((p), (n), (h), (t), __func__, __LINE__)
220 #else
221 #define XMALLOC(s, h, t) IntelQaMalloc((s), (h), (t))
222 #define XFREE(p, h, t) IntelQaFree((p), (h), (t))
223 #define XREALLOC(p, n, h, t) IntelQaRealloc((p), (n), (h), (t))
224 #endif /* WOLFSSL_DEBUG_MEMORY */
225 #elif defined(XMALLOC_USER)
226 /* prototypes for user heap override functions */
227 #include <stddef.h> /* for size_t */
228 extern void *XMALLOC(size_t n, void* heap, int type);
229 extern void *XREALLOC(void *p, size_t n, void* heap, int type);
230 extern void XFREE(void *p, void* heap, int type);
231 #elif defined(WOLFSSL_MEMORY_LOG)
232 #define XMALLOC(n, h, t) xmalloc(n, h, t, __func__, __FILE__, __LINE__)
233 #define XREALLOC(p, n, h, t) xrealloc(p, n, h, t, __func__, __FILE__, __LINE__)
234 #define XFREE(p, h, t) xfree(p, h, t, __func__, __FILE__, __LINE__)
235
236 /* prototypes for user heap override functions */
237 #include <stddef.h> /* for size_t */
238 #include <stdlib.h>
239 extern void *xmalloc(size_t n, void* heap, int type, const char* func,
240 const char* file, unsigned int line);
241 extern void *xrealloc(void *p, size_t n, void* heap, int type,
242 const char* func, const char* file, unsigned int line);
243 extern void xfree(void *p, void* heap, int type, const char* func,
244 const char* file, unsigned int line);
245 #elif defined(XMALLOC_OVERRIDE)
246 /* override the XMALLOC, XFREE and XREALLOC macros */
247 #elif defined(NO_WOLFSSL_MEMORY)
248 /* just use plain C stdlib stuff if desired */
249 #include <stdlib.h>
250 #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s)))
251 #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
252 #define XREALLOC(p, n, h, t) realloc((p), (n))
253 #elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) \
254 && !defined(WOLFSSL_SAFERTOS) && !defined(FREESCALE_MQX) \
255 && !defined(FREESCALE_KSDK_MQX) && !defined(FREESCALE_FREE_RTOS) \
256 && !defined(WOLFSSL_LEANPSK) && !defined(WOLFSSL_uITRON4)
257 /* default C runtime, can install different routines at runtime via cbs */
258 #include <wolfssl/wolfcrypt/memory.h>
259 #ifdef WOLFSSL_STATIC_MEMORY
260 #ifdef WOLFSSL_DEBUG_MEMORY
261 #define XMALLOC(s, h, t) wolfSSL_Malloc((s), (h), (t), __func__, __LINE__)
262 #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), (h), (t), __func__, __LINE__);}
263 #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), (h), (t), __func__, __LINE__)
264 #else
265 #define XMALLOC(s, h, t) wolfSSL_Malloc((s), (h), (t))
266 #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), (h), (t));}
267 #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), (h), (t))
268 #endif /* WOLFSSL_DEBUG_MEMORY */
269 #elif !defined(FREERTOS) && !defined(FREERTOS_TCP)
270 #ifdef WOLFSSL_DEBUG_MEMORY
271 #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s), __func__, __LINE__))
272 #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), __func__, __LINE__);}
273 #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), __func__, __LINE__)
274 #else
275 #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s)))
276 #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));}
277 #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))
278 #endif /* WOLFSSL_DEBUG_MEMORY */
279 #endif /* WOLFSSL_STATIC_MEMORY */
280 #endif
281
282 /* declare/free variable handling for async */
283 #ifdef WOLFSSL_ASYNC_CRYPT
284 #define DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
285 VAR_TYPE* VAR_NAME = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT);
286 #define DECLARE_VAR_INIT(VAR_NAME, VAR_TYPE, VAR_SIZE, INIT_VALUE, HEAP) \
287 VAR_TYPE* VAR_NAME = ({ \
288 VAR_TYPE* ptr = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \
289 if (ptr && INIT_VALUE) { \
290 XMEMCPY(ptr, INIT_VALUE, sizeof(VAR_TYPE) * VAR_SIZE); \
291 } \
292 ptr; \
293 })
294 #define DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
295 VAR_TYPE* VAR_NAME[VAR_ITEMS]; \
296 int idx##VAR_NAME; \
297 for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \
298 VAR_NAME[idx##VAR_NAME] = (VAR_TYPE*)XMALLOC(VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \
299 }
300 #define FREE_VAR(VAR_NAME, HEAP) \
301 XFREE(VAR_NAME, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT);
302 #define FREE_ARRAY(VAR_NAME, VAR_ITEMS, HEAP) \
303 for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \
304 XFREE(VAR_NAME[idx##VAR_NAME], (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \
305 }
306 #else
307 #define DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
308 VAR_TYPE VAR_NAME[VAR_SIZE]
309 #define DECLARE_VAR_INIT(VAR_NAME, VAR_TYPE, VAR_SIZE, INIT_VALUE, HEAP) \
310 VAR_TYPE* VAR_NAME = (VAR_TYPE*)INIT_VALUE
311 #define DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
312 VAR_TYPE VAR_NAME[VAR_ITEMS][VAR_SIZE]
313 #define FREE_VAR(VAR_NAME, HEAP) /* nothing to free, its stack */
314 #define FREE_ARRAY(VAR_NAME, VAR_ITEMS, HEAP) /* nothing to free, its stack */
315 #endif
316
317 #if !defined(USE_WOLF_STRTOK) && \
318 ((defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) || \
319 defined(WOLFSSL_TIRTOS) || defined(WOLF_C99))
320 #define USE_WOLF_STRTOK
321 #endif
322 #if !defined(USE_WOLF_STRSEP) && (defined(WOLF_C99))
323 #define USE_WOLF_STRSEP
324 #endif
325
326 #ifndef STRING_USER
327 #include <string.h>
328 #define XMEMCPY(d,s,l) memcpy((d),(s),(l))
329 #define XMEMSET(b,c,l) memset((b),(c),(l))
330 #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
331 #define XMEMMOVE(d,s,l) memmove((d),(s),(l))
332
333 #define XSTRLEN(s1) strlen((s1))
334 #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
335 /* strstr, strncmp, and strncat only used by wolfSSL proper,
336 * not required for wolfCrypt only */
337 #define XSTRSTR(s1,s2) strstr((s1),(s2))
338 #define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n))
339 #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
340 #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
341
342 #ifdef USE_WOLF_STRSEP
343 #define XSTRSEP(s1,d) wc_strsep((s1),(d))
344 #else
345 #define XSTRSEP(s1,d) strsep((s1),(d))
346 #endif
347
348 #if defined(MICROCHIP_PIC32) || defined(WOLFSSL_TIRTOS)
349 /* XC32 does not support strncasecmp, so use case sensitive one */
350 #define XSTRNCASECMP(s1,s2,n) strncmp((s1),(s2),(n))
351 #elif defined(USE_WINDOWS_API) || defined(FREERTOS_TCP_WINSIM)
352 #define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
353 #else
354 #if defined(HAVE_STRINGS_H) && defined(WOLF_C99) && \
355 !defined(WOLFSSL_SGX)
356 #include <strings.h>
357 #endif
358 #define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
359 #endif
360
361 /* snprintf is used in asn.c for GetTimeString, PKCS7 test, and when
362 debugging is turned on */
363 #ifndef USE_WINDOWS_API
364 #if defined(NO_FILESYSTEM) && (defined(OPENSSL_EXTRA) || \
365 defined(HAVE_PKCS7)) && !defined(NO_STDIO_FILESYSTEM)
366 /* case where stdio is not included else where but is needed for
367 * snprintf */
368 #include <stdio.h>
369 #endif
370 #define XSNPRINTF snprintf
371 #else
372 #define XSNPRINTF _snprintf
373 #endif
374
375 #if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
376 /* use only Thread Safe version of strtok */
377 #if defined(USE_WOLF_STRTOK)
378 #define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
379 #elif defined(USE_WINDOWS_API) || defined(INTIME_RTOS)
380 #define XSTRTOK(s1,d,ptr) strtok_s((s1),(d),(ptr))
381 #else
382 #define XSTRTOK(s1,d,ptr) strtok_r((s1),(d),(ptr))
383 #endif
384 #endif
385 #endif
386
387 #ifdef USE_WOLF_STRTOK
388 WOLFSSL_API char* wc_strtok(char *str, const char *delim, char **nextp);
389 #endif
390 #ifdef USE_WOLF_STRSEP
391 WOLFSSL_API char* wc_strsep(char **stringp, const char *delim);
392 #endif
393
394 #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
395 !defined(NO_STDIO_FILESYSTEM)
396 #ifndef XGETENV
397 #include <stdlib.h>
398 #define XGETENV getenv
399 #endif
400 #endif /* OPENSSL_EXTRA */
401
402 #ifndef CTYPE_USER
403 #include <ctype.h>
404 #if defined(HAVE_ECC) || defined(HAVE_OCSP) || \
405 defined(WOLFSSL_KEY_GEN) || !defined(NO_DSA)
406 #define XTOUPPER(c) toupper((c))
407 #define XISALPHA(c) isalpha((c))
408 #endif
409 /* needed by wolfSSL_check_domain_name() */
410 #define XTOLOWER(c) tolower((c))
411 #endif
412
413
414 /* memory allocation types for user hints */
415 enum {
416 DYNAMIC_TYPE_CA = 1,
417 DYNAMIC_TYPE_CERT = 2,
418 DYNAMIC_TYPE_KEY = 3,
419 DYNAMIC_TYPE_FILE = 4,
420 DYNAMIC_TYPE_SUBJECT_CN = 5,
421 DYNAMIC_TYPE_PUBLIC_KEY = 6,
422 DYNAMIC_TYPE_SIGNER = 7,
423 DYNAMIC_TYPE_NONE = 8,
424 DYNAMIC_TYPE_BIGINT = 9,
425 DYNAMIC_TYPE_RSA = 10,
426 DYNAMIC_TYPE_METHOD = 11,
427 DYNAMIC_TYPE_OUT_BUFFER = 12,
428 DYNAMIC_TYPE_IN_BUFFER = 13,
429 DYNAMIC_TYPE_INFO = 14,
430 DYNAMIC_TYPE_DH = 15,
431 DYNAMIC_TYPE_DOMAIN = 16,
432 DYNAMIC_TYPE_SSL = 17,
433 DYNAMIC_TYPE_CTX = 18,
434 DYNAMIC_TYPE_WRITEV = 19,
435 DYNAMIC_TYPE_OPENSSL = 20,
436 DYNAMIC_TYPE_DSA = 21,
437 DYNAMIC_TYPE_CRL = 22,
438 DYNAMIC_TYPE_REVOKED = 23,
439 DYNAMIC_TYPE_CRL_ENTRY = 24,
440 DYNAMIC_TYPE_CERT_MANAGER = 25,
441 DYNAMIC_TYPE_CRL_MONITOR = 26,
442 DYNAMIC_TYPE_OCSP_STATUS = 27,
443 DYNAMIC_TYPE_OCSP_ENTRY = 28,
444 DYNAMIC_TYPE_ALTNAME = 29,
445 DYNAMIC_TYPE_SUITES = 30,
446 DYNAMIC_TYPE_CIPHER = 31,
447 DYNAMIC_TYPE_RNG = 32,
448 DYNAMIC_TYPE_ARRAYS = 33,
449 DYNAMIC_TYPE_DTLS_POOL = 34,
450 DYNAMIC_TYPE_SOCKADDR = 35,
451 DYNAMIC_TYPE_LIBZ = 36,
452 DYNAMIC_TYPE_ECC = 37,
453 DYNAMIC_TYPE_TMP_BUFFER = 38,
454 DYNAMIC_TYPE_DTLS_MSG = 39,
455 DYNAMIC_TYPE_X509 = 40,
456 DYNAMIC_TYPE_TLSX = 41,
457 DYNAMIC_TYPE_OCSP = 42,
458 DYNAMIC_TYPE_SIGNATURE = 43,
459 DYNAMIC_TYPE_HASHES = 44,
460 DYNAMIC_TYPE_SRP = 45,
461 DYNAMIC_TYPE_COOKIE_PWD = 46,
462 DYNAMIC_TYPE_USER_CRYPTO = 47,
463 DYNAMIC_TYPE_OCSP_REQUEST = 48,
464 DYNAMIC_TYPE_X509_EXT = 49,
465 DYNAMIC_TYPE_X509_STORE = 50,
466 DYNAMIC_TYPE_X509_CTX = 51,
467 DYNAMIC_TYPE_URL = 52,
468 DYNAMIC_TYPE_DTLS_FRAG = 53,
469 DYNAMIC_TYPE_DTLS_BUFFER = 54,
470 DYNAMIC_TYPE_SESSION_TICK = 55,
471 DYNAMIC_TYPE_PKCS = 56,
472 DYNAMIC_TYPE_MUTEX = 57,
473 DYNAMIC_TYPE_PKCS7 = 58,
474 DYNAMIC_TYPE_AES_BUFFER = 59,
475 DYNAMIC_TYPE_WOLF_BIGINT = 60,
476 DYNAMIC_TYPE_ASN1 = 61,
477 DYNAMIC_TYPE_LOG = 62,
478 DYNAMIC_TYPE_WRITEDUP = 63,
479 DYNAMIC_TYPE_PRIVATE_KEY = 64,
480 DYNAMIC_TYPE_HMAC = 65,
481 DYNAMIC_TYPE_ASYNC = 66,
482 DYNAMIC_TYPE_ASYNC_NUMA = 67,
483 DYNAMIC_TYPE_ASYNC_NUMA64 = 68,
484 DYNAMIC_TYPE_CURVE25519 = 69,
485 DYNAMIC_TYPE_ED25519 = 70,
486 DYNAMIC_TYPE_SECRET = 71,
487 DYNAMIC_TYPE_DIGEST = 72,
488 DYNAMIC_TYPE_RSA_BUFFER = 73,
489 DYNAMIC_TYPE_DCERT = 74,
490 DYNAMIC_TYPE_STRING = 75,
491 DYNAMIC_TYPE_PEM = 76,
492 DYNAMIC_TYPE_DER = 77,
493 DYNAMIC_TYPE_CERT_EXT = 78,
494 DYNAMIC_TYPE_ALPN = 79,
495 DYNAMIC_TYPE_ENCRYPTEDINFO= 80,
496 DYNAMIC_TYPE_DIRCTX = 81,
497 DYNAMIC_TYPE_HASHCTX = 82,
498 DYNAMIC_TYPE_SEED = 83,
499 DYNAMIC_TYPE_SYMMETRIC_KEY= 84,
500 DYNAMIC_TYPE_ECC_BUFFER = 85,
501 DYNAMIC_TYPE_QSH = 86,
502 DYNAMIC_TYPE_SALT = 87,
503 DYNAMIC_TYPE_HASH_TMP = 88,
504 DYNAMIC_TYPE_BLOB = 89,
505 DYNAMIC_TYPE_NAME_ENTRY = 90,
506 };
507
508 /* max error buffer string size */
509 #ifndef WOLFSSL_MAX_ERROR_SZ
510 #define WOLFSSL_MAX_ERROR_SZ 80
511 #endif
512
513 /* stack protection */
514 enum {
515 MIN_STACK_BUFFER = 8
516 };
517
518
519 /* Algorithm Types */
520 enum wc_AlgoType {
521 WC_ALGO_TYPE_NONE = 0,
522 WC_ALGO_TYPE_HASH = 1,
523 WC_ALGO_TYPE_CIPHER = 2,
524 WC_ALGO_TYPE_PK = 3,
525
526 WC_ALGO_TYPE_MAX = WC_ALGO_TYPE_PK
527 };
528
529 /* hash types */
530 enum wc_HashType {
531 #if defined(HAVE_SELFTEST) || defined(HAVE_FIPS)
532 /* In selftest build, WC_* types are not mapped to WC_HASH_TYPE types.
533 * Values here are based on old selftest hmac.h enum, with additions */
534 WC_HASH_TYPE_NONE = 15,
535 WC_HASH_TYPE_MD2 = 16,
536 WC_HASH_TYPE_MD4 = 17,
537 WC_HASH_TYPE_MD5 = 0,
538 WC_HASH_TYPE_SHA = 1, /* SHA-1 (not old SHA-0) */
539 WC_HASH_TYPE_SHA224 = 8,
540 WC_HASH_TYPE_SHA256 = 2,
541 WC_HASH_TYPE_SHA384 = 5,
542 WC_HASH_TYPE_SHA512 = 4,
543 WC_HASH_TYPE_MD5_SHA = 18,
544 WC_HASH_TYPE_SHA3_224 = 10,
545 WC_HASH_TYPE_SHA3_256 = 11,
546 WC_HASH_TYPE_SHA3_384 = 12,
547 WC_HASH_TYPE_SHA3_512 = 13,
548 WC_HASH_TYPE_BLAKE2B = 14,
549
550 WC_HASH_TYPE_MAX = WC_HASH_TYPE_MD5_SHA
551 #else
552 WC_HASH_TYPE_NONE = 0,
553 WC_HASH_TYPE_MD2 = 1,
554 WC_HASH_TYPE_MD4 = 2,
555 WC_HASH_TYPE_MD5 = 3,
556 WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */
557 WC_HASH_TYPE_SHA224 = 5,
558 WC_HASH_TYPE_SHA256 = 6,
559 WC_HASH_TYPE_SHA384 = 7,
560 WC_HASH_TYPE_SHA512 = 8,
561 WC_HASH_TYPE_MD5_SHA = 9,
562 WC_HASH_TYPE_SHA3_224 = 10,
563 WC_HASH_TYPE_SHA3_256 = 11,
564 WC_HASH_TYPE_SHA3_384 = 12,
565 WC_HASH_TYPE_SHA3_512 = 13,
566 WC_HASH_TYPE_BLAKE2B = 14,
567
568 WC_HASH_TYPE_MAX = WC_HASH_TYPE_BLAKE2B
569 #endif /* HAVE_SELFTEST */
570 };
571
572 /* cipher types */
573 enum wc_CipherType {
574 WC_CIPHER_NONE = 0,
575 WC_CIPHER_AES = 1,
576 WC_CIPHER_AES_CBC = 2,
577 WC_CIPHER_AES_GCM = 3,
578 WC_CIPHER_AES_CTR = 4,
579 WC_CIPHER_AES_XTS = 5,
580 WC_CIPHER_AES_CFB = 6,
581 WC_CIPHER_DES3 = 7,
582 WC_CIPHER_DES = 8,
583 WC_CIPHER_CHACHA = 9,
584 WC_CIPHER_HC128 = 10,
585 WC_CIPHER_IDEA = 11,
586
587 WC_CIPHER_MAX = WC_CIPHER_HC128
588 };
589
590 /* PK=public key (asymmetric) based algorithms */
591 enum wc_PkType {
592 WC_PK_TYPE_NONE = 0,
593 WC_PK_TYPE_RSA = 1,
594 WC_PK_TYPE_DH = 2,
595 WC_PK_TYPE_ECDH = 3,
596 WC_PK_TYPE_ECDSA_SIGN = 4,
597 WC_PK_TYPE_ECDSA_VERIFY = 5,
598 WC_PK_TYPE_ED25519 = 6,
599 WC_PK_TYPE_CURVE25519 = 7,
600 WC_PK_TYPE_RSA_KEYGEN = 8,
601 WC_PK_TYPE_EC_KEYGEN = 9,
602
603 WC_PK_TYPE_MAX = WC_PK_TYPE_EC_KEYGEN
604 };
605
606
607 /* settings detection for compile vs runtime math incompatibilities */
608 enum {
609 #if !defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
610 CTC_SETTINGS = 0x0
611 #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
612 CTC_SETTINGS = 0x1
613 #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
614 CTC_SETTINGS = 0x2
615 #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
616 CTC_SETTINGS = 0x4
617 #elif defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
618 CTC_SETTINGS = 0x8
619 #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
620 CTC_SETTINGS = 0x10
621 #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
622 CTC_SETTINGS = 0x20
623 #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
624 CTC_SETTINGS = 0x40
625 #else
626 #error "bad math long / long long settings"
627 #endif
628 };
629
630
631 WOLFSSL_API word32 CheckRunTimeSettings(void);
632
633 /* If user uses RSA, DH, DSA, or ECC math lib directly then fast math and long
634 types need to match at compile time and run time, CheckCtcSettings will
635 return 1 if a match otherwise 0 */
636 #define CheckCtcSettings() (CTC_SETTINGS == CheckRunTimeSettings())
637
638 /* invalid device id */
639 #define INVALID_DEVID -2
640
641
642 /* AESNI requires alignment and ARMASM gains some performance from it */
643 #if defined(WOLFSSL_AESNI) || defined(WOLFSSL_ARMASM) || defined(USE_INTEL_SPEEDUP)
644 #if !defined(ALIGN16)
645 #if defined(__GNUC__)
646 #define ALIGN16 __attribute__ ( (aligned (16)))
647 #elif defined(_MSC_VER)
648 /* disable align warning, we want alignment ! */
649 #pragma warning(disable: 4324)
650 #define ALIGN16 __declspec (align (16))
651 #else
652 #define ALIGN16
653 #endif
654 #endif /* !ALIGN16 */
655
656 #if !defined (ALIGN32)
657 #if defined (__GNUC__)
658 #define ALIGN32 __attribute__ ( (aligned (32)))
659 #elif defined(_MSC_VER)
660 /* disable align warning, we want alignment ! */
661 #pragma warning(disable: 4324)
662 #define ALIGN32 __declspec (align (32))
663 #else
664 #define ALIGN32
665 #endif
666 #endif
667
668 #if !defined(ALIGN32)
669 #if defined(__GNUC__)
670 #define ALIGN32 __attribute__ ( (aligned (32)))
671 #elif defined(_MSC_VER)
672 /* disable align warning, we want alignment ! */
673 #pragma warning(disable: 4324)
674 #define ALIGN32 __declspec (align (32))
675 #else
676 #define ALIGN32
677 #endif
678 #endif /* !ALIGN32 */
679
680 #if defined(__GNUC__)
681 #define ALIGN128 __attribute__ ( (aligned (128)))
682 #elif defined(_MSC_VER)
683 /* disable align warning, we want alignment ! */
684 #pragma warning(disable: 4324)
685 #define ALIGN128 __declspec (align (128))
686 #else
687 #define ALIGN128
688 #endif
689
690 #if defined(__GNUC__)
691 #define ALIGN256 __attribute__ ( (aligned (256)))
692 #elif defined(_MSC_VER)
693 /* disable align warning, we want alignment ! */
694 #pragma warning(disable: 4324)
695 #define ALIGN256 __declspec (align (256))
696 #else
697 #define ALIGN256
698 #endif
699
700 #else
701 #ifndef ALIGN16
702 #define ALIGN16
703 #endif
704 #ifndef ALIGN32
705 #define ALIGN32
706 #endif
707 #ifndef ALIGN128
708 #define ALIGN128
709 #endif
710 #ifndef ALIGN256
711 #define ALIGN256
712 #endif
713 #endif /* WOLFSSL_AESNI || WOLFSSL_ARMASM */
714
715
716 #ifndef TRUE
717 #define TRUE 1
718 #endif
719 #ifndef FALSE
720 #define FALSE 0
721 #endif
722
723
724 #ifdef WOLFSSL_RIOT_OS
725 #define EXIT_TEST(ret) exit(ret)
726 #elif defined(HAVE_STACK_SIZE)
727 #define EXIT_TEST(ret) return (void*)((size_t)(ret))
728 #else
729 #define EXIT_TEST(ret) return ret
730 #endif
731
732
733 #if defined(__GNUC__)
734 #define WOLFSSL_PACK __attribute__ ((packed))
735 #else
736 #define WOLFSSL_PACK
737 #endif
738
739 #ifndef __GNUC_PREREQ
740 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
741 #define __GNUC_PREREQ(maj, min) \
742 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
743 #else
744 #define __GNUC_PREREQ(maj, min) (0) /* not GNUC */
745 #endif
746 #endif
747
748 #if defined(__GNUC__)
749 #define WC_NORETURN __attribute__((noreturn))
750 #else
751 #define WC_NORETURN
752 #endif
753
754 #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) || \
755 defined(WOLFSSL_DEBUG_MATH) || defined(DEBUG_WOLFSSL) || \
756 defined(WOLFSSL_PUBLIC_MP) || defined(OPENSSL_EXTRA) || \
757 (defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT))
758 #undef WC_MP_TO_RADIX
759 #define WC_MP_TO_RADIX
760 #endif
761
762 #ifdef __cplusplus
763 } /* extern "C" */
764 #endif
765
766#endif /* WOLF_CRYPT_TYPES_H */
Note: See TracBrowser for help on using the repository browser.