]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/cc_config.h
45979d8cf81c60174c06a304fb7b61f3867025f7
5 * Created on 11/16/2010
7 * Copyright (c) 2010,2011,2012,2013,2014,2015 Apple Inc. All rights reserved.
11 #ifndef _CORECRYPTO_CC_CONFIG_H_
12 #define _CORECRYPTO_CC_CONFIG_H_
14 /* A word about configuration macros:
16 Conditional configuration macros specific to corecrypto should be named CORECRYPTO_xxx
17 or CCxx_yyy and be defined to be either 0 or 1 in this file. You can add an
18 #ifndef #error construct at the end of this file to make sure it's always defined.
20 They should always be tested using the #if directive, never the #ifdef directive.
22 No other conditional macros shall ever be used (except in this file)
24 Configuration Macros that are defined outside of corecrypto (eg: KERNEL, DEBUG, ...)
25 shall only be used in this file to define CCxxx macros.
27 External macros should be assumed to be either undefined, defined with no value,
28 or defined as true or false. We shall strive to build with -Wundef whenever possible,
29 so the following construct should be used to test external macros in this file:
31 #if defined(DEBUG) && (DEBUG)
32 #define CORECRYPTO_DEBUG 1
34 #define CORECRYPTO_DEBUG 0
38 It is acceptable to define a conditional CC_xxxx macro in an implementation file,
39 to be used only in this file.
41 The current code is not guaranteed to follow those rules, but should be fixed to.
43 Corecrypto requires GNU and C99 compatibility.
44 Typically enabled by passing --gnu --c99 to the compiler (eg. armcc)
48 #if (defined(DEBUG) && (DEBUG))
49 /* CC_DEBUG is already used in CommonCrypto */
50 #define CORECRYPTO_DEBUG 1
52 #define CORECRYPTO_DEBUG 0
55 #if defined(KERNEL) && (KERNEL)
56 #define CC_KERNEL 1 // KEXT, XNU repo or kernel components such as AppleKeyStore
61 // LINUX_BUILD_TEST is for sanity check of the configuration
62 // > xcodebuild -scheme "corecrypto_test" OTHER_CFLAGS="$(values) -DLINUX_BUILD_TEST"
63 #if defined(__linux__) || defined(LINUX_BUILD_TEST)
69 #if defined(USE_L4) && (USE_L4)
75 #if defined(USE_SEPROM) && (USE_SEPROM)
76 #define CC_USE_SEPROM 1
78 #define CC_USE_SEPROM 0
81 #if defined(USE_S3) && (USE_S3)
87 #if defined(MAVERICK) && (MAVERICK)
93 #if defined(IBOOT) && (IBOOT)
103 #if defined(ENDIAN_LITTLE) || (defined(__arm__) && !defined(__BIG_ENDIAN))
104 #define __LITTLE_ENDIAN__
105 #elif !defined(ENDIAN_BIG) && !defined(__BIG_ENDIAN)
106 #error Baseband endianess not defined.
108 #define AESOPT_ENDIAN_NO_FILE
111 #define CCN_UNIT_SIZE 4 // 32 bits
112 #define aligned(x) aligned((x)>8?8:(x)) // Alignment on 8 bytes max
113 #define SAFE_IO // AES support for unaligned Input/Output
115 // -- External function
116 #define assert ASSERT // sanity
119 // Ignore irrelevant warnings after verification
120 // #1254-D: arithmetic on pointer to void or function type
121 // #186-D: pointless comparison of unsigned integer with zero
122 // #546-D: transfer of control bypasses initialization of
123 #if defined(__GNUC__)
124 // warning: pointer of type 'void *' used in arithmetic
125 #pragma GCC diagnostic ignored "-Wpointer-arith"
126 #endif // arm or gnuc
130 #if !defined(CCN_UNIT_SIZE)
131 #if defined(__arm64__) || defined(__x86_64__)
132 #define CCN_UNIT_SIZE 8
133 #elif defined(__arm__) || defined(__i386__)
134 #define CCN_UNIT_SIZE 4
136 #define CCN_UNIT_SIZE 2
138 #endif /* !defined(CCN_UNIT_SIZE) */
140 #if defined(__x86_64__) || defined(__i386__)
145 #if CC_USE_L4 || CC_USE_S3
146 /* No dynamic linking allowed in L4, e.g. avoid nonlazy symbols */
147 /* For corecrypto kext, CC_STATIC should be undefined */
151 #if CC_USE_L4 || CC_IBOOT
152 /* For L4, stack is too short, need to use HEAP for some computations */
153 /* CC_USE_HEAP_FOR_WORKSPACE not supported for KERNEL! */
154 #define CC_USE_HEAP_FOR_WORKSPACE 1
156 #define CC_USE_HEAP_FOR_WORKSPACE 0
159 /* L4 do not have bzero, neither does hexagon of ARMCC even with gnu compatibility mode */
160 #if CC_USE_L4 || defined(__CC_ARM) || defined(__hexagon__)
161 #define CC_HAS_BZERO 0
163 #define CC_HAS_BZERO 1
166 /* memset_s is only available in few target */
167 #if CC_USE_L4 || CC_KERNEL || CC_IBOOT || CC_USE_SEPROM || defined(__CC_ARM) || defined(__hexagon__)
168 #define CC_HAS_MEMSET_S 0
170 #define CC_HAS_MEMSET_S 1
174 #if defined(__CC_ARM) || defined(__hexagon__) || CC_LINUX || defined(__NO_ASM__)
175 // ARMASM.exe does not to like the file syntax of the asm implementation
176 #define CCN_DEDICATED_SQR 1
177 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
178 #define CCN_ADD_ASM 0
179 #define CCN_SUB_ASM 0
180 #define CCN_MUL_ASM 0
181 #define CCN_ADDMUL1_ASM 0
182 #define CCN_MUL1_ASM 0
183 #define CCN_CMP_ASM 0
184 #define CCN_ADD1_ASM 0
185 #define CCN_SUB1_ASM 0
187 #define CCN_SET_ASM 0
189 #define CCAES_INTEL 0
190 #define CCN_USE_BUILTIN_CLZ 0
191 #if !defined(__NO_ASM__)
192 #define CCSHA1_VNG_INTEL 0
193 #define CCSHA2_VNG_INTEL 0
194 #define CCSHA1_VNG_ARMV7NEON 0
195 #define CCSHA2_VNG_ARMV7NEON 0
199 #elif defined(__x86_64__) || defined(__i386__)
200 #define CCN_DEDICATED_SQR 1
201 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
202 /* These assembly routines only work for a single CCN_UNIT_SIZE. */
203 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8) || (defined(__i386__) && CCN_UNIT_SIZE == 4)
204 #define CCN_ADD_ASM 1
205 #define CCN_SUB_ASM 1
206 #define CCN_MUL_ASM 0
208 #define CCN_ADD_ASM 0
209 #define CCN_SUB_ASM 0
210 #define CCN_MUL_ASM 0
213 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8)
214 #define CCN_CMP_ASM 1
217 #define CCN_CMP_ASM 0
221 #define CCN_ADDMUL1_ASM 0
222 #define CCN_MUL1_ASM 0
223 #define CCN_ADD1_ASM 0
224 #define CCN_SUB1_ASM 0
225 #define CCN_SET_ASM 0
227 #define CCAES_INTEL 1
229 #define CCN_USE_BUILTIN_CLZ 0
230 #define CCSHA1_VNG_INTEL 1
231 #define CCSHA2_VNG_INTEL 1
232 #define CCSHA1_VNG_ARMV7NEON 0
233 #define CCSHA2_VNG_ARMV7NEON 0
236 #define CCN_DEDICATED_SQR 1
237 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
238 #define CCN_ADD_ASM 0
239 #define CCN_SUB_ASM 0
240 #define CCN_MUL_ASM 0
241 #define CCN_ADDMUL1_ASM 0
242 #define CCN_MUL1_ASM 0
243 #define CCN_CMP_ASM 0
244 #define CCN_ADD1_ASM 0
245 #define CCN_SUB1_ASM 0
247 #define CCN_SET_ASM 0
249 #define CCAES_INTEL 0
251 #define CCN_USE_BUILTIN_CLZ 0
252 #define CCSHA1_VNG_INTEL 0
253 #define CCSHA2_VNG_INTEL 0
254 #define CCSHA1_VNG_ARMV7NEON 0
255 #define CCSHA2_VNG_ARMV7NEON 0
257 #endif /* !defined(__i386__) */
259 #define CC_INLINE static inline
262 #define CC_NORETURN __attribute__((__noreturn__))
263 #define CC_NOTHROW __attribute__((__nothrow__))
265 #if defined(__CC_ARM) || defined(__hexagon__)
266 #define CC_NONNULL_TU(N)
268 #define CC_NONNULL_TU(N) __attribute__((__nonnull__ N))
270 #define CC_NONNULL(N) __attribute__((__nonnull__ N))
271 #define CC_NONNULL1 __attribute__((__nonnull__(1)))
272 #define CC_NONNULL2 __attribute__((__nonnull__(2)))
273 #define CC_NONNULL3 __attribute__((__nonnull__(3)))
274 #define CC_NONNULL4 __attribute__((__nonnull__(4)))
275 #define CC_NONNULL5 __attribute__((__nonnull__(5)))
276 #define CC_NONNULL6 __attribute__((__nonnull__(6)))
277 #define CC_NONNULL7 __attribute__((__nonnull__(7)))
278 #define CC_NONNULL_ALL __attribute__((__nonnull__))
279 #define CC_SENTINEL __attribute__((__sentinel__))
280 #define CC_CONST __attribute__((__const__))
281 #define CC_PURE __attribute__((__pure__))
282 #define CC_WARN_RESULT __attribute__((__warn_unused_result__))
283 #define CC_MALLOC __attribute__((__malloc__))
284 #define CC_UNUSED __attribute__((unused))
285 #else /* !__GNUC__ */
289 #define CC_NONNULL_TU(N)
291 #define CC_NONNULL(N)
311 #define CC_NONNULL_ALL
319 #define CC_WARN_RESULT
322 #endif /* !__GNUC__ */
325 #endif /* _CORECRYPTO_CC_CONFIG_H_ */