]>
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__)
262 /* For corecrypto kext, CC_STATIC should be undefined */
266 #if !defined(CC_USE_HEAP_FOR_WORKSPACE)
267 #if CC_USE_S3 || CC_USE_SEPROM || CC_RTKITROM
268 #define CC_USE_HEAP_FOR_WORKSPACE 0
270 #define CC_USE_HEAP_FOR_WORKSPACE 1
274 /* memset_s is only available in few target */
275 #if CC_USE_SEPROM || defined(__CC_ARM) \
276 || defined(__hexagon__) || CC_EFI
277 #define CC_HAS_MEMSET_S 0
279 #define CC_HAS_MEMSET_S 1
282 // Include target conditionals if available.
283 #if defined(__has_include) /* portability */
284 #if __has_include(<TargetConditionals.h>)
285 #include <TargetConditionals.h>
286 #endif /* __has_include(<TargetConditionals.h>) */
287 #endif /* defined(__has_include) */
289 // Disable RSA Keygen on iBridge
290 #if defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE && CC_KERNEL
291 #define CC_DISABLE_RSAKEYGEN 1 /* for iBridge */
293 #define CC_DISABLE_RSAKEYGEN 0 /* default */
296 // see rdar://problem/26636018
297 #if (CCN_UNIT_SIZE == 8) && !( defined(_MSC_VER) && defined(__clang__))
298 #define CCEC25519_CURVE25519_64BIT 1
300 #define CCEC25519_CURVE25519_64BIT 0
303 //- functions implemented in assembly ------------------------------------------
304 //this the list of corecrypto clients that use assembly and the clang compiler
305 #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
306 #warning "You are using the default corecrypto configuration, assembly optimizations may not be available for your platform"
309 // Enable assembler in Linux if CC_LINUX_ASM is defined
310 #if CC_LINUX && defined(CC_LINUX_ASM) && CC_LINUX_ASM
314 // Use this macro to strictly disable assembly regardless of cpu/os/compiler/etc.
315 // Our assembly code is not gcc compatible. Clang defines the __GNUC__ macro as well.
316 #if !defined(CC_USE_ASM)
317 #if defined(_WIN32) || CC_EFI || CC_BASEBAND || CC_XNU_KERNEL_PRIVATE || (defined(__GNUC__) && !defined(__clang__)) || defined(__ANDROID_API__) || CC_LINUX
325 #if defined(_ARM_ARCH_7) && __clang__ && CC_USE_ASM
326 #define CCN_DEDICATED_SQR CC_SMALL_CODE
327 #define CCN_MUL_KARATSUBA 0 // no performance improvement
328 #define CCN_ADD_ASM 1
329 #define CCN_SUB_ASM 1
330 #define CCN_MUL_ASM 0
331 #define CCN_ADDMUL1_ASM 1
332 #define CCN_MUL1_ASM 1
333 #define CCN_CMP_ASM 1
334 #define CCN_ADD1_ASM 1
335 #define CCN_SUB1_ASM 1
337 #define CCN_SET_ASM 1
338 #define CCN_SHIFT_RIGHT_ASM 1
339 #if defined(__ARM_NEON__)
340 #define CCN_SHIFT_LEFT_ASM 1
342 #define CCN_SHIFT_LEFT_ASM 0
344 #define CCN_MOD_224_ASM 1
345 #define CCN_MULMOD_256_ASM 1
346 #define CCAES_ARM_ASM 1
347 #define CCAES_INTEL_ASM 0
348 #if CC_KERNEL || CC_USE_L4 || CC_IBOOT || CC_RTKIT || CC_RTKITROM || CC_USE_SEPROM || CC_USE_S3
353 #define CCN_USE_BUILTIN_CLZ 1
354 #define CCSHA1_VNG_INTEL 0
355 #define CCSHA2_VNG_INTEL 0
357 #if defined(__ARM_NEON__) || CC_KERNEL
358 #define CCSHA1_VNG_ARM 1
359 #define CCSHA2_VNG_ARM 1
360 #else /* !defined(__ARM_NEON__) */
361 #define CCSHA1_VNG_ARM 0
362 #define CCSHA2_VNG_ARM 0
363 #endif /* !defined(__ARM_NEON__) */
364 #define CCSHA256_ARMV6M_ASM 0
366 #define CC_ACCELERATECRYPTO 1
369 #elif defined(__arm64__) && __clang__ && CC_USE_ASM
370 #define CCN_DEDICATED_SQR CC_SMALL_CODE
371 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
372 #define CCN_ADD_ASM 1
373 #define CCN_SUB_ASM 1
374 #define CCN_MUL_ASM 1
375 #define CCN_ADDMUL1_ASM 0
376 #define CCN_MUL1_ASM 0
377 #define CCN_CMP_ASM 1
378 #define CCN_ADD1_ASM 0
379 #define CCN_SUB1_ASM 0
381 #define CCN_SET_ASM 0
382 #define CCN_SHIFT_RIGHT_ASM 1
383 #define CCN_SHIFT_LEFT_ASM 1
384 #define CCN_MOD_224_ASM 0
385 #define CCN_MULMOD_256_ASM 1
386 #define CCAES_ARM_ASM 1
387 #define CCAES_INTEL_ASM 0
388 #define CCAES_MUX 0 // On 64bit SoC, asm is much faster than HW
389 #define CCN_USE_BUILTIN_CLZ 1
390 #define CCSHA1_VNG_INTEL 0
391 #define CCSHA2_VNG_INTEL 0
392 #define CCSHA1_VNG_ARM 1
393 #define CCSHA2_VNG_ARM 1
394 #define CCSHA256_ARMV6M_ASM 0
396 #define CC_ACCELERATECRYPTO 1
399 #elif (defined(__x86_64__) || defined(__i386__)) && __clang__ && CC_USE_ASM
400 #define CCN_DEDICATED_SQR 1
401 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
402 /* These assembly routines only work for a single CCN_UNIT_SIZE. */
403 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8) || (defined(__i386__) && CCN_UNIT_SIZE == 4)
404 #define CCN_ADD_ASM 1
405 #define CCN_SUB_ASM 1
406 #define CCN_MUL_ASM 1
408 #define CCN_ADD_ASM 0
409 #define CCN_SUB_ASM 0
410 #define CCN_MUL_ASM 0
413 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8)
414 #define CCN_CMP_ASM 1
416 #define CCN_SHIFT_RIGHT_ASM 1
417 #define CCN_SHIFT_LEFT_ASM 1
419 #define CCN_CMP_ASM 0
421 #define CCN_SHIFT_RIGHT_ASM 0
422 #define CCN_SHIFT_LEFT_ASM 0
425 #define CCN_MOD_224_ASM 0
426 #define CCN_MULMOD_256_ASM 0
427 #define CCN_ADDMUL1_ASM 0
428 #define CCN_MUL1_ASM 0
429 #define CCN_ADD1_ASM 0
430 #define CCN_SUB1_ASM 0
431 #define CCN_SET_ASM 0
432 #define CCAES_ARM_ASM 0
433 #define CCAES_INTEL_ASM 1
435 #define CCN_USE_BUILTIN_CLZ 0
436 #define CCSHA1_VNG_INTEL 1
437 #define CCSHA2_VNG_INTEL 1
438 #define CCSHA1_VNG_ARM 0
439 #define CCSHA2_VNG_ARM 0
440 #define CCSHA256_ARMV6M_ASM 0
442 #define CC_ACCELERATECRYPTO 1
444 //-(4) disable assembly
446 #if CCN_UINT128_SUPPORT_FOR_64BIT_ARCH
447 #define CCN_DEDICATED_SQR 1
449 #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
451 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
452 #define CCN_ADD_ASM 0
453 #define CCN_SUB_ASM 0
454 #define CCN_MUL_ASM 0
455 #define CCN_ADDMUL1_ASM 0
456 #define CCN_MUL1_ASM 0
457 #define CCN_CMP_ASM 0
458 #define CCN_ADD1_ASM 0
459 #define CCN_SUB1_ASM 0
461 #define CCN_SET_ASM 0
462 #define CCN_SHIFT_RIGHT_ASM 0
463 #define CCN_SHIFT_LEFT_ASM 0
464 #define CCN_MOD_224_ASM 0
465 #define CCN_MULMOD_256_ASM 0
466 #define CCAES_ARM_ASM 0
467 #define CCAES_INTEL_ASM 0
469 #define CCN_USE_BUILTIN_CLZ 0
470 #define CCSHA1_VNG_INTEL 0
471 #define CCSHA2_VNG_INTEL 0
472 #define CCSHA1_VNG_ARM 0
473 #define CCSHA2_VNG_ARM 0
474 #define CCSHA256_ARMV6M_ASM 0
476 #define CC_ACCELERATECRYPTO 0
480 #define CC_INLINE static inline
483 #define CC_NORETURN __attribute__((__noreturn__))
484 #define CC_NOTHROW __attribute__((__nothrow__))
485 #define CC_NONNULL(N) __attribute__((__nonnull__ N))
486 #define CC_NONNULL4 CC_NONNULL((4))
487 #define CC_NONNULL_ALL __attribute__((__nonnull__))
488 #define CC_SENTINEL __attribute__((__sentinel__))
489 // Only apply the `CC_CONST` attribute to functions with no side-effects where the output is a strict function of pass by value input vars with no exterior side-effects.
490 // Specifically, do not apply CC_CONST if the function has any arguments that are pointers (directly, or indirectly)
491 #define CC_CONST __attribute__((__const__))
492 #define CC_PURE __attribute__((__pure__))
493 #define CC_WARN_RESULT __attribute__((__warn_unused_result__))
494 #define CC_MALLOC_CLEAR __attribute__((__malloc__))
495 #define CC_UNUSED __attribute__((unused))
496 #else /* !__GNUC__ */
500 #define CC_NONNULL(N)
508 #define CC_NONNULL_ALL
516 #define CC_WARN_RESULT
518 #define CC_MALLOC_CLEAR
519 #endif /* !__GNUC__ */
522 // Bridge differences between MachO and ELF compiler/assemblers. */
525 #define CC_ASM_SECTION_CONST .rodata
526 #define CC_ASM_PRIVATE_EXTERN .hidden
527 #define CC_C_LABEL(_sym) _sym
528 #else /* !CC_LINUX */
529 #define CC_ASM_SECTION_CONST .const
530 #define CC_ASM_PRIVATE_EXTERN .private_extern
531 #define CC_C_LABEL(_sym) _##_sym
532 #endif /* !CC_LINUX */
533 #endif /* CC_USE_ASM */
536 // Enable FIPSPOST function tracing only when supported. */
537 #ifdef CORECRYPTO_POST_TRACE
538 #define CC_FIPSPOST_TRACE 1
540 #define CC_FIPSPOST_TRACE 0
543 #endif /* _CORECRYPTO_CC_CONFIG_H_ */