1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
10 /* This is the build config file.
12 * With this you can setup what to inlcude/exclude automatically during any
13 * build. Just comment out the line that #define's the word for the thing you
14 * want to remove. phew!
17 #ifndef TOMCRYPT_CFG_H
18 #define TOMCRYPT_CFG_H
20 #if defined(_WIN32) || defined(_MSC_VER)
21 #define LTC_CALL __cdecl
22 #elif !defined(LTC_CALL)
30 /* certain platforms use macros for these, making the prototypes broken */
31 #ifndef LTC_NO_PROTOTYPES
33 /* you can change how memory allocation works ... */
34 LTC_EXPORT void * LTC_CALL XMALLOC(size_t n);
35 LTC_EXPORT void * LTC_CALL XREALLOC(void *p, size_t n);
36 LTC_EXPORT void * LTC_CALL XCALLOC(size_t n, size_t s);
37 LTC_EXPORT void LTC_CALL XFREE(void *p);
39 LTC_EXPORT void LTC_CALL XQSORT(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
42 /* change the clock function too */
43 LTC_EXPORT clock_t LTC_CALL XCLOCK(void);
45 /* various other functions */
46 LTC_EXPORT void * LTC_CALL XMEMCPY(void *dest, const void *src, size_t n);
47 LTC_EXPORT int LTC_CALL XMEMCMP(const void *s1, const void *s2, size_t n);
48 LTC_EXPORT void * LTC_CALL XMEMSET(void *s, int c, size_t n);
50 LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
54 /* some compilers do not like "inline" (or maybe "static inline"), namely: HP
56 #if defined(__HP_cc) || defined(__xlc__)
58 #elif defined(_MSC_VER)
59 #define LTC_INLINE __inline
61 #define LTC_INLINE inline
64 /* type of argument checking, 0=default, 1=fatal and 2=error+continue, 3=nothing */
74 /* Controls endianess and size of registers. Leave uncommented to get platform neutral [slower] code
76 * Note: in order to use the optimized macros your platform must support unaligned 32 and 64 bit read/writes.
77 * The x86 platforms allow this but some others [ARM for instance] do not. On those platforms you **MUST**
78 * use the portable [slower] macros.
80 /* detect x86/i386 32bit */
81 #if defined(__i386__) || defined(__i386) || defined(_M_IX86)
83 #define ENDIAN_32BITWORD
87 /* detect amd64/x64 */
88 #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64)
90 #define ENDIAN_64BITWORD
95 #if defined(LTC_PPC32)
97 #define ENDIAN_32BITWORD
101 /* detects MIPS R5900 processors (PS2) */
102 #if (defined(__R5900) || defined(R5900) || defined(__R5900__)) && (defined(_mips) || defined(__mips__) || defined(mips))
103 #define ENDIAN_64BITWORD
104 #if defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
107 #define ENDIAN_LITTLE
112 #if defined(_AIX) && defined(_BIG_ENDIAN)
114 #if defined(__LP64__) || defined(_ARCH_PPC64)
115 #define ENDIAN_64BITWORD
117 #define ENDIAN_32BITWORD
122 #if defined(__hpux) || defined(__hpux__)
124 #if defined(__ia64) || defined(__ia64__) || defined(__LP64__)
125 #define ENDIAN_64BITWORD
127 #define ENDIAN_32BITWORD
131 /* detect Apple OS X */
132 #if defined(__APPLE__) && defined(__MACH__)
133 #if defined(__LITTLE_ENDIAN__) || defined(__x86_64__)
134 #define ENDIAN_LITTLE
138 #if defined(__LP64__) || defined(__x86_64__)
139 #define ENDIAN_64BITWORD
141 #define ENDIAN_32BITWORD
145 /* detect SPARC and SPARC64 */
146 #if defined(__sparc__) || defined(__sparc)
148 #if defined(__arch64__) || defined(__sparcv9) || defined(__sparc_v9__)
149 #define ENDIAN_64BITWORD
151 #define ENDIAN_32BITWORD
155 /* detect IBM S390(x) */
156 #if defined(__s390x__) || defined(__s390__)
158 #if defined(__s390x__)
159 #define ENDIAN_64BITWORD
161 #define ENDIAN_32BITWORD
166 #if defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__)
167 #define ENDIAN_64BITWORD
168 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
170 #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
171 #define ENDIAN_LITTLE
176 /* endianness fallback */
177 #if !defined(ENDIAN_BIG) && !defined(ENDIAN_LITTLE)
178 #if defined(_BYTE_ORDER) && _BYTE_ORDER == _BIG_ENDIAN || \
179 defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \
180 defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ || \
181 defined(__BIG_ENDIAN__) || \
182 defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
183 defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
185 #elif defined(_BYTE_ORDER) && _BYTE_ORDER == _LITTLE_ENDIAN || \
186 defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \
187 defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ || \
188 defined(__LITTLE_ENDIAN__) || \
189 defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
190 defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
191 #define ENDIAN_LITTLE
193 #error Cannot detect endianness
197 /* ulong64: 64-bit data type */
199 #define CONST64(n) n ## ui64
200 typedef unsigned __int64 ulong64;
202 #define CONST64(n) n ## ULL
203 typedef unsigned long long ulong64;
206 /* ulong32: "32-bit at least" data type */
207 #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) || \
208 defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || \
209 defined(__s390x__) || defined(__arch64__) || defined(__aarch64__) || \
210 defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \
211 defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \
212 defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
213 typedef unsigned ulong32;
214 #if !defined(ENDIAN_64BITWORD) && !defined(ENDIAN_32BITWORD)
215 #define ENDIAN_64BITWORD
218 typedef unsigned long ulong32;
219 #if !defined(ENDIAN_64BITWORD) && !defined(ENDIAN_32BITWORD)
220 #define ENDIAN_32BITWORD
224 #if defined(ENDIAN_64BITWORD) && !defined(_MSC_VER)
225 typedef unsigned long long ltc_mp_digit;
227 typedef unsigned long ltc_mp_digit;
230 /* No asm is a quick way to disable anything "not portable" */
232 #define ENDIAN_NEUTRAL
233 #undef ENDIAN_32BITWORD
234 #undef ENDIAN_64BITWORD
240 /* No LTC_FAST if: explicitly disabled OR non-gcc/non-clang compiler OR old gcc OR using -ansi -std=c99 */
241 #if defined(LTC_NO_FAST) || (__GNUC__ < 4) || defined(__STRICT_ANSI__)
246 #define LTC_FAST_TYPE_PTR_CAST(x) ((LTC_FAST_TYPE*)(void*)(x))
247 #ifdef ENDIAN_64BITWORD
248 typedef ulong64 __attribute__((__may_alias__)) LTC_FAST_TYPE;
250 typedef ulong32 __attribute__((__may_alias__)) LTC_FAST_TYPE;
254 #if !defined(ENDIAN_NEUTRAL) && (defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) && !(defined(ENDIAN_32BITWORD) || defined(ENDIAN_64BITWORD))
255 #error You must specify a word size as well as endianess in tomcrypt_cfg.h
258 #if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE))
259 #define ENDIAN_NEUTRAL
262 #if (defined(ENDIAN_32BITWORD) && defined(ENDIAN_64BITWORD))
263 #error Cannot be 32 and 64 bit words...
266 /* gcc 4.3 and up has a bswap builtin; detect it by gcc version.
267 * clang also supports the bswap builtin, and although clang pretends
268 * to be gcc (macro-wise, anyway), clang pretends to be a version
269 * prior to gcc 4.3, so we can't detect bswap that way. Instead,
270 * clang has a __has_builtin mechanism that can be used to check
272 * http://clang.llvm.org/docs/LanguageExtensions.html#feature_check */
273 #ifndef __has_builtin
274 #define __has_builtin(x) 0
276 #if !defined(LTC_NO_BSWAP) && defined(__GNUC__) && \
277 ((__GNUC__ * 100 + __GNUC_MINOR__ >= 403) || \
278 (__has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)))
279 #define LTC_HAVE_BSWAP_BUILTIN
283 /* ref: $Format:%D$ */
284 /* git commit: $Format:%H$ */
285 /* commit time: $Format:%ai$ */