]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/cc_config.h
044c8e16898af676b8470eb47d049945115c9f83
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 //this macro is used to turn on/off usage of transparent union in corecrypto
56 //it should be commented out in corecrypto and be used only by the software that use corecrypto
57 //#define CORECRYPTO_DONOT_USE_TRANSPARENT_UNION
58 #if defined(__cplusplus)
59 #define CORECRYPTO_USE_TRANSPARENT_UNION 0
60 #elif defined(CORECRYPTO_DONOT_USE_TRANSPARENT_UNION)
61 #define CORECRYPTO_USE_TRANSPARENT_UNION !CORECRYPTO_DONOT_USE_TRANSPARENT_UNION
63 #define CORECRYPTO_USE_TRANSPARENT_UNION 1
66 #if (defined(DEBUG) && (DEBUG)) || defined(_DEBUG) //MSVC defines _DEBUG
67 /* CC_DEBUG is already used in CommonCrypto */
68 #define CORECRYPTO_DEBUG 1
70 #define CORECRYPTO_DEBUG 0
73 // This macro can be used to enable prints when a condition in the macro "cc_require"
74 // is false. This is especially useful to confirm that negative testing fails
75 // at the intended location
76 #define CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS 0
78 #if defined(KERNEL) && (KERNEL)
79 #define CC_KERNEL 1 // KEXT, XNU repo or kernel components such as AppleKeyStore
84 #if defined(__linux__) || CORECRYPTO_SIMULATE_POSIX_ENVIRONMENT
90 #if defined(USE_L4) && (USE_L4)
96 #if defined(RTKIT) && (RTKIT)
102 #if defined(USE_SEPROM) && (USE_SEPROM)
103 #define CC_USE_SEPROM 1
105 #define CC_USE_SEPROM 0
108 #if defined(USE_S3) && (USE_S3)
114 #if (defined(ICE_FEATURES_ENABLED)) || (defined(MAVERICK) && (MAVERICK))
115 #define CC_BASEBAND 1
117 #define CC_BASEBAND 0
120 #if defined(EFI) && (EFI)
126 #if defined(IBOOT) && (IBOOT)
132 // Defined by the XNU build scripts
133 // Applies to code embedded in XNU but NOT to the kext
134 #if defined(XNU_KERNEL_PRIVATE)
135 #define CC_XNU_KERNEL_PRIVATE 1
137 #define CC_XNU_KERNEL_PRIVATE 0
140 // handle unaligned data, if the cpu cannot. Currently for gladman AES and the C version of the SHA256
141 #define CC_HANDLE_UNALIGNED_DATA CC_BASEBAND
143 // BaseBand configuration
147 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
148 #if defined(ENDIAN_LITTLE) || (defined(__arm__) && !defined(__BIG_ENDIAN))
149 #define __LITTLE_ENDIAN__
150 #elif !defined(ENDIAN_BIG) && !defined(__BIG_ENDIAN)
151 #error Baseband endianess not defined.
153 #define AESOPT_ENDIAN_NO_FILE
157 #define CCN_UNIT_SIZE 4 // 32 bits
159 // -- External function
160 #define assert ASSERT // sanity
163 // Ignore irrelevant warnings after verification
164 // #1254-D: arithmetic on pointer to void or function type
165 // #186-D: pointless comparison of unsigned integer with zero
166 // #546-D: transfer of control bypasses initialization of
168 #pragma diag_suppress 186, 1254,546
169 #elif defined(__GNUC__)
170 // warning: pointer of type 'void *' used in arithmetic
171 #pragma GCC diagnostic ignored "-Wpointer-arith"
173 #endif // CC_BASEBAND
175 //CC_XNU_KERNEL_AVAILABLE indicates the availibity of XNU kernel functions,
176 //like what we have on OSX, iOS, tvOS, Watch OS
177 #if defined(__APPLE__) && defined(__MACH__)
178 #define CC_XNU_KERNEL_AVAILABLE 1
180 #define CC_XNU_KERNEL_AVAILABLE 0
183 //arm arch64 definition for gcc
184 #if defined(__GNUC__) && defined(__aarch64__) && !defined(__arm64__)
188 #if !defined(CCN_UNIT_SIZE)
189 #if defined(__arm64__) || defined(__x86_64__) || defined(_WIN64)
190 #define CCN_UNIT_SIZE 8
191 #elif defined(__arm__) || defined(__i386__) || defined(_WIN32)
192 #define CCN_UNIT_SIZE 4
194 #error undefined architecture
196 #endif /* !defined(CCN_UNIT_SIZE) */
199 //this allows corecrypto Windows development using xcode
200 #if defined(CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT)
201 #if CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT && CC_XNU_KERNEL_AVAILABLE && CORECRYPTO_DEBUG
203 #define CC_USE_HEAP_FOR_WORKSPACE 1
204 #if (CCN_UNIT_SIZE==8)
205 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 0
207 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1
212 #if !defined(CCN_UINT128_SUPPORT_FOR_64BIT_ARCH)
213 #if defined(_WIN64) && defined(_WIN32) && (CCN_UNIT_SIZE==8)
214 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 0
215 #elif defined(_WIN32)
216 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1//should not be a problem
218 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1
222 #if defined(_MSC_VER)
223 #if defined(__clang__)
224 #define CC_ALIGNED(x) __attribute__ ((aligned(x))) //clang compiler
226 #define CC_ALIGNED(x) __declspec(align(x)) //MS complier
229 #if __clang__ || CCN_UNIT_SIZE==8
230 #define CC_ALIGNED(x) __attribute__ ((aligned(x)))
232 #define CC_ALIGNED(x) __attribute__ ((aligned((x)>8?8:(x))))
237 //this is copied from <arm/arch.h>, because <arm/arch.h> is not available on SEPROM environment
238 #if defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7S__) || defined (__ARM_ARCH_7F__) || defined (__ARM_ARCH_7K__)
242 #if defined(__ARM_ARCH_6M__) || defined(__TARGET_ARCH_6S_M) || defined (__armv6m__)
247 #if defined(__arm64__) || defined(__arm__)
250 #elif defined(__x86_64__) || defined(__i386__)
255 #if CC_USE_L4 || CC_USE_S3
256 /* No dynamic linking allowed in L4, e.g. avoid nonlazy symbols */
257 /* For corecrypto kext, CC_STATIC should be undefined */
261 #if !defined(CC_USE_HEAP_FOR_WORKSPACE)
262 #if CC_USE_S3 || CC_USE_SEPROM || CC_RTKIT
263 #define CC_USE_HEAP_FOR_WORKSPACE 0
265 #define CC_USE_HEAP_FOR_WORKSPACE 1
269 /* memset_s is only available in few target */
270 #if CC_USE_SEPROM || defined(__CC_ARM) \
271 || defined(__hexagon__) || CC_EFI
272 #define CC_HAS_MEMSET_S 0
274 #define CC_HAS_MEMSET_S 1
277 // Include target conditionals if available.
278 #if defined(__has_include) /* portability */
279 #if __has_include(<TargetConditionals.h>)
280 #include <TargetConditionals.h>
281 #endif /* __has_include(<TargetConditionals.h>) */
282 #endif /* defined(__has_include) */
284 // Disable RSA Keygen on iBridge
285 #if defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE && CC_KERNEL
286 #define CC_DISABLE_RSAKEYGEN 1 /* for iBridge */
288 #define CC_DISABLE_RSAKEYGEN 0 /* default */
291 //- functions implemented in assembly ------------------------------------------
292 //this the list of corecrypto clients that use assembly and the clang compiler
293 #if !(CC_XNU_KERNEL_AVAILABLE || CC_KERNEL || CC_USE_L4 || CC_IBOOT || CC_RTKIT || CC_USE_SEPROM || CC_USE_S3) && !defined(_WIN32) && CORECRYPTO_DEBUG
294 #warning "You are using the default corecrypto configuration, assembly optimizations may not be available for your platform"
297 // Use this macro to strictly disable assembly regardless of cpu/os/compiler/etc.
298 // Our assembly code is not gcc compatible. Clang defines the __GNUC__ macro as well.
299 #if !defined(CC_USE_ASM)
300 #if defined(_WIN32) || CC_EFI || CC_BASEBAND || CC_XNU_KERNEL_PRIVATE || (defined(__GNUC__) && !defined(__clang__)) || defined(__ANDROID_API__)
308 #if defined(_ARM_ARCH_7) && __clang__ && CC_USE_ASM
309 #define CCN_DEDICATED_SQR 1
310 #define CCN_MUL_KARATSUBA 0 // no performance improvement
311 #define CCN_ADD_ASM 1
312 #define CCN_SUB_ASM 1
313 #define CCN_MUL_ASM 0
314 #define CCN_ADDMUL1_ASM 1
315 #define CCN_MUL1_ASM 1
316 #define CCN_CMP_ASM 1
317 #define CCN_ADD1_ASM 0
318 #define CCN_SUB1_ASM 0
320 #define CCN_SET_ASM 1
321 #define CCN_SHIFT_RIGHT_ASM 1
322 #define CCAES_ARM_ASM 1
323 #define CCAES_INTEL_ASM 0
324 #if CC_KERNEL || CC_USE_L4 || CC_IBOOT || CC_RTKIT || CC_USE_SEPROM || CC_USE_S3
329 #define CCN_USE_BUILTIN_CLZ 1
330 #define CCSHA1_VNG_INTEL 0
331 #define CCSHA2_VNG_INTEL 0
333 #if defined(__ARM_NEON__) || CC_KERNEL
334 #define CCSHA1_VNG_ARMV7NEON 1
335 #define CCSHA2_VNG_ARMV7NEON 1
336 #else /* !defined(__ARM_NEON__) */
337 #define CCSHA1_VNG_ARMV7NEON 0
338 #define CCSHA2_VNG_ARMV7NEON 0
339 #endif /* !defined(__ARM_NEON__) */
340 #define CCSHA256_ARMV6M_ASM 0
343 #elif defined(__arm64__) && __clang__ && CC_USE_ASM
344 #define CCN_DEDICATED_SQR 1
345 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
346 #define CCN_ADD_ASM 1
347 #define CCN_SUB_ASM 1
348 #define CCN_MUL_ASM 1
349 #define CCN_ADDMUL1_ASM 0
350 #define CCN_MUL1_ASM 0
351 #define CCN_CMP_ASM 1
352 #define CCN_ADD1_ASM 0
353 #define CCN_SUB1_ASM 0
355 #define CCN_SET_ASM 0
356 #define CCN_SHIFT_RIGHT_ASM 1
357 #define CCAES_ARM_ASM 1
358 #define CCAES_INTEL_ASM 0
359 #define CCAES_MUX 0 // On 64bit SoC, asm is much faster than HW
360 #define CCN_USE_BUILTIN_CLZ 1
361 #define CCSHA1_VNG_INTEL 0
362 #define CCSHA2_VNG_INTEL 0
363 #define CCSHA1_VNG_ARMV7NEON 1 // reused this to avoid making change to xcode project, put arm64 assembly code with armv7 code
364 #define CCSHA2_VNG_ARMV7NEON 1
365 #define CCSHA256_ARMV6M_ASM 0
368 #elif (defined(__x86_64__) || defined(__i386__)) && __clang__ && CC_USE_ASM
369 #define CCN_DEDICATED_SQR 1
370 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
371 /* These assembly routines only work for a single CCN_UNIT_SIZE. */
372 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8) || (defined(__i386__) && CCN_UNIT_SIZE == 4)
373 #define CCN_ADD_ASM 1
374 #define CCN_SUB_ASM 1
375 #define CCN_MUL_ASM 1
377 #define CCN_ADD_ASM 0
378 #define CCN_SUB_ASM 0
379 #define CCN_MUL_ASM 0
382 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8)
383 #define CCN_CMP_ASM 1
385 #define CCN_SHIFT_RIGHT_ASM 1
387 #define CCN_CMP_ASM 0
389 #define CCN_SHIFT_RIGHT_ASM 0
392 #define CCN_ADDMUL1_ASM 0
393 #define CCN_MUL1_ASM 0
394 #define CCN_ADD1_ASM 0
395 #define CCN_SUB1_ASM 0
396 #define CCN_SET_ASM 0
397 #define CCAES_ARM_ASM 0
398 #define CCAES_INTEL_ASM 1
400 #define CCN_USE_BUILTIN_CLZ 0
401 #define CCSHA1_VNG_INTEL 1
402 #define CCSHA2_VNG_INTEL 1
403 #define CCSHA1_VNG_ARMV7NEON 0
404 #define CCSHA2_VNG_ARMV7NEON 0
405 #define CCSHA256_ARMV6M_ASM 0
407 //-(4) disable assembly
409 #if CCN_UINT128_SUPPORT_FOR_64BIT_ARCH
410 #define CCN_DEDICATED_SQR 1
412 #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
414 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
415 #define CCN_ADD_ASM 0
416 #define CCN_SUB_ASM 0
417 #define CCN_MUL_ASM 0
418 #define CCN_ADDMUL1_ASM 0
419 #define CCN_MUL1_ASM 0
420 #define CCN_CMP_ASM 0
421 #define CCN_ADD1_ASM 0
422 #define CCN_SUB1_ASM 0
424 #define CCN_SET_ASM 0
425 #define CCN_SHIFT_RIGHT_ASM 0
426 #define CCAES_ARM_ASM 0
427 #define CCAES_INTEL_ASM 0
429 #define CCN_USE_BUILTIN_CLZ 0
430 #define CCSHA1_VNG_INTEL 0
431 #define CCSHA2_VNG_INTEL 0
432 #define CCSHA1_VNG_ARMV7NEON 0
433 #define CCSHA2_VNG_ARMV7NEON 0
434 #define CCSHA256_ARMV6M_ASM 0
438 #define CC_INLINE static inline
440 #if CORECRYPTO_USE_TRANSPARENT_UNION
441 // Non null for transparent unions is ambiguous and cause problems
442 // for most tools (GCC and others: 23919290).
443 #define CC_NONNULL_TU(N)
445 #define CC_NONNULL_TU(N) CC_NONNULL(N)
449 #define CC_NORETURN __attribute__((__noreturn__))
450 #define CC_NOTHROW __attribute__((__nothrow__))
451 #define CC_NONNULL(N) __attribute__((__nonnull__ N))
452 #define CC_NONNULL1 __attribute__((__nonnull__(1)))
453 #define CC_NONNULL2 __attribute__((__nonnull__(2)))
454 #define CC_NONNULL3 __attribute__((__nonnull__(3)))
455 #define CC_NONNULL4 __attribute__((__nonnull__(4)))
456 #define CC_NONNULL5 __attribute__((__nonnull__(5)))
457 #define CC_NONNULL6 __attribute__((__nonnull__(6)))
458 #define CC_NONNULL7 __attribute__((__nonnull__(7)))
459 #define CC_NONNULL_ALL __attribute__((__nonnull__))
460 #define CC_SENTINEL __attribute__((__sentinel__))
461 #define CC_CONST __attribute__((__const__))
462 #define CC_PURE __attribute__((__pure__))
463 #define CC_WARN_RESULT __attribute__((__warn_unused_result__))
464 #define CC_MALLOC __attribute__((__malloc__))
465 #define CC_UNUSED __attribute__((unused))
466 #else /* !__GNUC__ */
470 #define CC_NONNULL(N)
490 #define CC_NONNULL_ALL
498 #define CC_WARN_RESULT
501 #endif /* !__GNUC__ */
503 // Enable FIPSPOST function tracing only when supported. */
504 #ifdef CORECRYPTO_POST_TRACE
505 #define CC_FIPSPOST_TRACE 1
507 #define CC_FIPSPOST_TRACE 0
510 #endif /* _CORECRYPTO_CC_CONFIG_H_ */