types.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* types.h
  2. *
  3. * Copyright (C) 2006-2011 Sawtooth Consulting Ltd.
  4. *
  5. * This file is part of CyaSSL.
  6. *
  7. * CyaSSL 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. * CyaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  20. */
  21. #ifndef CTAO_CRYPT_TYPES_H
  22. #define CTAO_CRYPT_TYPES_H
  23. #include "os_settings.h"
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #if defined(WORDS_BIGENDIAN) || (defined(__MWERKS__) && !defined(__INTEL__))
  31. #define BIG_ENDIAN_ORDER
  32. #endif
  33. #ifndef BIG_ENDIAN_ORDER
  34. #define LITTLE_ENDIAN_ORDER
  35. #endif
  36. #ifndef CYASSL_TYPES
  37. typedef unsigned char byte;
  38. typedef unsigned short word16;
  39. typedef unsigned int word32;
  40. #endif
  41. #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
  42. #define WORD64_AVAILABLE
  43. #define W64LIT(x) x##ui64
  44. typedef unsigned __int64 word64;
  45. #elif SIZEOF_LONG == 8
  46. #define WORD64_AVAILABLE
  47. #define W64LIT(x) x##LL
  48. typedef unsigned long word64;
  49. #elif SIZEOF_LONG_LONG == 8
  50. #define WORD64_AVAILABLE
  51. #define W64LIT(x) x##LL
  52. typedef unsigned long long word64;
  53. #else
  54. #define MP_16BIT /* for mp_int, mp_word needs to be twice as big as
  55. mp_digit, no 64 bit type so make mp_digit 16 bit */
  56. #endif
  57. /* These platforms have 64-bit CPU registers. */
  58. #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
  59. defined(__mips64) || defined(__x86_64__))
  60. typedef word64 word;
  61. #else
  62. typedef word32 word;
  63. #ifdef WORD64_AVAILABLE
  64. #define CTAOCRYPT_SLOW_WORD64
  65. #endif
  66. #endif
  67. enum {
  68. WORD_SIZE = sizeof(word),
  69. BIT_SIZE = 8,
  70. WORD_BITS = WORD_SIZE * BIT_SIZE
  71. };
  72. /* use inlining if compiler allows */
  73. #ifndef INLINE
  74. #ifndef NO_INLINE
  75. #ifdef _MSC_VER
  76. #define INLINE __inline
  77. #elif defined(__GNUC__)
  78. #define INLINE inline
  79. #elif defined(THREADX)
  80. #define INLINE _Inline
  81. #else
  82. #define INLINE
  83. #endif
  84. #else
  85. #define INLINE
  86. #endif
  87. #endif
  88. /* set up rotate style */
  89. #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
  90. #define INTEL_INTRINSICS
  91. #define FAST_ROTATE
  92. #elif defined(__MWERKS__) && TARGET_CPU_PPC
  93. #define PPC_INTRINSICS
  94. #define FAST_ROTATE
  95. #elif defined(__GNUC__) && defined(__i386__)
  96. /* GCC does peephole optimizations which should result in using rotate
  97. instructions */
  98. #define FAST_ROTATE
  99. #endif
  100. /* Micrium will use Visual Studio for compilation but not the Win32 API */
  101. #if defined(_WIN32) && !defined(MICRIUM)
  102. #define USE_WINDOWS_API
  103. #endif
  104. /* idea to add global alloc override by Moisés Guimarães */
  105. /* default to libc stuff */
  106. /* XREALLOC is used once in mormal math lib, not in fast math lib */
  107. /* XFREE on some embeded systems doesn't like free(0) so test */
  108. #ifdef XMALLOC_USER
  109. /* prototypes for user heap override functions */
  110. #include <stddef.h> /* for size_t */
  111. extern void *XMALLOC(size_t n, void* heap, int type);
  112. extern void *XREALLOC(void *p, size_t n, void* heap, int type);
  113. extern void XFREE(void *p, void* heap, int type);
  114. #elif !defined(MICRIUM_MALLOC)
  115. /* defaults to C runtime if user doesn't override and not Micrium */
  116. #include <stdlib.h>
  117. #define XMALLOC(s, h, t) malloc((s))
  118. #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
  119. #define XREALLOC(p, n, h, t) realloc((p), (n))
  120. #endif
  121. #ifndef STRING_USER
  122. #include <string.h>
  123. #define XMEMCPY(d,s,l) memcpy((d),(s),(l))
  124. #define XMEMSET(b,c,l) memset((b),(c),(l))
  125. #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
  126. #define XMEMMOVE(d,s,l) memmove((d),(s),(l))
  127. #define XSTRLEN(s1) strlen((s1))
  128. #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
  129. /* strstr and strncmp only used by CyaSSL proper, not required for
  130. CTaoCrypt only */
  131. #define XSTRSTR(s1,s2) strstr((s1),(s2))
  132. #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
  133. #endif
  134. #ifdef HAVE_ECC
  135. #ifndef CTYPE_USER
  136. #include <ctype.h>
  137. #define XTOUPPER(c) toupper((c))
  138. #endif
  139. #endif
  140. /* memory allocation types for user hints */
  141. enum {
  142. DYNAMIC_TYPE_CA = 1,
  143. DYNAMIC_TYPE_CERT = 2,
  144. DYNAMIC_TYPE_KEY = 3,
  145. DYNAMIC_TYPE_FILE = 4,
  146. DYNAMIC_TYPE_ISSUER_CN = 5,
  147. DYNAMIC_TYPE_PUBLIC_KEY = 6,
  148. DYNAMIC_TYPE_SIGNER = 7,
  149. DYNAMIC_TYPE_NONE = 8,
  150. DYNAMIC_TYPE_BIGINT = 9,
  151. DYNAMIC_TYPE_RSA = 10,
  152. DYNAMIC_TYPE_METHOD = 11,
  153. DYNAMIC_TYPE_OUT_BUFFER = 12,
  154. DYNAMIC_TYPE_IN_BUFFER = 13,
  155. DYNAMIC_TYPE_INFO = 14,
  156. DYNAMIC_TYPE_DH = 15,
  157. DYNAMIC_TYPE_DOMAIN = 16,
  158. DYNAMIC_TYPE_SSL = 17,
  159. DYNAMIC_TYPE_CTX = 18,
  160. DYNAMIC_TYPE_WRITEV = 19,
  161. DYNAMIC_TYPE_OPENSSL = 20
  162. };
  163. #ifdef __cplusplus
  164. } /* extern "C" */
  165. #endif
  166. #endif /* CTAO_CRYPT_TYPES_H */