1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis 3 * 4 * LibTomCrypt is a library that provides various cryptographic 5 * algorithms in a highly modular and flexible manner. 6 * 7 * The library is free for all purposes without any express 8 * guarantee it works. 9 */ 10 11 /* This is the build config file. 12 * 13 * With this you can setup what to inlcude/exclude automatically during any build. Just comment 14 * out the line that #define's the word for the thing you want to remove. phew! 15 */ 16 17 #ifndef TOMCRYPT_CFG_H 18 #define TOMCRYPT_CFG_H 19 20 #if defined(_WIN32) || defined(_MSC_VER) 21 #define LTC_CALL __cdecl 22 #elif !defined(LTC_CALL) 23 #define LTC_CALL 24 #endif 25 26 #ifndef LTC_EXPORT 27 #define LTC_EXPORT 28 #endif 29 30 /* certain platforms use macros for these, making the prototypes broken */ 31 #ifndef LTC_NO_PROTOTYPES 32 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); 38 39 LTC_EXPORT void LTC_CALL XQSORT(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); 40 41 42 /* change the clock function too */ 43 LTC_EXPORT clock_t LTC_CALL XCLOCK(void); 44 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); 49 50 LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); 51 52 #endif 53 54 /* some compilers do not like "inline" (or maybe "static inline"), namely: HP cc, IBM xlc */ 55 #if defined(__GNUC__) || defined(__xlc__) 56 #define LTC_INLINE __inline__ 57 #elif defined(_MSC_VER) || defined(__HP_cc) 58 #define LTC_INLINE __inline 59 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 60 #define LTC_INLINE inline 61 #else 62 #define LTC_INLINE 63 #endif 64 65 #if defined(__clang__) || defined(__GNUC_MINOR__) 66 #define LTC_NORETURN __attribute__ ((noreturn)) 67 #elif defined(_MSC_VER) 68 #define LTC_NORETURN __declspec(noreturn) 69 #else 70 #define LTC_NORETURN 71 #endif 72 73 /* type of argument checking, 0=default, 1=fatal and 2=error+continue, 3=nothing */ 74 #ifndef ARGTYPE 75 #define ARGTYPE 0 76 #endif 77 78 #undef LTC_ENCRYPT 79 #define LTC_ENCRYPT 0 80 #undef LTC_DECRYPT 81 #define LTC_DECRYPT 1 82 83 /* Controls endianess and size of registers. Leave uncommented to get platform neutral [slower] code 84 * 85 * Note: in order to use the optimized macros your platform must support unaligned 32 and 64 bit read/writes. 86 * The x86 platforms allow this but some others [ARM for instance] do not. On those platforms you **MUST** 87 * use the portable [slower] macros. 88 */ 89 /* detect x86/i386 32bit */ 90 #if defined(__i386__) || defined(__i386) || defined(_M_IX86) 91 #define ENDIAN_LITTLE 92 #define ENDIAN_32BITWORD 93 #define LTC_FAST 94 #endif 95 96 /* detect amd64/x64 */ 97 #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) 98 #define ENDIAN_LITTLE 99 #define ENDIAN_64BITWORD 100 #define LTC_FAST 101 #endif 102 103 /* detect PPC32 */ 104 #if defined(LTC_PPC32) 105 #define ENDIAN_BIG 106 #define ENDIAN_32BITWORD 107 #define LTC_FAST 108 #endif 109 110 /* detects MIPS R5900 processors (PS2) */ 111 #if (defined(__R5900) || defined(R5900) || defined(__R5900__)) && (defined(_mips) || defined(__mips__) || defined(mips)) 112 #define ENDIAN_64BITWORD 113 #if defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) 114 #define ENDIAN_BIG 115 #endif 116 #define ENDIAN_LITTLE 117 #endif 118 #endif 119 120 /* detect AIX */ 121 #if defined(_AIX) && defined(_BIG_ENDIAN) 122 #define ENDIAN_BIG 123 #if defined(__LP64__) || defined(_ARCH_PPC64) 124 #define ENDIAN_64BITWORD 125 #else 126 #define ENDIAN_32BITWORD 127 #endif 128 #endif 129 130 /* detect HP-UX */ 131 #if defined(__hpux) || defined(__hpux__) 132 #define ENDIAN_BIG 133 #if defined(__ia64) || defined(__ia64__) || defined(__LP64__) 134 #define ENDIAN_64BITWORD 135 #else 136 #define ENDIAN_32BITWORD 137 #endif 138 #endif 139 140 /* detect Apple OS X */ 141 #if defined(__APPLE__) && defined(__MACH__) 142 #if defined(__LITTLE_ENDIAN__) || defined(__x86_64__) 143 #define ENDIAN_LITTLE 144 #else 145 #define ENDIAN_BIG 146 #endif 147 #if defined(__LP64__) || defined(__x86_64__) 148 #define ENDIAN_64BITWORD 149 #else 150 #define ENDIAN_32BITWORD 151 #endif 152 #endif 153 154 /* detect SPARC and SPARC64 */ 155 #if defined(__sparc__) || defined(__sparc) 156 #define ENDIAN_BIG 157 #if defined(__arch64__) || defined(__sparcv9) || defined(__sparc_v9__) 158 #define ENDIAN_64BITWORD 159 #else 160 #define ENDIAN_32BITWORD 161 #endif 162 #endif 163 164 /* detect IBM S390(x) */ 165 #if defined(__s390x__) || defined(__s390__) 166 #define ENDIAN_BIG 167 #if defined(__s390x__) 168 #define ENDIAN_64BITWORD 169 #else 170 #define ENDIAN_32BITWORD 171 #endif 172 #endif 173 174 /* detect PPC64 */ 175 #if defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) 176 #define ENDIAN_64BITWORD 177 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 178 #define ENDIAN_BIG 179 #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 180 #define ENDIAN_LITTLE 181 #endif 182 #define LTC_FAST 183 #endif 184 185 /* endianness fallback */ 186 #if !defined(ENDIAN_BIG) && !defined(ENDIAN_LITTLE) 187 #if defined(_BYTE_ORDER) && _BYTE_ORDER == _BIG_ENDIAN || \ 188 defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \ 189 defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ || \ 190 defined(__BIG_ENDIAN__) || \ 191 defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ 192 defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) 193 #define ENDIAN_BIG 194 #elif defined(_BYTE_ORDER) && _BYTE_ORDER == _LITTLE_ENDIAN || \ 195 defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \ 196 defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ || \ 197 defined(__LITTLE_ENDIAN__) || \ 198 defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \ 199 defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) 200 #define ENDIAN_LITTLE 201 #else 202 #error Cannot detect endianness 203 #endif 204 #endif 205 206 /* ulong64: 64-bit data type */ 207 #ifdef _MSC_VER 208 #define CONST64(n) n ## ui64 209 typedef unsigned __int64 ulong64; 210 typedef __int64 long64; 211 #else 212 #define CONST64(n) n ## ULL 213 typedef unsigned long long ulong64; 214 typedef long long long64; 215 #endif 216 217 /* ulong32: "32-bit at least" data type */ 218 #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) || \ 219 defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || \ 220 defined(__s390x__) || defined(__arch64__) || defined(__aarch64__) || \ 221 defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \ 222 defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \ 223 defined(__LP64__) || defined(_LP64) || defined(__64BIT__) 224 typedef unsigned ulong32; 225 #if !defined(ENDIAN_64BITWORD) && !defined(ENDIAN_32BITWORD) 226 #define ENDIAN_64BITWORD 227 #endif 228 #else 229 typedef unsigned long ulong32; 230 #if !defined(ENDIAN_64BITWORD) && !defined(ENDIAN_32BITWORD) 231 #define ENDIAN_32BITWORD 232 #endif 233 #endif 234 235 #if defined(ENDIAN_64BITWORD) && !defined(_MSC_VER) 236 typedef unsigned long long ltc_mp_digit; 237 #else 238 typedef unsigned long ltc_mp_digit; 239 #endif 240 241 /* No asm is a quick way to disable anything "not portable" */ 242 #ifdef LTC_NO_ASM 243 #define ENDIAN_NEUTRAL 244 #undef ENDIAN_32BITWORD 245 #undef ENDIAN_64BITWORD 246 #undef LTC_FAST 247 #define LTC_NO_ROLC 248 #define LTC_NO_BSWAP 249 #endif 250 251 /* No LTC_FAST if: explicitly disabled OR non-gcc/non-clang compiler OR old gcc OR using -ansi -std=c99 */ 252 #if defined(LTC_NO_FAST) || (__GNUC__ < 4) || defined(__STRICT_ANSI__) 253 #undef LTC_FAST 254 #endif 255 256 #ifdef LTC_FAST 257 #define LTC_FAST_TYPE_PTR_CAST(x) ((LTC_FAST_TYPE*)(void*)(x)) 258 #ifdef ENDIAN_64BITWORD 259 typedef ulong64 __attribute__((__may_alias__)) LTC_FAST_TYPE; 260 #else 261 typedef ulong32 __attribute__((__may_alias__)) LTC_FAST_TYPE; 262 #endif 263 #endif 264 265 #if !defined(ENDIAN_NEUTRAL) && (defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) && !(defined(ENDIAN_32BITWORD) || defined(ENDIAN_64BITWORD)) 266 #error You must specify a word size as well as endianess in tomcrypt_cfg.h 267 #endif 268 269 #if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) 270 #define ENDIAN_NEUTRAL 271 #endif 272 273 #if (defined(ENDIAN_32BITWORD) && defined(ENDIAN_64BITWORD)) 274 #error Cannot be 32 and 64 bit words... 275 #endif 276 277 /* gcc 4.3 and up has a bswap builtin; detect it by gcc version. 278 * clang also supports the bswap builtin, and although clang pretends 279 * to be gcc (macro-wise, anyway), clang pretends to be a version 280 * prior to gcc 4.3, so we can't detect bswap that way. Instead, 281 * clang has a __has_builtin mechanism that can be used to check 282 * for builtins: 283 * http://clang.llvm.org/docs/LanguageExtensions.html#feature_check */ 284 #ifndef __has_builtin 285 #define __has_builtin(x) 0 286 #endif 287 #if !defined(LTC_NO_BSWAP) && defined(__GNUC__) && \ 288 ((__GNUC__ * 100 + __GNUC_MINOR__ >= 403) || \ 289 (__has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64))) 290 #define LTC_HAVE_BSWAP_BUILTIN 291 #endif 292 293 #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 301) 294 #define LTC_DEPRECATED __attribute__((deprecated)) 295 #elif defined(_MSC_VER) && _MSC_VER >= 1500 296 /* supported since Visual Studio 2008 */ 297 #define LTC_DEPRECATED __declspec(deprecated) 298 #else 299 #define LTC_DEPRECATED 300 #endif 301 302 /* ref: $Format:%D$ */ 303 /* git commit: $Format:%H$ */ 304 /* commit time: $Format:%ai$ */ 305