source: UsbWattMeter/trunk/wolfssl-3.7.0/wolfssl/wolfcrypt/types.h@ 164

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

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr
File size: 11.1 KB
RevLine 
[164]1/* types.h
2 *
3 * Copyright (C) 2006-2015 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL. (formerly known as CyaSSL)
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-1301, USA
20 */
21
22
23#ifndef WOLF_CRYPT_TYPES_H
24#define WOLF_CRYPT_TYPES_H
25
26 #include <wolfssl/wolfcrypt/settings.h>
27 #include <wolfssl/wolfcrypt/wc_port.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33
34 #if defined(WORDS_BIGENDIAN)
35 #define BIG_ENDIAN_ORDER
36 #endif
37
38 #ifndef BIG_ENDIAN_ORDER
39 #define LITTLE_ENDIAN_ORDER
40 #endif
41
42 #ifndef WOLFSSL_TYPES
43 #ifndef byte
44 typedef unsigned char byte;
45 #endif
46 typedef unsigned short word16;
47 typedef unsigned int word32;
48 #endif
49
50
51 /* try to set SIZEOF_LONG or LONG_LONG if user didn't */
52 #if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__)
53 #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG)
54 #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) \
55 || defined(__mips64) || defined(__x86_64__))
56 /* long should be 64bit */
57 #define SIZEOF_LONG 8
58 #elif defined(__i386__) || defined(__CORTEX_M3__)
59 /* long long should be 64bit */
60 #define SIZEOF_LONG_LONG 8
61 #endif
62 #endif
63 #endif
64
65
66 #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
67 #define WORD64_AVAILABLE
68 #define W64LIT(x) x##ui64
69 typedef unsigned __int64 word64;
70 #elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8
71 #define WORD64_AVAILABLE
72 #define W64LIT(x) x##LL
73 typedef unsigned 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 #elif defined(__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 8
79 #define WORD64_AVAILABLE
80 #define W64LIT(x) x##LL
81 typedef unsigned long long word64;
82 #else
83 #define MP_16BIT /* for mp_int, mp_word needs to be twice as big as
84 mp_digit, no 64 bit type so make mp_digit 16 bit */
85 #endif
86
87
88 /* These platforms have 64-bit CPU registers. */
89 #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
90 defined(__mips64) || defined(__x86_64__) || defined(_M_X64))
91 typedef word64 wolfssl_word;
92 #else
93 typedef word32 wolfssl_word;
94 #ifdef WORD64_AVAILABLE
95 #define WOLFCRYPT_SLOW_WORD64
96 #endif
97 #endif
98
99
100 enum {
101 WOLFSSL_WORD_SIZE = sizeof(wolfssl_word),
102 WOLFSSL_BIT_SIZE = 8,
103 WOLFSSL_WORD_BITS = WOLFSSL_WORD_SIZE * WOLFSSL_BIT_SIZE
104 };
105
106 #define WOLFSSL_MAX_16BIT 0xffffU
107
108 /* use inlining if compiler allows */
109 #ifndef INLINE
110 #ifndef NO_INLINE
111 #ifdef _MSC_VER
112 #define INLINE __inline
113 #elif defined(__GNUC__)
114 #ifdef WOLFSSL_VXWORKS
115 #define INLINE __inline__
116 #else
117 #define INLINE inline
118 #endif
119 #elif defined(__IAR_SYSTEMS_ICC__)
120 #define INLINE inline
121 #elif defined(THREADX)
122 #define INLINE _Inline
123 #else
124 #define INLINE
125 #endif
126 #else
127 #define INLINE
128 #endif
129 #endif
130
131
132 /* set up rotate style */
133 #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
134 #define INTEL_INTRINSICS
135 #define FAST_ROTATE
136 #elif defined(__MWERKS__) && TARGET_CPU_PPC
137 #define PPC_INTRINSICS
138 #define FAST_ROTATE
139 #elif defined(__GNUC__) && defined(__i386__)
140 /* GCC does peephole optimizations which should result in using rotate
141 instructions */
142 #define FAST_ROTATE
143 #endif
144
145
146 /* set up thread local storage if available */
147 #ifdef HAVE_THREAD_LS
148 #if defined(_MSC_VER)
149 #define THREAD_LS_T __declspec(thread)
150 /* Thread local storage only in FreeRTOS v8.2.1 and higher */
151 #elif defined(FREERTOS)
152 #define THREAD_LS_T
153 #else
154 #define THREAD_LS_T __thread
155 #endif
156 #else
157 #define THREAD_LS_T
158 #endif
159
160
161 /* Micrium will use Visual Studio for compilation but not the Win32 API */
162 #if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && !defined(FREERTOS_TCP) \
163 && !defined(EBSNET) && !defined(WOLFSSL_uITRON4)
164 #define USE_WINDOWS_API
165 #endif
166
167
168 /* idea to add global alloc override by Moises Guimaraes */
169 /* default to libc stuff */
170 /* XREALLOC is used once in normal math lib, not in fast math lib */
171 /* XFREE on some embeded systems doesn't like free(0) so test */
172 #if defined(XMALLOC_USER)
173 /* prototypes for user heap override functions */
174 #include <stddef.h> /* for size_t */
175 //extern void *XMALLOC(size_t n, void* heap, int type);
176 //extern void *XREALLOC(void *p, size_t n, void* heap, int type);
177 //extern void XFREE(void *p, void* heap, int type);
178 #elif defined(NO_WOLFSSL_MEMORY)
179 /* just use plain C stdlib stuff if desired */
180 #include <stdlib.h>
181 #define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s)))
182 #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
183 #define XREALLOC(p, n, h, t) realloc((p), (n))
184 #elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) \
185 && !defined(WOLFSSL_SAFERTOS) && !defined(FREESCALE_MQX) \
186 && !defined(FREESCALE_KSDK_MQX) && !defined(FREESCALE_FREE_RTOS) \
187 && !defined(WOLFSSL_LEANPSK) && !defined(FREERTOS) && !defined(FREERTOS_TCP)\
188 && !defined(WOLFSSL_uITRON4) && !defined(WOLFSSL_uTKERNEL2)
189 /* default C runtime, can install different routines at runtime via cbs */
190 #include <wolfssl/wolfcrypt/memory.h>
191 #define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s)))
192 #define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));}
193 #define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))
194 #endif
195
196 #ifndef STRING_USER
197 #include <string.h>
198 char* mystrnstr(const char* s1, const char* s2, unsigned int n);
199
200 #define XMEMCPY(d,s,l) memcpy((d),(s),(l))
201 #define XMEMSET(b,c,l) memset((b),(c),(l))
202 #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
203 #define XMEMMOVE(d,s,l) memmove((d),(s),(l))
204
205 #define XSTRLEN(s1) strlen((s1))
206 #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
207 /* strstr, strncmp, and strncat only used by wolfSSL proper,
208 * not required for wolfCrypt only */
209 #define XSTRSTR(s1,s2) strstr((s1),(s2))
210 #define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n))
211 #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
212 #define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
213 #ifndef USE_WINDOWS_API
214 #define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
215 #else
216 #define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
217 #endif
218
219 #if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
220 /* use only Thread Safe version of strtok */
221 #ifndef USE_WINDOWS_API
222 #define XSTRTOK strtok_r
223 #else
224 #define XSTRTOK strtok_s
225 #endif
226 #endif
227 #endif
228
229 #ifndef CTYPE_USER
230 #include <ctype.h>
231 #if defined(HAVE_ECC) || defined(HAVE_OCSP) || defined(WOLFSSL_KEY_GEN)
232 #define XTOUPPER(c) toupper((c))
233 #define XISALPHA(c) isalpha((c))
234 #endif
235 /* needed by wolfSSL_check_domain_name() */
236 #define XTOLOWER(c) tolower((c))
237 #endif
238
239
240 /* memory allocation types for user hints */
241 enum {
242 DYNAMIC_TYPE_CA = 1,
243 DYNAMIC_TYPE_CERT = 2,
244 DYNAMIC_TYPE_KEY = 3,
245 DYNAMIC_TYPE_FILE = 4,
246 DYNAMIC_TYPE_SUBJECT_CN = 5,
247 DYNAMIC_TYPE_PUBLIC_KEY = 6,
248 DYNAMIC_TYPE_SIGNER = 7,
249 DYNAMIC_TYPE_NONE = 8,
250 DYNAMIC_TYPE_BIGINT = 9,
251 DYNAMIC_TYPE_RSA = 10,
252 DYNAMIC_TYPE_METHOD = 11,
253 DYNAMIC_TYPE_OUT_BUFFER = 12,
254 DYNAMIC_TYPE_IN_BUFFER = 13,
255 DYNAMIC_TYPE_INFO = 14,
256 DYNAMIC_TYPE_DH = 15,
257 DYNAMIC_TYPE_DOMAIN = 16,
258 DYNAMIC_TYPE_SSL = 17,
259 DYNAMIC_TYPE_CTX = 18,
260 DYNAMIC_TYPE_WRITEV = 19,
261 DYNAMIC_TYPE_OPENSSL = 20,
262 DYNAMIC_TYPE_DSA = 21,
263 DYNAMIC_TYPE_CRL = 22,
264 DYNAMIC_TYPE_REVOKED = 23,
265 DYNAMIC_TYPE_CRL_ENTRY = 24,
266 DYNAMIC_TYPE_CERT_MANAGER = 25,
267 DYNAMIC_TYPE_CRL_MONITOR = 26,
268 DYNAMIC_TYPE_OCSP_STATUS = 27,
269 DYNAMIC_TYPE_OCSP_ENTRY = 28,
270 DYNAMIC_TYPE_ALTNAME = 29,
271 DYNAMIC_TYPE_SUITES = 30,
272 DYNAMIC_TYPE_CIPHER = 31,
273 DYNAMIC_TYPE_RNG = 32,
274 DYNAMIC_TYPE_ARRAYS = 33,
275 DYNAMIC_TYPE_DTLS_POOL = 34,
276 DYNAMIC_TYPE_SOCKADDR = 35,
277 DYNAMIC_TYPE_LIBZ = 36,
278 DYNAMIC_TYPE_ECC = 37,
279 DYNAMIC_TYPE_TMP_BUFFER = 38,
280 DYNAMIC_TYPE_DTLS_MSG = 39,
281 DYNAMIC_TYPE_CAVIUM_TMP = 40,
282 DYNAMIC_TYPE_CAVIUM_RSA = 41,
283 DYNAMIC_TYPE_X509 = 42,
284 DYNAMIC_TYPE_TLSX = 43,
285 DYNAMIC_TYPE_OCSP = 44,
286 DYNAMIC_TYPE_SIGNATURE = 45,
287 DYNAMIC_TYPE_HASHES = 46,
288 DYNAMIC_TYPE_SRP = 47,
289 DYNAMIC_TYPE_COOKIE_PWD = 48,
290 DYNAMIC_TYPE_USER_CRYPTO = 49
291 };
292
293 /* max error buffer string size */
294 enum {
295 WOLFSSL_MAX_ERROR_SZ = 80
296 };
297
298 /* stack protection */
299 enum {
300 MIN_STACK_BUFFER = 8
301 };
302
303
304
305 /* settings detection for compile vs runtime math incombatibilities */
306 enum {
307 #if !defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
308 CTC_SETTINGS = 0x0
309 #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
310 CTC_SETTINGS = 0x1
311 #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
312 CTC_SETTINGS = 0x2
313 #elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
314 CTC_SETTINGS = 0x4
315 #elif defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
316 CTC_SETTINGS = 0x8
317 #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
318 CTC_SETTINGS = 0x10
319 #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
320 CTC_SETTINGS = 0x20
321 #elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
322 CTC_SETTINGS = 0x40
323 #else
324 #error "bad math long / long long settings"
325 #endif
326 };
327
328
329 WOLFSSL_API word32 CheckRunTimeSettings(void);
330
331 /* If user uses RSA, DH, DSA, or ECC math lib directly then fast math and long
332 types need to match at compile time and run time, CheckCtcSettings will
333 return 1 if a match otherwise 0 */
334 #define CheckCtcSettings() (CTC_SETTINGS == CheckRunTimeSettings())
335
336
337 #ifdef __cplusplus
338 } /* extern "C" */
339 #endif
340
341#endif /* WOLF_CRYPT_TYPES_H */
Note: See TracBrowser for help on using the repository browser.