1/* 2 * cc_config.h 3 * corecrypto 4 * 5 * Created by Michael Brouwer on 10/18/10. 6 * Copyright 2010,2011 Apple Inc. All rights reserved. 7 * 8 */ 9 10#ifndef _CORECRYPTO_CC_CONFIG_H_ 11#define _CORECRYPTO_CC_CONFIG_H_ 12 13/* A word about configuration macros: 14 15 Conditional configuration macros specific to corecrypto should be named CORECRYPTO_xxx 16 or CCxx_yyy and be defined to be either 0 or 1 in this file. You can add an 17 #ifndef #error construct at the end of this file to make sure it's always defined. 18 19 They should always be tested using the #if directive, never the #ifdef directive. 20 21 No other conditional macros shall ever be used (except in this file) 22 23 Configuration Macros that are defined outside of corecrypto (eg: KERNEL, DEBUG, ...) 24 shall only be used in this file to define CCxxx macros. 25 26 External macros should be assumed to be either undefined, defined with no value, 27 or defined as true or false. We shall strive to build with -Wundef whenever possible, 28 so the following construct should be used to test external macros in this file: 29 30 #if defined(DEBUG) && (DEBUG) 31 #define CORECRYPTO_DEBUG 1 32 #else 33 #define CORECRYPTO_DEBUG 0 34 #endif 35 36 37 It is acceptable to define a conditional CC_xxxx macro in an implementation file, 38 to be used only in this file. 39 40 The current code is not guaranteed to follow those rules, but should be fixed to. 41 42 Corecrypto requires GNU and C99 compatibility. 43 Typically enabled by passing --gnu --c99 to the compiler (eg. armcc) 44 45*/ 46 47#if defined(DEBUG) && (DEBUG) 48/* CC_DEBUG is already used in CommonCrypto */ 49#define CORECRYPTO_DEBUG 1 50#else 51#define CORECRYPTO_DEBUG 0 52#endif 53 54#if defined(KERNEL) && (KERNEL) 55#define CC_KERNEL 1 56#else 57#define CC_KERNEL 0 58#endif 59 60#if defined(USE_L4) && (USE_L4) 61#define CC_USE_L4 1 62#else 63#define CC_USE_L4 0 64#endif 65 66#if defined(MAVERICK) && (MAVERICK) 67#define CC_MAVERICK 1 68#else 69#define CC_MAVERICK 0 70#endif 71 72#if defined(IBOOT) && (IBOOT) 73#define CC_IBOOT 1 74#else 75#define CC_IBOOT 0 76#endif 77 78// BB configuration 79#if CC_MAVERICK 80 81// -- ENDIANESS 82#if defined(ENDIAN_LITTLE) || (defined(__arm__) && !defined(__BIG_ENDIAN)) 83#define __LITTLE_ENDIAN__ 84#elif !defined(ENDIAN_BIG) && !defined(__BIG_ENDIAN) 85#error Baseband endianess not defined. 86#endif 87#define AESOPT_ENDIAN_NO_FILE 88 89// -- Architecture 90#define CCN_UNIT_SIZE 4 // 32 bits 91#define aligned(x) aligned((x)>8?8:(x)) // Alignment on 8 bytes max 92#define SAFE_IO // AES support for unaligned Input/Output 93 94// -- External function 95#define assert ASSERT // sanity 96 97// -- Warnings 98// Ignore irrelevant warnings after verification 99// #1254-D: arithmetic on pointer to void or function type 100// #186-D: pointless comparison of unsigned integer with zero 101// #546-D: transfer of control bypasses initialization of 102#if defined(__GNUC__) 103// warning: pointer of type 'void *' used in arithmetic 104#pragma GCC diagnostic ignored "-Wpointer-arith" 105#endif // arm or gnuc 106 107#endif // MAVERICK 108 109#if !defined(CCN_UNIT_SIZE) 110#if defined(__arm64__) || defined(__x86_64__) 111#define CCN_UNIT_SIZE 8 112#elif defined(__arm__) || defined(__i386__) 113#define CCN_UNIT_SIZE 4 114#else 115#define CCN_UNIT_SIZE 2 116#endif 117#endif /* !defined(CCN_UNIT_SIZE) */ 118 119#if defined(__x86_64__) || defined(__i386__) 120#define CCN_IOS 0 121#define CCN_OSX 1 122#endif 123 124/* No dynamic linking allowed in L4, e.g. avoid nonlazy symbols */ 125/* For corecrypto kext, CC_STATIC should be 0 */ 126#if CC_USE_L4 127#define CC_STATIC 1 128#endif 129 130/* L4 do not have bzero, neither does hexagon of ARMCC even with gnu compatibility mode */ 131#if CC_USE_L4 || defined(__CC_ARM) || defined(__hexagon__) 132#define CC_HAS_BZERO 0 133#else 134#define CC_HAS_BZERO 1 135#endif 136 137#if defined(__CC_ARM) || defined(__hexagon__) 138// ARMASM.exe does not to like the file syntax of the asm implementation 139 140#define CCN_ADD_ASM 0 141#define CCN_SUB_ASM 0 142#define CCN_MUL_ASM 0 143#define CCN_ADDMUL1_ASM 0 144#define CCN_MUL1_ASM 0 145#define CCN_CMP_ASM 0 146#define CCN_ADD1_ASM 0 147#define CCN_SUB1_ASM 0 148#define CCN_N_ASM 0 149#define CCN_SET_ASM 0 150#define CCAES_ARM 0 151#define CCAES_INTEL 0 152#define CCN_USE_BUILTIN_CLZ 0 153#define CCSHA1_VNG_INTEL 0 154#define CCSHA2_VNG_INTEL 0 155 156#elif defined(__x86_64__) || defined(__i386__) 157 158/* These assembly routines only work for a single CCN_UNIT_SIZE. */ 159#if (defined(__x86_64__) && CCN_UNIT_SIZE == 8) || (defined(__i386__) && CCN_UNIT_SIZE == 4) 160#define CCN_ADD_ASM 1 161#define CCN_SUB_ASM 1 162#define CCN_MUL_ASM 1 163#else 164#define CCN_ADD_ASM 0 165#define CCN_SUB_ASM 0 166#define CCN_MUL_ASM 0 167#endif 168 169#define CCN_ADDMUL1_ASM 0 170#define CCN_MUL1_ASM 0 171#define CCN_CMP_ASM 0 172#define CCN_ADD1_ASM 0 173#define CCN_SUB1_ASM 0 174#define CCN_N_ASM 0 175#define CCN_SET_ASM 0 176#define CCAES_ARM 0 177#define CCAES_INTEL 1 178#define CCAES_MUX 0 179#define CCN_USE_BUILTIN_CLZ 0 180#define CCSHA1_VNG_INTEL 1 181#define CCSHA2_VNG_INTEL 1 182#define CCSHA1_VNG_ARMV7NEON 0 183#define CCSHA2_VNG_ARMV7NEON 0 184 185#else 186 187#define CCN_ADD_ASM 0 188#define CCN_SUB_ASM 0 189#define CCN_MUL_ASM 0 190#define CCN_ADDMUL1_ASM 0 191#define CCN_MUL1_ASM 0 192#define CCN_CMP_ASM 0 193#define CCN_ADD1_ASM 0 194#define CCN_SUB1_ASM 0 195#define CCN_N_ASM 0 196#define CCN_SET_ASM 0 197#define CCAES_ARM 0 198#define CCAES_INTEL 0 199#define CCAES_MUX 0 200#define CCN_USE_BUILTIN_CLZ 0 201#define CCSHA1_VNG_INTEL 0 202#define CCSHA2_VNG_INTEL 0 203#define CCSHA1_VNG_ARMV7NEON 0 204#define CCSHA2_VNG_ARMV7NEON 0 205 206#endif /* !defined(__i386__) */ 207 208#define CCN_N_INLINE 0 209#define CCN_CMP_INLINE 0 210 211#define CC_INLINE static inline 212 213#ifdef __GNUC__ 214#define CC_NORETURN __attribute__((__noreturn__)) 215#define CC_NOTHROW __attribute__((__nothrow__)) 216// Transparent Union 217#if defined(__CC_ARM) || defined(__hexagon__) 218#define CC_NONNULL_TU(N) 219#else 220#define CC_NONNULL_TU(N) __attribute__((__nonnull__ N)) 221#endif 222#define CC_NONNULL(N) __attribute__((__nonnull__ N)) 223#define CC_NONNULL1 __attribute__((__nonnull__(1))) 224#define CC_NONNULL2 __attribute__((__nonnull__(2))) 225#define CC_NONNULL3 __attribute__((__nonnull__(3))) 226#define CC_NONNULL4 __attribute__((__nonnull__(4))) 227#define CC_NONNULL5 __attribute__((__nonnull__(5))) 228#define CC_NONNULL6 __attribute__((__nonnull__(6))) 229#define CC_NONNULL7 __attribute__((__nonnull__(7))) 230#define CC_NONNULL_ALL __attribute__((__nonnull__)) 231#define CC_SENTINEL __attribute__((__sentinel__)) 232#define CC_CONST __attribute__((__const__)) 233#define CC_PURE __attribute__((__pure__)) 234#define CC_WARN_RESULT __attribute__((__warn_unused_result__)) 235#define CC_MALLOC __attribute__((__malloc__)) 236#define CC_UNUSED __attribute__((unused)) 237#else /* !__GNUC__ */ 238/*! @parseOnly */ 239#define CC_UNUSED 240/*! @parseOnly */ 241#define CC_NONNULL_TU(N) 242/*! @parseOnly */ 243#define CC_NONNULL(N) 244/*! @parseOnly */ 245#define CC_NORETURN 246/*! @parseOnly */ 247#define CC_NOTHROW 248/*! @parseOnly */ 249#define CC_NONNULL1 250/*! @parseOnly */ 251#define CC_NONNULL2 252/*! @parseOnly */ 253#define CC_NONNULL3 254/*! @parseOnly */ 255#define CC_NONNULL4 256/*! @parseOnly */ 257#define CC_NONNULL5 258/*! @parseOnly */ 259#define CC_NONNULL6 260/*! @parseOnly */ 261#define CC_NONNULL7 262/*! @parseOnly */ 263#define CC_NONNULL_ALL 264/*! @parseOnly */ 265#define CC_SENTINEL 266/*! @parseOnly */ 267#define CC_CONST 268/*! @parseOnly */ 269#define CC_PURE 270/*! @parseOnly */ 271#define CC_WARN_RESULT 272/*! @parseOnly */ 273#define CC_MALLOC 274#endif /* !__GNUC__ */ 275 276#endif /* _CORECRYPTO_CC_CONFIG_H_ */ 277