]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/cc_config.h
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 this macros to 1, unless you are developing/testing for Linux under macOS
49 #define CORECRYPTO_SIMULATE_POSIX_ENVIRONMENT 0
51 //Do not set these macros to 1, unless you are developing/testing for Windows under macOS
52 #define CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT 0
53 #define CORECRYPTO_HACK_FOR_WINDOWS_DEVELOPMENT 0 //to be removed after <rdar://problem/27304763> port corecrypto to Windows
55 #if (defined(DEBUG) && (DEBUG)) || defined(_DEBUG) //MSVC defines _DEBUG
56 /* CC_DEBUG is already used in CommonCrypto */
57 #define CORECRYPTO_DEBUG 1
59 #define CORECRYPTO_DEBUG 0
62 // This macro can be used to enable prints when a condition in the macro "cc_require"
63 // is false. This is especially useful to confirm that negative testing fails
64 // at the intended location
65 #define CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS 0
67 #if defined(KERNEL) && (KERNEL)
68 #define CC_KERNEL 1 // KEXT, XNU repo or kernel components such as AppleKeyStore
73 #if defined(__linux__) || CORECRYPTO_SIMULATE_POSIX_ENVIRONMENT
79 #if defined(USE_L4) && (USE_L4)
85 #if defined(RTKIT) && (RTKIT)
91 #if defined(RTKITROM) && (RTKITROM)
97 #if defined(USE_SEPROM) && (USE_SEPROM)
98 #define CC_USE_SEPROM 1
100 #define CC_USE_SEPROM 0
103 #if defined(USE_S3) && (USE_S3)
109 #if (defined(ICE_FEATURES_ENABLED)) || (defined(MAVERICK) && (MAVERICK))
110 #define CC_BASEBAND 1
112 #define CC_BASEBAND 0
115 #if defined(EFI) && (EFI)
121 #if defined(IBOOT) && (IBOOT)
127 // Defined by the XNU build scripts
128 // Applies to code embedded in XNU but NOT to the kext
129 #if defined(XNU_KERNEL_PRIVATE)
130 #define CC_XNU_KERNEL_PRIVATE 1
132 #define CC_XNU_KERNEL_PRIVATE 0
135 // handle unaligned data, if the cpu cannot. Currently for gladman AES and the C version of the SHA256
136 #define CC_HANDLE_UNALIGNED_DATA CC_BASEBAND
138 // BaseBand configuration
142 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
143 #if defined(ENDIAN_LITTLE) || (defined(__arm__) && !defined(__BIG_ENDIAN))
144 #define __LITTLE_ENDIAN__
145 #elif !defined(ENDIAN_BIG) && !defined(__BIG_ENDIAN)
146 #error Baseband endianess not defined.
148 #define AESOPT_ENDIAN_NO_FILE
152 #define CCN_UNIT_SIZE 4 // 32 bits
154 // -- External function
155 #define assert ASSERT // sanity
158 // Ignore irrelevant warnings after verification
159 // #1254-D: arithmetic on pointer to void or function type
160 // #186-D: pointless comparison of unsigned integer with zero
161 // #546-D: transfer of control bypasses initialization of
163 #pragma diag_suppress 186, 1254,546
164 #elif defined(__GNUC__)
165 // warning: pointer of type 'void *' used in arithmetic
166 #pragma GCC diagnostic ignored "-Wpointer-arith"
168 #define CC_SMALL_CODE 1
170 #endif // CC_BASEBAND
172 #if CC_RTKIT || CC_RTKITROM
173 #define CC_SMALL_CODE 1
177 #ifndef CC_SMALL_CODE
178 #define CC_SMALL_CODE 0
181 //CC_XNU_KERNEL_AVAILABLE indicates the availibity of XNU kernel functions,
182 //like what we have on OSX, iOS, tvOS, Watch OS
183 #if defined(__APPLE__) && defined(__MACH__)
184 #define CC_XNU_KERNEL_AVAILABLE 1
186 #define CC_XNU_KERNEL_AVAILABLE 0
189 //arm arch64 definition for gcc
190 #if defined(__GNUC__) && defined(__aarch64__) && !defined(__arm64__)
194 #if !defined(CCN_UNIT_SIZE)
195 #if defined(__arm64__) || defined(__x86_64__) || defined(_WIN64)
196 #define CCN_UNIT_SIZE 8
197 #elif defined(__arm__) || defined(__i386__) || defined(_WIN32)
198 #define CCN_UNIT_SIZE 4
200 #error undefined architecture
202 #endif /* !defined(CCN_UNIT_SIZE) */
205 //this allows corecrypto Windows development using xcode
206 #if defined(CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT)
207 #if CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT && CC_XNU_KERNEL_AVAILABLE && CORECRYPTO_DEBUG
209 #define CC_USE_HEAP_FOR_WORKSPACE 1
210 #if (CCN_UNIT_SIZE==8)
211 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 0
213 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1
218 #if !defined(CCN_UINT128_SUPPORT_FOR_64BIT_ARCH)
219 #if defined(_WIN64) && defined(_WIN32) && (CCN_UNIT_SIZE==8)
220 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 0
221 #elif defined(_WIN32)
222 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1//should not be a problem
224 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1
228 #if defined(_MSC_VER)
229 #if defined(__clang__)
230 #define CC_ALIGNED(x) __attribute__ ((aligned(x))) //clang compiler
232 #define CC_ALIGNED(x) __declspec(align(x)) //MS complier
235 #if __clang__ || CCN_UNIT_SIZE==8
236 #define CC_ALIGNED(x) __attribute__ ((aligned(x)))
238 #define CC_ALIGNED(x) __attribute__ ((aligned((x)>8?8:(x))))
243 //this is copied from <arm/arch.h>, because <arm/arch.h> is not available on SEPROM environment
244 #if defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7S__) || defined (__ARM_ARCH_7F__) || defined (__ARM_ARCH_7K__) || defined(__ARM_ARCH_7EM__)
248 #if defined(__ARM_ARCH_6M__) || defined(__TARGET_ARCH_6S_M) || defined (__armv6m__)
253 #if defined(__arm64__) || defined(__arm__)
256 #elif defined(__x86_64__) || defined(__i386__)
261 #if CC_USE_L4 || CC_USE_S3
262 /* No dynamic linking allowed in L4, e.g. avoid nonlazy symbols */
263 /* For corecrypto kext, CC_STATIC should be undefined */
267 #if !defined(CC_USE_HEAP_FOR_WORKSPACE)
268 #if CC_USE_S3 || CC_USE_SEPROM || CC_RTKITROM
269 #define CC_USE_HEAP_FOR_WORKSPACE 0
271 #define CC_USE_HEAP_FOR_WORKSPACE 1
275 /* memset_s is only available in few target */
276 #if CC_USE_SEPROM || defined(__CC_ARM) \
277 || defined(__hexagon__) || CC_EFI
278 #define CC_HAS_MEMSET_S 0
280 #define CC_HAS_MEMSET_S 1
283 // Include target conditionals if available.
284 #if defined(__has_include) /* portability */
285 #if __has_include(<TargetConditionals.h>)
286 #include <TargetConditionals.h>
287 #endif /* __has_include(<TargetConditionals.h>) */
288 #endif /* defined(__has_include) */
290 // Disable RSA Keygen on iBridge
291 #if defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE && CC_KERNEL
292 #define CC_DISABLE_RSAKEYGEN 1 /* for iBridge */
294 #define CC_DISABLE_RSAKEYGEN 0 /* default */
297 // see rdar://problem/26636018
298 #if (CCN_UNIT_SIZE == 8) && !( defined(_MSC_VER) && defined(__clang__))
299 #define CCEC25519_CURVE25519DONNA_64BIT 1
301 #define CCEC25519_CURVE25519DONNA_64BIT 0
304 //- functions implemented in assembly ------------------------------------------
305 //this the list of corecrypto clients that use assembly and the clang compiler
306 #if !(CC_XNU_KERNEL_AVAILABLE || CC_KERNEL || CC_USE_L4 || CC_IBOOT || CC_RTKIT || CC_RTKITROM || CC_USE_SEPROM || CC_USE_S3) && !defined(_WIN32) && CORECRYPTO_DEBUG
307 #warning "You are using the default corecrypto configuration, assembly optimizations may not be available for your platform"
310 // Use this macro to strictly disable assembly regardless of cpu/os/compiler/etc.
311 // Our assembly code is not gcc compatible. Clang defines the __GNUC__ macro as well.
312 #if !defined(CC_USE_ASM)
313 #if defined(_WIN32) || CC_EFI || CC_BASEBAND || CC_XNU_KERNEL_PRIVATE || (defined(__GNUC__) && !defined(__clang__)) || defined(__ANDROID_API__) || CC_RTKIT || CC_RTKITROM
321 #if defined(_ARM_ARCH_7) && __clang__ && CC_USE_ASM
322 #define CCN_DEDICATED_SQR CC_SMALL_CODE
323 #define CCN_MUL_KARATSUBA 0 // no performance improvement
324 #define CCN_ADD_ASM 1
325 #define CCN_SUB_ASM 1
326 #define CCN_MUL_ASM 0
327 #define CCN_ADDMUL1_ASM 1
328 #define CCN_MUL1_ASM 1
329 #define CCN_CMP_ASM 1
330 #define CCN_ADD1_ASM 0
331 #define CCN_SUB1_ASM 0
333 #define CCN_SET_ASM 1
334 #define CCN_SHIFT_RIGHT_ASM 1
335 #define CCAES_ARM_ASM 1
336 #define CCAES_INTEL_ASM 0
337 #if CC_KERNEL || CC_USE_L4 || CC_IBOOT || CC_RTKIT || CC_RTKITROM || CC_USE_SEPROM || CC_USE_S3
342 #define CCN_USE_BUILTIN_CLZ 1
343 #define CCSHA1_VNG_INTEL 0
344 #define CCSHA2_VNG_INTEL 0
346 #if defined(__ARM_NEON__) || CC_KERNEL
347 #define CCSHA1_VNG_ARMV7NEON 1
348 #define CCSHA2_VNG_ARMV7NEON 1
349 #else /* !defined(__ARM_NEON__) */
350 #define CCSHA1_VNG_ARMV7NEON 0
351 #define CCSHA2_VNG_ARMV7NEON 0
352 #endif /* !defined(__ARM_NEON__) */
353 #define CCSHA256_ARMV6M_ASM 0
356 #elif defined(__arm64__) && __clang__ && CC_USE_ASM
357 #define CCN_DEDICATED_SQR CC_SMALL_CODE
358 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
359 #define CCN_ADD_ASM 1
360 #define CCN_SUB_ASM 1
361 #define CCN_MUL_ASM 1
362 #define CCN_ADDMUL1_ASM 0
363 #define CCN_MUL1_ASM 0
364 #define CCN_CMP_ASM 1
365 #define CCN_ADD1_ASM 0
366 #define CCN_SUB1_ASM 0
368 #define CCN_SET_ASM 0
369 #define CCN_SHIFT_RIGHT_ASM 1
370 #define CCAES_ARM_ASM 1
371 #define CCAES_INTEL_ASM 0
372 #define CCAES_MUX 0 // On 64bit SoC, asm is much faster than HW
373 #define CCN_USE_BUILTIN_CLZ 1
374 #define CCSHA1_VNG_INTEL 0
375 #define CCSHA2_VNG_INTEL 0
376 #define CCSHA1_VNG_ARMV7NEON 1 // reused this to avoid making change to xcode project, put arm64 assembly code with armv7 code
377 #define CCSHA2_VNG_ARMV7NEON 1
378 #define CCSHA256_ARMV6M_ASM 0
381 #elif (defined(__x86_64__) || defined(__i386__)) && __clang__ && CC_USE_ASM
382 #define CCN_DEDICATED_SQR 1
383 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
384 /* These assembly routines only work for a single CCN_UNIT_SIZE. */
385 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8) || (defined(__i386__) && CCN_UNIT_SIZE == 4)
386 #define CCN_ADD_ASM 1
387 #define CCN_SUB_ASM 1
388 #define CCN_MUL_ASM 1
390 #define CCN_ADD_ASM 0
391 #define CCN_SUB_ASM 0
392 #define CCN_MUL_ASM 0
395 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8)
396 #define CCN_CMP_ASM 1
398 #define CCN_SHIFT_RIGHT_ASM 1
400 #define CCN_CMP_ASM 0
402 #define CCN_SHIFT_RIGHT_ASM 0
405 #define CCN_ADDMUL1_ASM 0
406 #define CCN_MUL1_ASM 0
407 #define CCN_ADD1_ASM 0
408 #define CCN_SUB1_ASM 0
409 #define CCN_SET_ASM 0
410 #define CCAES_ARM_ASM 0
411 #define CCAES_INTEL_ASM 1
413 #define CCN_USE_BUILTIN_CLZ 0
414 #define CCSHA1_VNG_INTEL 1
415 #define CCSHA2_VNG_INTEL 1
416 #define CCSHA1_VNG_ARMV7NEON 0
417 #define CCSHA2_VNG_ARMV7NEON 0
418 #define CCSHA256_ARMV6M_ASM 0
420 //-(4) disable assembly
422 #if CCN_UINT128_SUPPORT_FOR_64BIT_ARCH
423 #define CCN_DEDICATED_SQR 1
425 #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
427 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
428 #define CCN_ADD_ASM 0
429 #define CCN_SUB_ASM 0
430 #define CCN_MUL_ASM 0
431 #define CCN_ADDMUL1_ASM 0
432 #define CCN_MUL1_ASM 0
433 #define CCN_CMP_ASM 0
434 #define CCN_ADD1_ASM 0
435 #define CCN_SUB1_ASM 0
437 #define CCN_SET_ASM 0
438 #define CCN_SHIFT_RIGHT_ASM 0
439 #define CCAES_ARM_ASM 0
440 #define CCAES_INTEL_ASM 0
442 #define CCN_USE_BUILTIN_CLZ 0
443 #define CCSHA1_VNG_INTEL 0
444 #define CCSHA2_VNG_INTEL 0
445 #define CCSHA1_VNG_ARMV7NEON 0
446 #define CCSHA2_VNG_ARMV7NEON 0
447 #define CCSHA256_ARMV6M_ASM 0
451 #define CC_INLINE static inline
454 #define CC_NORETURN __attribute__((__noreturn__))
455 #define CC_NOTHROW __attribute__((__nothrow__))
456 #define CC_NONNULL(N) __attribute__((__nonnull__ N))
457 #define CC_NONNULL4 CC_NONNULL((4))
458 #define CC_NONNULL_ALL __attribute__((__nonnull__))
459 #define CC_SENTINEL __attribute__((__sentinel__))
460 #define CC_CONST __attribute__((__const__))
461 #define CC_PURE __attribute__((__pure__))
462 #define CC_WARN_RESULT __attribute__((__warn_unused_result__))
463 #define CC_MALLOC __attribute__((__malloc__))
464 #define CC_UNUSED __attribute__((unused))
465 #else /* !__GNUC__ */
469 #define CC_NONNULL(N)
477 #define CC_NONNULL_ALL
485 #define CC_WARN_RESULT
488 #endif /* !__GNUC__ */
490 // Enable FIPSPOST function tracing only when supported. */
491 #ifdef CORECRYPTO_POST_TRACE
492 #define CC_FIPSPOST_TRACE 1
494 #define CC_FIPSPOST_TRACE 0
497 #endif /* _CORECRYPTO_CC_CONFIG_H_ */