]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/cc_config.h
807d58cea6bad74591f0c3443e89ba78449160c6
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 //Do not set these macros to 1, unless you are developing/testing for Windows
49 #define CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT 0
50 #define CORECRYPTO_HACK_FOR_WINDOWS_DEVELOPMENT 0 //to be removed after <rdar://problem/26585938> port corecrypto to Windows
52 //this macro is used to turn on/off usage of transparent union in corecrypto
53 //it should be commented out in corecrypto and be used only by the software that use corecrypto
54 //#define CORECRYPTO_DONOT_USE_TRANSPARENT_UNION
55 #ifdef CORECRYPTO_DONOT_USE_TRANSPARENT_UNION
56 #define CORECRYPTO_USE_TRANSPARENT_UNION 0
58 #define CORECRYPTO_USE_TRANSPARENT_UNION 1
61 #if (defined(DEBUG) && (DEBUG)) || defined(_DEBUG) //MSVC defines _DEBUG
62 /* CC_DEBUG is already used in CommonCrypto */
63 #define CORECRYPTO_DEBUG 1
65 #define CORECRYPTO_DEBUG 0
68 // This macro can be used to enable prints when a condition in the macro "cc_require"
69 // is false. This is especially useful to confirm that negative testing fails
70 // at the intended location
71 #define CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS 0
73 #if defined(KERNEL) && (KERNEL)
74 #define CC_KERNEL 1 // KEXT, XNU repo or kernel components such as AppleKeyStore
79 // LINUX_BUILD_TEST is for sanity check of the configuration
80 // > xcodebuild -scheme "corecrypto_test" OTHER_CFLAGS="$(values) -DLINUX_BUILD_TEST"
81 #if defined(__linux__) || defined(LINUX_BUILD_TEST)
87 #if defined(USE_L4) && (USE_L4)
93 #if defined(USE_SEPROM) && (USE_SEPROM)
94 #define CC_USE_SEPROM 1
96 #define CC_USE_SEPROM 0
99 #if defined(USE_S3) && (USE_S3)
105 #if (defined(ICE_FEATURES_ENABLED)) || (defined(MAVERICK) && (MAVERICK))
106 #define CC_BASEBAND 1
108 #define CC_BASEBAND 0
111 #if defined(EFI) && (EFI)
117 #if defined(IBOOT) && (IBOOT)
127 #if defined(ENDIAN_LITTLE) || (defined(__arm__) && !defined(__BIG_ENDIAN))
128 #define __LITTLE_ENDIAN__
129 #elif !defined(ENDIAN_BIG) && !defined(__BIG_ENDIAN)
130 #error Baseband endianess not defined.
132 #define AESOPT_ENDIAN_NO_FILE
135 #define CCN_UNIT_SIZE 4 // 32 bits
136 #define SAFE_IO // AES support for unaligned Input/Output
138 // -- External function
139 #define assert ASSERT // sanity
142 // Ignore irrelevant warnings after verification
143 // #1254-D: arithmetic on pointer to void or function type
144 // #186-D: pointless comparison of unsigned integer with zero
145 // #546-D: transfer of control bypasses initialization of
146 #if defined(__GNUC__)
147 // warning: pointer of type 'void *' used in arithmetic
148 #pragma GCC diagnostic ignored "-Wpointer-arith"
149 #endif // arm or gnuc
151 #endif // CC_BASEBAND
153 //CC_XNU_KERNEL_AVAILABLE indicates the availibity of XNU kernel functions,
154 //like what we have on OSX, iOS, tvOS, Watch OS
155 #if defined(__APPLE__) && defined(__MACH__)
156 #define CC_XNU_KERNEL_AVAILABLE 1
158 #define CC_XNU_KERNEL_AVAILABLE 0
161 #if !defined(CCN_UNIT_SIZE)
162 #if defined(__arm64__) || defined(__x86_64__) || defined(_WIN64)
163 #define CCN_UNIT_SIZE 8
164 #elif defined(__arm__) || defined(__i386__) || defined(_WIN32)
165 #define CCN_UNIT_SIZE 4
167 #error undefined architecture
169 #endif /* !defined(CCN_UNIT_SIZE) */
172 //this allows corecrypto Windows development using xcode
173 #if defined(CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT)
174 #if CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT && CC_XNU_KERNEL_AVAILABLE && CORECRYPTO_DEBUG
176 #define CC_USE_HEAP_FOR_WORKSPACE 1
177 #if (CCN_UNIT_SIZE==8)
178 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 0
180 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1
185 #if !defined(CCN_UINT128_SUPPORT_FOR_64BIT_ARCH)
186 #if defined(_WIN64) && defined(_WIN32) && (CCN_UNIT_SIZE==8)
187 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 0
188 #elif defined(_WIN32)
189 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1//should not be a problem
191 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1
195 #if __clang__ || CCN_UNIT_SIZE==8
196 #define CC_ALIGNED(x) __attribute__ ((aligned(x)))
198 #define CC_ALIGNED(x) __declspec(align(x))
200 #define CC_ALIGNED(x) __attribute__ ((aligned((x)>8?8:(x))))
204 #if defined(__x86_64__) || defined(__i386__)
209 #if CC_USE_L4 || CC_USE_S3
210 /* No dynamic linking allowed in L4, e.g. avoid nonlazy symbols */
211 /* For corecrypto kext, CC_STATIC should be undefined */
215 #if !defined(CC_USE_HEAP_FOR_WORKSPACE)
216 #if CC_USE_L4 || CC_IBOOT || CC_BASEBAND || defined(_MSC_VER)
217 /* For L4, stack is too short, need to use HEAP for some computations */
218 /* CC_USE_HEAP_FOR_WORKSPACE not supported for KERNEL! */
219 #define CC_USE_HEAP_FOR_WORKSPACE 1
221 #define CC_USE_HEAP_FOR_WORKSPACE 0
225 /* memset_s is only available in few target */
226 #if CC_KERNEL || CC_USE_SEPROM || defined(__CC_ARM) \
227 || defined(__hexagon__) || CC_EFI
228 #define CC_HAS_MEMSET_S 0
230 #define CC_HAS_MEMSET_S 1
233 // Include target conditionals if available.
234 #if defined(__has_include) /* portability */
235 #if __has_include(<TargetConditionals.h>)
236 #include <TargetConditionals.h>
237 #endif /* __has_include(<TargetConditionals.h>) */
238 #endif /* defined(__has_include) */
240 // Disable FIPS key gen algorithm on userland and kext so that related POST
241 // is skipped and boot time is reduced
242 #if defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE && CC_KERNEL
243 #define CC_DISABLE_RSAKEYGEN 1 /* for iBridge */
245 #define CC_DISABLE_RSAKEYGEN 0 /* default */
248 //- functions implemented in assembly ------------------------------------------
249 //this the list of corecrypto clients that use assembly and the clang compiler
250 #if !(CC_XNU_KERNEL_AVAILABLE || CC_KERNEL || CC_USE_L4 || CC_IBOOT || CC_USE_SEPROM || CC_USE_S3) && !defined(_WIN32) && CORECRYPTO_DEBUG
251 #warning "You are using the default corecrypto configuration, assembly optimizations may not be available for your platform"
254 // use this macro to strictly disable assembly regardless of cpu/os/compiler/etc
255 #if !defined(CC_USE_ASM)
256 #if defined(_MSC_VER) || CC_LINUX || CC_EFI || CC_BASEBAND
264 #if defined(_ARM_ARCH_7) && __clang__ && CC_USE_ASM
265 #define CCN_DEDICATED_SQR 1
266 #define CCN_MUL_KARATSUBA 0 // no performance improvement
267 #define CCN_ADD_ASM 1
268 #define CCN_SUB_ASM 1
269 #define CCN_MUL_ASM 0
270 #define CCN_ADDMUL1_ASM 1
271 #define CCN_MUL1_ASM 1
272 #define CCN_CMP_ASM 1
273 #define CCN_ADD1_ASM 0
274 #define CCN_SUB1_ASM 0
276 #define CCN_SET_ASM 1
277 #define CCN_SHIFT_RIGHT_ASM 1
278 #define CCAES_ARM_ASM 1
279 #define CCAES_INTEL_ASM 0
280 #if CC_KERNEL || CC_USE_L4 || CC_IBOOT || CC_USE_SEPROM || CC_USE_S3
285 #define CCN_USE_BUILTIN_CLZ 1
286 #define CCSHA1_VNG_INTEL 0
287 #define CCSHA2_VNG_INTEL 0
289 #if defined(__ARM_NEON__) || CC_KERNEL
290 #define CCSHA1_VNG_ARMV7NEON 1
291 #define CCSHA2_VNG_ARMV7NEON 1
292 #else /* !defined(__ARM_NEON__) */
293 #define CCSHA1_VNG_ARMV7NEON 0
294 #define CCSHA2_VNG_ARMV7NEON 0
295 #endif /* !defined(__ARM_NEON__) */
296 #define CCSHA256_ARMV6M_ASM 0
299 #elif (defined(__x86_64__) || defined(__i386__)) && __clang__ && CC_USE_ASM
300 #define CCN_DEDICATED_SQR 1
301 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
302 /* These assembly routines only work for a single CCN_UNIT_SIZE. */
303 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8) || (defined(__i386__) && CCN_UNIT_SIZE == 4)
304 #define CCN_ADD_ASM 1
305 #define CCN_SUB_ASM 1
306 #define CCN_MUL_ASM 1
308 #define CCN_ADD_ASM 0
309 #define CCN_SUB_ASM 0
310 #define CCN_MUL_ASM 0
313 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8)
314 #define CCN_CMP_ASM 1
316 #define CCN_SHIFT_RIGHT_ASM 1
318 #define CCN_CMP_ASM 0
320 #define CCN_SHIFT_RIGHT_ASM 0
323 #define CCN_ADDMUL1_ASM 0
324 #define CCN_MUL1_ASM 0
325 #define CCN_ADD1_ASM 0
326 #define CCN_SUB1_ASM 0
327 #define CCN_SET_ASM 0
328 #define CCAES_ARM_ASM 0
329 #define CCAES_INTEL_ASM 1
331 #define CCN_USE_BUILTIN_CLZ 0
332 #define CCSHA1_VNG_INTEL 1
333 #define CCSHA2_VNG_INTEL 1
334 #define CCSHA1_VNG_ARMV7NEON 0
335 #define CCSHA2_VNG_ARMV7NEON 0
336 #define CCSHA256_ARMV6M_ASM 0
338 //-(4) disable assembly
340 #if CCN_UINT128_SUPPORT_FOR_64BIT_ARCH
341 #define CCN_DEDICATED_SQR 1
343 #define CCN_DEDICATED_SQR 0 //when assembly is off and 128-bit integers are not supported, dedicated square is off. This is the case on Windows
345 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
346 #define CCN_ADD_ASM 0
347 #define CCN_SUB_ASM 0
348 #define CCN_MUL_ASM 0
349 #define CCN_ADDMUL1_ASM 0
350 #define CCN_MUL1_ASM 0
351 #define CCN_CMP_ASM 0
352 #define CCN_ADD1_ASM 0
353 #define CCN_SUB1_ASM 0
355 #define CCN_SET_ASM 0
356 #define CCN_SHIFT_RIGHT_ASM 0
357 #define CCAES_ARM_ASM 0
358 #define CCAES_INTEL_ASM 0
360 #define CCN_USE_BUILTIN_CLZ 0
361 #define CCSHA1_VNG_INTEL 0
362 #define CCSHA2_VNG_INTEL 0
363 #define CCSHA1_VNG_ARMV7NEON 0
364 #define CCSHA2_VNG_ARMV7NEON 0
365 #define CCSHA256_ARMV6M_ASM 0
369 #define CC_INLINE static inline
371 #if CORECRYPTO_USE_TRANSPARENT_UNION
372 // Non null for transparent unions is ambiguous and cause problems
373 // for most tools (GCC and others: 23919290).
374 #define CC_NONNULL_TU(N)
376 #define CC_NONNULL_TU(N) CC_NONNULL(N)
380 #define CC_NORETURN __attribute__((__noreturn__))
381 #define CC_NOTHROW __attribute__((__nothrow__))
382 #define CC_NONNULL(N) __attribute__((__nonnull__ N))
383 #define CC_NONNULL1 __attribute__((__nonnull__(1)))
384 #define CC_NONNULL2 __attribute__((__nonnull__(2)))
385 #define CC_NONNULL3 __attribute__((__nonnull__(3)))
386 #define CC_NONNULL4 __attribute__((__nonnull__(4)))
387 #define CC_NONNULL5 __attribute__((__nonnull__(5)))
388 #define CC_NONNULL6 __attribute__((__nonnull__(6)))
389 #define CC_NONNULL7 __attribute__((__nonnull__(7)))
390 #define CC_NONNULL_ALL __attribute__((__nonnull__))
391 #define CC_SENTINEL __attribute__((__sentinel__))
392 #define CC_CONST __attribute__((__const__))
393 #define CC_PURE __attribute__((__pure__))
394 #define CC_WARN_RESULT __attribute__((__warn_unused_result__))
395 #define CC_MALLOC __attribute__((__malloc__))
396 #define CC_UNUSED __attribute__((unused))
397 #else /* !__GNUC__ */
401 #define CC_NONNULL(N)
421 #define CC_NONNULL_ALL
429 #define CC_WARN_RESULT
432 #endif /* !__GNUC__ */
435 #endif /* _CORECRYPTO_CC_CONFIG_H_ */