- Timestamp:
- Feb 7, 2019, 8:36:33 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/types.h
r352 r372 20 20 */ 21 21 22 22 /*! 23 \file wolfssl/wolfcrypt/types.h 24 */ 23 25 24 26 #ifndef WOLF_CRYPT_TYPES_H … … 52 54 53 55 /* try to set SIZEOF_LONG or LONG_LONG if user didn't */ 54 #if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__)56 #if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__) && !defined(__EMSCRIPTEN__) 55 57 #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG) 56 #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) \ 57 || defined(__mips64) || defined(__x86_64__) || \ 58 #if (defined(__alpha__) || defined(__ia64__) || \ 59 defined(_ARCH_PPC64) || defined(__mips64) || \ 60 defined(__x86_64__) || \ 58 61 ((defined(sun) || defined(__sun)) && \ 59 62 (defined(LP64) || defined(_LP64)))) … … 67 70 #endif 68 71 69 70 72 #if defined(_MSC_VER) || defined(__BCPLUSPLUS__) 71 73 #define WORD64_AVAILABLE 72 74 #define W64LIT(x) x##ui64 73 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; 74 80 #elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8 75 81 #define WORD64_AVAILABLE … … 84 90 #define W64LIT(x) x##LL 85 91 typedef unsigned long long word64; 86 #else 87 #define MP_16BIT /* for mp_int, mp_word needs to be twice as big as 88 mp_digit, no 64 bit type so make mp_digit 16 bit */ 89 #endif 90 91 92 #endif 93 94 #if !defined(NO_64BIT) && defined(WORD64_AVAILABLE) 92 95 /* These platforms have 64-bit CPU registers. */ 93 96 #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \ … … 100 103 /* LP64 with GNU GCC compiler is reserved for when long int is 64 bits 101 104 * and int uses 32 bits. When using Solaris Studio sparc and __sparc are 102 * av ialable for 32 bit detection but __sparc64__ could be missed. This105 * available for 32 bit detection but __sparc64__ could be missed. This 103 106 * uses LP64 for checking 64 bit CPU arch. */ 104 107 typedef word64 wolfssl_word; … … 110 113 #endif 111 114 #endif 112 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 113 121 114 122 enum { … … 121 129 122 130 /* use inlining if compiler allows */ 123 #ifndefINLINE131 #ifndef WC_INLINE 124 132 #ifndef NO_INLINE 125 133 #ifdef _MSC_VER 126 #defineINLINE __inline134 #define WC_INLINE __inline 127 135 #elif defined(__GNUC__) 128 136 #ifdef WOLFSSL_VXWORKS 129 #define INLINE __inline__137 #define WC_INLINE __inline__ 130 138 #else 131 #define INLINE inline139 #define WC_INLINE inline 132 140 #endif 133 141 #elif defined(__IAR_SYSTEMS_ICC__) 134 #defineINLINE inline142 #define WC_INLINE inline 135 143 #elif defined(THREADX) 136 #defineINLINE _Inline144 #define WC_INLINE _Inline 137 145 #else 138 #defineINLINE146 #define WC_INLINE 139 147 #endif 140 148 #else 141 #define INLINE 142 #endif 149 #define WC_INLINE 150 #endif 151 #endif 152 153 #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST) 154 #define INLINE WC_INLINE 143 155 #endif 144 156 … … 164 176 #define THREAD_LS_T __declspec(thread) 165 177 /* Thread local storage only in FreeRTOS v8.2.1 and higher */ 166 #elif defined(FREERTOS)178 #elif defined(FREERTOS) || defined(FREERTOS_TCP) 167 179 #define THREAD_LS_T 168 180 #else … … 176 188 #if defined(__GNUC__) 177 189 #if ((__GNUC__ > 7) || ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 1))) 178 #define FALL_THROUGH __attribute__ ((fallthrough)) ;190 #define FALL_THROUGH __attribute__ ((fallthrough)) 179 191 #endif 180 192 #endif … … 194 206 /* default to libc stuff */ 195 207 /* XREALLOC is used once in normal math lib, not in fast math lib */ 196 /* XFREE on some embeded systems doesn't like free(0) so test */208 /* XFREE on some embedded systems doesn't like free(0) so test */ 197 209 #if defined(HAVE_IO_POOL) 198 210 WOLFSSL_API void* XMALLOC(size_t n, void* heap, int type); … … 217 229 extern void *XREALLOC(void *p, size_t n, void* heap, int type); 218 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); 219 245 #elif defined(XMALLOC_OVERRIDE) 220 246 /* override the XMALLOC, XFREE and XREALLOC macros */ … … 228 254 && !defined(WOLFSSL_SAFERTOS) && !defined(FREESCALE_MQX) \ 229 255 && !defined(FREESCALE_KSDK_MQX) && !defined(FREESCALE_FREE_RTOS) \ 230 && !defined(WOLFSSL_LEANPSK) && !defined(FREERTOS) && !defined(FREERTOS_TCP)\ 231 && !defined(WOLFSSL_uITRON4) 256 && !defined(WOLFSSL_LEANPSK) && !defined(WOLFSSL_uITRON4) 232 257 /* default C runtime, can install different routines at runtime via cbs */ 233 258 #include <wolfssl/wolfcrypt/memory.h> … … 242 267 #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), (h), (t)) 243 268 #endif /* WOLFSSL_DEBUG_MEMORY */ 244 #el se269 #elif !defined(FREERTOS) && !defined(FREERTOS_TCP) 245 270 #ifdef WOLFSSL_DEBUG_MEMORY 246 271 #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s), __func__, __LINE__)) … … 258 283 #ifdef WOLFSSL_ASYNC_CRYPT 259 284 #define DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \ 260 VAR_TYPE* VAR_NAME = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, HEAP, DYNAMIC_TYPE_WOLF_BIGINT);285 VAR_TYPE* VAR_NAME = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); 261 286 #define DECLARE_VAR_INIT(VAR_NAME, VAR_TYPE, VAR_SIZE, INIT_VALUE, HEAP) \ 262 287 VAR_TYPE* VAR_NAME = ({ \ 263 VAR_TYPE* ptr = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, HEAP, DYNAMIC_TYPE_WOLF_BIGINT); \288 VAR_TYPE* ptr = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \ 264 289 if (ptr && INIT_VALUE) { \ 265 290 XMEMCPY(ptr, INIT_VALUE, sizeof(VAR_TYPE) * VAR_SIZE); \ … … 271 296 int idx##VAR_NAME; \ 272 297 for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \ 273 VAR_NAME[idx##VAR_NAME] = (VAR_TYPE*)XMALLOC(VAR_SIZE, HEAP, DYNAMIC_TYPE_WOLF_BIGINT); \298 VAR_NAME[idx##VAR_NAME] = (VAR_TYPE*)XMALLOC(VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \ 274 299 } 275 300 #define FREE_VAR(VAR_NAME, HEAP) \ 276 XFREE(VAR_NAME, HEAP, DYNAMIC_TYPE_WOLF_BIGINT);301 XFREE(VAR_NAME, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); 277 302 #define FREE_ARRAY(VAR_NAME, VAR_ITEMS, HEAP) \ 278 303 for (idx##VAR_NAME=0; idx##VAR_NAME<VAR_ITEMS; idx##VAR_NAME++) { \ 279 XFREE(VAR_NAME[idx##VAR_NAME], HEAP, DYNAMIC_TYPE_WOLF_BIGINT); \304 XFREE(VAR_NAME[idx##VAR_NAME], (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \ 280 305 } 281 306 #else … … 290 315 #endif 291 316 292 #ifndef WOLFSSL_LEANPSK 293 char* mystrnstr(const char* s1, const char* s2, unsigned int n); 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 294 324 #endif 295 325 … … 310 340 #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n)) 311 341 312 #ifdef MICROCHIP_PIC32 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) 313 349 /* XC32 does not support strncasecmp, so use case sensitive one */ 314 350 #define XSTRNCASECMP(s1,s2,n) strncmp((s1),(s2),(n)) 315 #elif defined(USE_WINDOWS_API) 351 #elif defined(USE_WINDOWS_API) || defined(FREERTOS_TCP_WINSIM) 316 352 #define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n)) 317 353 #else 354 #if defined(HAVE_STRINGS_H) && defined(WOLF_C99) && \ 355 !defined(WOLFSSL_SGX) 356 #include <strings.h> 357 #endif 318 358 #define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n)) 319 359 #endif 320 360 321 /* snprintf is used in asn.c for GetTimeString and PKCS7 test */ 361 /* snprintf is used in asn.c for GetTimeString, PKCS7 test, and when 362 debugging is turned on */ 322 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 323 370 #define XSNPRINTF snprintf 324 371 #else … … 328 375 #if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN) 329 376 /* use only Thread Safe version of strtok */ 330 #if !defined(USE_WINDOWS_API) && !defined(INTIME_RTOS) 331 #define XSTRTOK strtok_r 332 #elif defined(__MINGW32__) || defined(WOLFSSL_TIRTOS) || \ 333 defined(USE_WOLF_STRTOK) 334 #ifndef USE_WOLF_STRTOK 335 #define USE_WOLF_STRTOK 336 #endif 337 #define XSTRTOK wc_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)) 338 381 #else 339 #define XSTRTOK strtok_s382 #define XSTRTOK(s1,d,ptr) strtok_r((s1),(d),(ptr)) 340 383 #endif 341 384 #endif 342 #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 */ 343 401 344 402 #ifndef CTYPE_USER 345 403 #include <ctype.h> 346 #if defined(HAVE_ECC) || defined(HAVE_OCSP) || defined(WOLFSSL_KEY_GEN) 404 #if defined(HAVE_ECC) || defined(HAVE_OCSP) || \ 405 defined(WOLFSSL_KEY_GEN) || !defined(NO_DSA) 347 406 #define XTOUPPER(c) toupper((c)) 348 407 #define XISALPHA(c) isalpha((c)) … … 438 497 DYNAMIC_TYPE_HASHCTX = 82, 439 498 DYNAMIC_TYPE_SEED = 83, 440 DYNAMIC_TYPE_SYM ETRIC_KEY= 84,499 DYNAMIC_TYPE_SYMMETRIC_KEY= 84, 441 500 DYNAMIC_TYPE_ECC_BUFFER = 85, 442 501 DYNAMIC_TYPE_QSH = 86, 443 502 DYNAMIC_TYPE_SALT = 87, 444 503 DYNAMIC_TYPE_HASH_TMP = 88, 504 DYNAMIC_TYPE_BLOB = 89, 505 DYNAMIC_TYPE_NAME_ENTRY = 90, 445 506 }; 446 507 447 508 /* max error buffer string size */ 448 enum { 449 WOLFSSL_MAX_ERROR_SZ =80450 }; 509 #ifndef WOLFSSL_MAX_ERROR_SZ 510 #define WOLFSSL_MAX_ERROR_SZ 80 511 #endif 451 512 452 513 /* stack protection */ … … 455 516 }; 456 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 }; 457 605 458 606 … … 582 730 #endif 583 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 584 762 #ifdef __cplusplus 585 763 } /* extern "C" */
Note:
See TracChangeset
for help on using the changeset viewer.