cya_u
Fork of CyaSSL-forEncrypt by
types.h@0:5045d2638c29, 2011-02-05 (annotated)
- Committer:
- toddouska
- Date:
- Sat Feb 05 01:09:17 2011 +0000
- Revision:
- 0:5045d2638c29
Beta Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
toddouska | 0:5045d2638c29 | 1 | /* types.h |
toddouska | 0:5045d2638c29 | 2 | * |
toddouska | 0:5045d2638c29 | 3 | * Copyright (C) 2006-2009 Sawtooth Consulting Ltd. |
toddouska | 0:5045d2638c29 | 4 | * |
toddouska | 0:5045d2638c29 | 5 | * This file is part of CyaSSL. |
toddouska | 0:5045d2638c29 | 6 | * |
toddouska | 0:5045d2638c29 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
toddouska | 0:5045d2638c29 | 8 | * it under the terms of the GNU General Public License as published by |
toddouska | 0:5045d2638c29 | 9 | * the Free Software Foundation; either version 2 of the License, or |
toddouska | 0:5045d2638c29 | 10 | * (at your option) any later version. |
toddouska | 0:5045d2638c29 | 11 | * |
toddouska | 0:5045d2638c29 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
toddouska | 0:5045d2638c29 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
toddouska | 0:5045d2638c29 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
toddouska | 0:5045d2638c29 | 15 | * GNU General Public License for more details. |
toddouska | 0:5045d2638c29 | 16 | * |
toddouska | 0:5045d2638c29 | 17 | * You should have received a copy of the GNU General Public License |
toddouska | 0:5045d2638c29 | 18 | * along with this program; if not, write to the Free Software |
toddouska | 0:5045d2638c29 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
toddouska | 0:5045d2638c29 | 20 | */ |
toddouska | 0:5045d2638c29 | 21 | |
toddouska | 0:5045d2638c29 | 22 | |
toddouska | 0:5045d2638c29 | 23 | #ifndef CTAO_CRYPT_TYPES_H |
toddouska | 0:5045d2638c29 | 24 | #define CTAO_CRYPT_TYPES_H |
toddouska | 0:5045d2638c29 | 25 | |
toddouska | 0:5045d2638c29 | 26 | #include "os_settings.h" |
toddouska | 0:5045d2638c29 | 27 | |
toddouska | 0:5045d2638c29 | 28 | #ifdef HAVE_CONFIG_H |
toddouska | 0:5045d2638c29 | 29 | #include "config.h" |
toddouska | 0:5045d2638c29 | 30 | #endif |
toddouska | 0:5045d2638c29 | 31 | |
toddouska | 0:5045d2638c29 | 32 | #ifdef __cplusplus |
toddouska | 0:5045d2638c29 | 33 | extern "C" { |
toddouska | 0:5045d2638c29 | 34 | #endif |
toddouska | 0:5045d2638c29 | 35 | |
toddouska | 0:5045d2638c29 | 36 | |
toddouska | 0:5045d2638c29 | 37 | #if defined(WORDS_BIGENDIAN) || (defined(__MWERKS__) && !defined(__INTEL__)) |
toddouska | 0:5045d2638c29 | 38 | #define BIG_ENDIAN_ORDER |
toddouska | 0:5045d2638c29 | 39 | #endif |
toddouska | 0:5045d2638c29 | 40 | |
toddouska | 0:5045d2638c29 | 41 | #ifndef BIG_ENDIAN_ORDER |
toddouska | 0:5045d2638c29 | 42 | #define LITTLE_ENDIAN_ORDER |
toddouska | 0:5045d2638c29 | 43 | #endif |
toddouska | 0:5045d2638c29 | 44 | |
toddouska | 0:5045d2638c29 | 45 | #ifndef CYASSL_TYPES |
toddouska | 0:5045d2638c29 | 46 | typedef unsigned char byte; |
toddouska | 0:5045d2638c29 | 47 | typedef unsigned short word16; |
toddouska | 0:5045d2638c29 | 48 | typedef unsigned int word32; |
toddouska | 0:5045d2638c29 | 49 | #endif |
toddouska | 0:5045d2638c29 | 50 | |
toddouska | 0:5045d2638c29 | 51 | #if defined(_MSC_VER) || defined(__BCPLUSPLUS__) |
toddouska | 0:5045d2638c29 | 52 | #define WORD64_AVAILABLE |
toddouska | 0:5045d2638c29 | 53 | #define W64LIT(x) x##ui64 |
toddouska | 0:5045d2638c29 | 54 | typedef unsigned __int64 word64; |
toddouska | 0:5045d2638c29 | 55 | #elif SIZEOF_LONG == 8 |
toddouska | 0:5045d2638c29 | 56 | #define WORD64_AVAILABLE |
toddouska | 0:5045d2638c29 | 57 | #define W64LIT(x) x##LL |
toddouska | 0:5045d2638c29 | 58 | typedef unsigned long word64; |
toddouska | 0:5045d2638c29 | 59 | #elif SIZEOF_LONG_LONG == 8 |
toddouska | 0:5045d2638c29 | 60 | #define WORD64_AVAILABLE |
toddouska | 0:5045d2638c29 | 61 | #define W64LIT(x) x##LL |
toddouska | 0:5045d2638c29 | 62 | typedef unsigned long long word64; |
toddouska | 0:5045d2638c29 | 63 | #else |
toddouska | 0:5045d2638c29 | 64 | #define MP_16BIT /* for mp_int, mp_word needs to be twice as big as |
toddouska | 0:5045d2638c29 | 65 | mp_digit, no 64 bit type so make mp_digit 16 bit */ |
toddouska | 0:5045d2638c29 | 66 | #endif |
toddouska | 0:5045d2638c29 | 67 | |
toddouska | 0:5045d2638c29 | 68 | |
toddouska | 0:5045d2638c29 | 69 | /* These platforms have 64-bit CPU registers. */ |
toddouska | 0:5045d2638c29 | 70 | #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \ |
toddouska | 0:5045d2638c29 | 71 | defined(__mips64) || defined(__x86_64__)) |
toddouska | 0:5045d2638c29 | 72 | typedef word64 word; |
toddouska | 0:5045d2638c29 | 73 | #else |
toddouska | 0:5045d2638c29 | 74 | typedef word32 word; |
toddouska | 0:5045d2638c29 | 75 | #ifdef WORD64_AVAILABLE |
toddouska | 0:5045d2638c29 | 76 | #define CTAOCRYPT_SLOW_WORD64 |
toddouska | 0:5045d2638c29 | 77 | #endif |
toddouska | 0:5045d2638c29 | 78 | #endif |
toddouska | 0:5045d2638c29 | 79 | |
toddouska | 0:5045d2638c29 | 80 | |
toddouska | 0:5045d2638c29 | 81 | enum { |
toddouska | 0:5045d2638c29 | 82 | WORD_SIZE = sizeof(word), |
toddouska | 0:5045d2638c29 | 83 | BIT_SIZE = 8, |
toddouska | 0:5045d2638c29 | 84 | WORD_BITS = WORD_SIZE * BIT_SIZE |
toddouska | 0:5045d2638c29 | 85 | }; |
toddouska | 0:5045d2638c29 | 86 | |
toddouska | 0:5045d2638c29 | 87 | |
toddouska | 0:5045d2638c29 | 88 | /* use inlining if compiler allows */ |
toddouska | 0:5045d2638c29 | 89 | #ifndef INLINE |
toddouska | 0:5045d2638c29 | 90 | #ifndef NO_INLINE |
toddouska | 0:5045d2638c29 | 91 | #ifdef _MSC_VER |
toddouska | 0:5045d2638c29 | 92 | #define INLINE __inline |
toddouska | 0:5045d2638c29 | 93 | #elif defined(__GNUC__) |
toddouska | 0:5045d2638c29 | 94 | #define INLINE inline |
toddouska | 0:5045d2638c29 | 95 | #elif defined(THREADX) |
toddouska | 0:5045d2638c29 | 96 | #define INLINE _Inline |
toddouska | 0:5045d2638c29 | 97 | #else |
toddouska | 0:5045d2638c29 | 98 | #define INLINE |
toddouska | 0:5045d2638c29 | 99 | #endif |
toddouska | 0:5045d2638c29 | 100 | #else |
toddouska | 0:5045d2638c29 | 101 | #define INLINE |
toddouska | 0:5045d2638c29 | 102 | #endif |
toddouska | 0:5045d2638c29 | 103 | #endif |
toddouska | 0:5045d2638c29 | 104 | |
toddouska | 0:5045d2638c29 | 105 | |
toddouska | 0:5045d2638c29 | 106 | /* set up rotate style */ |
toddouska | 0:5045d2638c29 | 107 | #if defined(_MSC_VER) || defined(__BCPLUSPLUS__) |
toddouska | 0:5045d2638c29 | 108 | #define INTEL_INTRINSICS |
toddouska | 0:5045d2638c29 | 109 | #define FAST_ROTATE |
toddouska | 0:5045d2638c29 | 110 | #elif defined(__MWERKS__) && TARGET_CPU_PPC |
toddouska | 0:5045d2638c29 | 111 | #define PPC_INTRINSICS |
toddouska | 0:5045d2638c29 | 112 | #define FAST_ROTATE |
toddouska | 0:5045d2638c29 | 113 | #elif defined(__GNUC__) && defined(__i386__) |
toddouska | 0:5045d2638c29 | 114 | /* GCC does peephole optimizations which should result in using rotate |
toddouska | 0:5045d2638c29 | 115 | instructions */ |
toddouska | 0:5045d2638c29 | 116 | #define FAST_ROTATE |
toddouska | 0:5045d2638c29 | 117 | #endif |
toddouska | 0:5045d2638c29 | 118 | |
toddouska | 0:5045d2638c29 | 119 | |
toddouska | 0:5045d2638c29 | 120 | /* Micrium will use Visual Studio for compilation but not the Win32 API */ |
toddouska | 0:5045d2638c29 | 121 | #if defined(_WIN32) && !defined(MICRIUM) |
toddouska | 0:5045d2638c29 | 122 | #define USE_WINDOWS_API |
toddouska | 0:5045d2638c29 | 123 | #endif |
toddouska | 0:5045d2638c29 | 124 | |
toddouska | 0:5045d2638c29 | 125 | |
toddouska | 0:5045d2638c29 | 126 | /* idea to add global alloc override by Moisés Guimarães */ |
toddouska | 0:5045d2638c29 | 127 | /* default to libc stuff */ |
toddouska | 0:5045d2638c29 | 128 | /* XREALLOC is used once in mormal math lib, not in fast math lib */ |
toddouska | 0:5045d2638c29 | 129 | /* XFREE on some embeded systems doesn't like free(0) so test */ |
toddouska | 0:5045d2638c29 | 130 | #ifdef XMALLOC_USER |
toddouska | 0:5045d2638c29 | 131 | /* prototypes for user heap override functions */ |
toddouska | 0:5045d2638c29 | 132 | #include <stddef.h> /* for size_t */ |
toddouska | 0:5045d2638c29 | 133 | extern void *XMALLOC(size_t n, void* heap, int type); |
toddouska | 0:5045d2638c29 | 134 | extern void *XREALLOC(void *p, size_t n, void* heap, int type); |
toddouska | 0:5045d2638c29 | 135 | extern void XFREE(void *p, void* heap, int type); |
toddouska | 0:5045d2638c29 | 136 | #elif !defined(MICRIUM_MALLOC) |
toddouska | 0:5045d2638c29 | 137 | /* defaults to C runtime if user doesn't override and not Micrium */ |
toddouska | 0:5045d2638c29 | 138 | #include <stdlib.h> |
toddouska | 0:5045d2638c29 | 139 | #define XMALLOC(s, h, t) malloc((s)) |
toddouska | 0:5045d2638c29 | 140 | #define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));} |
toddouska | 0:5045d2638c29 | 141 | #define XREALLOC(p, n, h, t) realloc((p), (n)) |
toddouska | 0:5045d2638c29 | 142 | #endif |
toddouska | 0:5045d2638c29 | 143 | |
toddouska | 0:5045d2638c29 | 144 | #ifndef STRING_USER |
toddouska | 0:5045d2638c29 | 145 | #include <string.h> |
toddouska | 0:5045d2638c29 | 146 | #define XMEMCPY(d,s,l) memcpy((d),(s),(l)) |
toddouska | 0:5045d2638c29 | 147 | #define XMEMSET(b,c,l) memset((b),(c),(l)) |
toddouska | 0:5045d2638c29 | 148 | #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n)) |
toddouska | 0:5045d2638c29 | 149 | #define XMEMMOVE(d,s,l) memmove((d),(s),(l)) |
toddouska | 0:5045d2638c29 | 150 | |
toddouska | 0:5045d2638c29 | 151 | #define XSTRLEN(s1) strlen((s1)) |
toddouska | 0:5045d2638c29 | 152 | #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n)) |
toddouska | 0:5045d2638c29 | 153 | /* strstr and strncmp only used by CyaSSL proper, not required for |
toddouska | 0:5045d2638c29 | 154 | CTaoCrypt only */ |
toddouska | 0:5045d2638c29 | 155 | #define XSTRSTR(s1,s2) strstr((s1),(s2)) |
toddouska | 0:5045d2638c29 | 156 | #define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n)) |
toddouska | 0:5045d2638c29 | 157 | #endif |
toddouska | 0:5045d2638c29 | 158 | |
toddouska | 0:5045d2638c29 | 159 | |
toddouska | 0:5045d2638c29 | 160 | /* memory allocation types for user hints */ |
toddouska | 0:5045d2638c29 | 161 | enum { |
toddouska | 0:5045d2638c29 | 162 | DYNAMIC_TYPE_CA = 1, |
toddouska | 0:5045d2638c29 | 163 | DYNAMIC_TYPE_CERT = 2, |
toddouska | 0:5045d2638c29 | 164 | DYNAMIC_TYPE_KEY = 3, |
toddouska | 0:5045d2638c29 | 165 | DYNAMIC_TYPE_FILE = 4, |
toddouska | 0:5045d2638c29 | 166 | DYNAMIC_TYPE_ISSUER_CN = 5, |
toddouska | 0:5045d2638c29 | 167 | DYNAMIC_TYPE_PUBLIC_KEY = 6, |
toddouska | 0:5045d2638c29 | 168 | DYNAMIC_TYPE_SIGNER = 7, |
toddouska | 0:5045d2638c29 | 169 | DYNAMIC_TYPE_NONE = 8, |
toddouska | 0:5045d2638c29 | 170 | DYNAMIC_TYPE_BIGINT = 9, |
toddouska | 0:5045d2638c29 | 171 | DYNAMIC_TYPE_RSA = 10, |
toddouska | 0:5045d2638c29 | 172 | DYNAMIC_TYPE_METHOD = 11, |
toddouska | 0:5045d2638c29 | 173 | DYNAMIC_TYPE_OUT_BUFFER = 12, |
toddouska | 0:5045d2638c29 | 174 | DYNAMIC_TYPE_IN_BUFFER = 13, |
toddouska | 0:5045d2638c29 | 175 | DYNAMIC_TYPE_INFO = 14, |
toddouska | 0:5045d2638c29 | 176 | DYNAMIC_TYPE_DH = 15, |
toddouska | 0:5045d2638c29 | 177 | DYNAMIC_TYPE_DOMAIN = 16, |
toddouska | 0:5045d2638c29 | 178 | DYNAMIC_TYPE_SSL = 17, |
toddouska | 0:5045d2638c29 | 179 | DYNAMIC_TYPE_CTX = 18, |
toddouska | 0:5045d2638c29 | 180 | DYNAMIC_TYPE_WRITEV = 19, |
toddouska | 0:5045d2638c29 | 181 | DYNAMIC_TYPE_OPENSSL = 20 |
toddouska | 0:5045d2638c29 | 182 | }; |
toddouska | 0:5045d2638c29 | 183 | |
toddouska | 0:5045d2638c29 | 184 | |
toddouska | 0:5045d2638c29 | 185 | #ifdef __cplusplus |
toddouska | 0:5045d2638c29 | 186 | } /* extern "C" */ |
toddouska | 0:5045d2638c29 | 187 | #endif |
toddouska | 0:5045d2638c29 | 188 | |
toddouska | 0:5045d2638c29 | 189 | |
toddouska | 0:5045d2638c29 | 190 | #endif /* CTAO_CRYPT_TYPES_H */ |
toddouska | 0:5045d2638c29 | 191 |