xref: /xnu-10002.61.3/EXTERNAL_HEADERS/corecrypto/cc_config.h (revision 0f4c859e951fba394238ab619495c4e1d54d0f34)
1 /* Copyright (c) (2010-2021) Apple Inc. All rights reserved.
2  *
3  * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which
4  * is contained in the License.txt file distributed with corecrypto) and only to
5  * people who accept that license. IMPORTANT:  Any license rights granted to you by
6  * Apple Inc. (if any) are limited to internal use within your organization only on
7  * devices and computers you own or control, for the sole purpose of verifying the
8  * security characteristics and correct functioning of the Apple Software.  You may
9  * not, directly or indirectly, redistribute the Apple Software or any portions thereof.
10  */
11 
12 #ifndef _CORECRYPTO_CC_CONFIG_H_
13 #define _CORECRYPTO_CC_CONFIG_H_
14 
15 /* A word about configuration macros:
16 
17     Conditional configuration macros specific to corecrypto should be named CORECRYPTO_xxx
18     or CCxx_yyy and be defined to be either 0 or 1 in this file. You can add an
19     #ifndef #error construct at the end of this file to make sure it's always defined.
20 
21     They should always be tested using the #if directive, never the #ifdef directive.
22 
23     No other conditional macros shall ever be used (except in this file)
24 
25     Configuration Macros that are defined outside of corecrypto (eg: KERNEL, DEBUG, ...)
26     shall only be used in this file to define CCxxx macros.
27 
28     External macros should be assumed to be either undefined, defined with no value,
29     or defined as true or false. We shall strive to build with -Wundef whenever possible,
30     so the following construct should be used to test external macros in this file:
31 
32          #if defined(DEBUG) && (DEBUG)
33          #define CORECRYPTO_DEBUG 1
34          #else
35          #define CORECRYPTO_DEBUG 0
36          #endif
37 
38 
39     It is acceptable to define a conditional CC_xxxx macro in an implementation file,
40     to be used only in this file.
41 
42     The current code is not guaranteed to follow those rules, but should be fixed to.
43 
44     Corecrypto requires GNU and C99 compatibility.
45     Typically enabled by passing --gnu --c99 to the compiler (eg. armcc)
46 
47 */
48 
49 #if !defined(__has_feature)
50     #define __has_feature(FEATURE) 0
51 #endif
52 
53 #if !defined(__has_attribute)
54     #define __has_attribute(ATTR) 0
55 #endif
56 
57 //Do not set this macros to 1, unless you are developing/testing for Linux under macOS
58 #define CORECRYPTO_SIMULATE_POSIX_ENVIRONMENT    0
59 
60 //Do not set these macros to 1, unless you are developing/testing for Windows under macOS
61 #define CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT 0
62 #define CORECRYPTO_HACK_FOR_WINDOWS_DEVELOPMENT 0
63 
64 #if (defined(DEBUG) && (DEBUG)) || defined(_DEBUG) //MSVC defines _DEBUG
65 /* CC_DEBUG is already used in CommonCrypto */
66  #define CORECRYPTO_DEBUG 1
67 #else
68  #define CORECRYPTO_DEBUG 0
69 #endif
70 
71 // Enable specific configurations only relevant in test builds
72 #if defined(CORECRYPTO_BUILT_FOR_TESTING) && CORECRYPTO_BUILT_FOR_TESTING
73   #define CC_BUILT_FOR_TESTING 1
74 #else
75   #define CC_BUILT_FOR_TESTING 0
76 #endif
77 
78 // This macro can be used to enable prints when a condition in the macro "cc_require"
79 // is false. This is especially useful to confirm that negative testing fails
80 // at the intended location
81 #define CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS 0
82 
83 
84 #if defined(KERNEL) && (KERNEL)
85  #define CC_KERNEL 1 // KEXT, XNU repo or kernel components such as AppleKeyStore
86 #else
87  #define CC_KERNEL 0
88 #endif
89 
90 #if defined(LINUX_SGX) && (LINUX_SGX)
91  #define CC_SGX 1
92 #else
93  #define CC_SGX 0
94 #endif
95 
96 #if (defined(__linux__) && !(CC_SGX)) || CORECRYPTO_SIMULATE_POSIX_ENVIRONMENT
97  #define CC_LINUX 1
98 #else
99  #define CC_LINUX 0
100 #endif
101 
102 #if defined(USE_L4) && (USE_L4)
103  #define CC_USE_L4 1
104 #else
105  #define CC_USE_L4 0
106 #endif
107 
108 #if defined(RTKIT) && (RTKIT)
109  #define CC_RTKIT 1
110 #else
111  #define CC_RTKIT 0
112 #endif
113 
114 #if defined(RTKITROM) && (RTKITROM)
115 #define CC_RTKITROM 1
116 #else
117 #define CC_RTKITROM 0
118 #endif
119 
120 #if defined(USE_SEPROM) && (USE_SEPROM)
121  #define CC_USE_SEPROM 1
122 #else
123  #define CC_USE_SEPROM 0
124 #endif
125 
126 #if (defined(ICE_FEATURES_ENABLED)) || (defined(MAVERICK) && (MAVERICK))
127  #define CC_BASEBAND 1
128 #else
129  #define CC_BASEBAND 0
130 #endif
131 
132 #if defined(EFI) && (EFI)
133  #define CC_EFI 1
134 #else
135  #define CC_EFI 0
136 #endif
137 
138 #if defined(IBOOT) && (IBOOT)
139  #define CC_IBOOT 1
140 #else
141  #define CC_IBOOT 0
142 #endif
143 
144 // Include target conditionals if available.
145 #if defined(__has_include)     /* portability */
146 #if __has_include(<TargetConditionals.h>)
147 #include <TargetConditionals.h>
148 #endif /* __has_include(<TargetConditionals.h>) */
149 #endif /* defined(__has_include) */
150 
151 #if defined(TARGET_OS_DRIVERKIT)
152  #define CC_DRIVERKIT TARGET_OS_DRIVERKIT
153 #else
154  #define CC_DRIVERKIT 0
155 #endif
156 
157 #if defined(TARGET_OS_BRIDGE)
158  #define CC_BRIDGE TARGET_OS_BRIDGE
159 #else
160  #define CC_BRIDGE 0
161 #endif
162 
163 // Check for open source builds
164 
165 // Defined by the XNU build scripts
166 // Applies to code embedded in XNU but NOT to the kext
167 #if defined(XNU_KERNEL_PRIVATE)
168  #define CC_XNU_KERNEL_PRIVATE 1
169 #else
170  #define CC_XNU_KERNEL_PRIVATE 0
171 #endif
172 
173 // handle unaligned data, if the cpu cannot. Currently for gladman AES and the C version of the SHA256
174 #define CC_HANDLE_UNALIGNED_DATA CC_BASEBAND
175 
176 // BaseBand configuration
177 #if CC_BASEBAND
178 
179 // -- ENDIANESS
180 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
181  #if defined(ENDIAN_LITTLE) || (defined(__arm__) && !defined(__BIG_ENDIAN))
182   #define __LITTLE_ENDIAN__
183  #elif !defined(ENDIAN_BIG) && !defined(__BIG_ENDIAN)
184   #error Baseband endianess not defined.
185  #endif
186  #define AESOPT_ENDIAN_NO_FILE
187 #endif
188 
189 #if !defined(__x86_64__) && !defined(__arm64__)
190 // -- Architecture
191  #define CCN_UNIT_SIZE  4 // 32 bits
192 #endif
193 
194 // -- External function
195  #define assert ASSERT   // sanity
196 
197 // -- Warnings
198 // Ignore irrelevant warnings after verification
199 // #186-D: pointless comparison of unsigned integer with zero
200 // #546-D: transfer of control bypasses initialization of
201  #ifdef __arm__
202   #pragma diag_suppress 186, 546
203  #endif // __arm__
204 #define CC_SMALL_CODE 1
205 
206 #endif // CC_BASEBAND
207 
208 #if CC_RTKIT || CC_RTKITROM
209 #define CC_SMALL_CODE 1
210 #endif
211 
212 
213 #ifndef CC_SMALL_CODE
214 #define CC_SMALL_CODE 0
215 #endif
216 
217 #ifndef CC_DARWIN
218  //CC_DARWIN indicates the availability of XNU kernel functions,
219  //like what we have on OSX, iOS, tvOS, Watch OS
220  #if (CC_USE_L4 || CC_RTKIT || CC_RTKITROM || CC_USE_SEPROM || CC_EFI || CC_LINUX || defined(_WIN32) || CC_BASEBAND || CC_SGX)
221   #define CC_DARWIN 0
222  #else
223   #define CC_DARWIN 1
224  #endif
225 #endif
226 
227 //arm arch64 definition for gcc
228 #if defined(__GNUC__) && defined(__aarch64__) && !defined(__arm64__)
229     #define __arm64__
230 #endif
231 
232 #if !defined(CCN_UNIT_SIZE)
233  #if defined(__arm64__) || defined(__x86_64__)  || defined(_WIN64)
234   #define CCN_UNIT_SIZE  8
235  #elif defined(__arm__) || defined(__i386__) || defined(_WIN32)
236   #define CCN_UNIT_SIZE  4
237  #else
238   #error undefined architecture
239  #endif
240 #endif /* !defined(CCN_UNIT_SIZE) */
241 
242 
243 //this allows corecrypto Windows development using xcode
244 #if defined(CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT)
245  #if CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT && CC_DARWIN && CORECRYPTO_DEBUG
246   #define CC_USE_ASM 0
247   #define CC_USE_HEAP_FOR_WORKSPACE 1
248    #if (CCN_UNIT_SIZE == 8)
249     #define CC_DUNIT_SUPPORTED 0
250    #else
251     #define CC_DUNIT_SUPPORTED 1
252    #endif
253  #endif
254 #endif
255 
256 #if !defined(CC_DUNIT_SUPPORTED)
257  #if defined(_WIN64) && defined(_WIN32) && (CCN_UNIT_SIZE == 8)
258   #define CC_DUNIT_SUPPORTED 0
259  #else
260   #define CC_DUNIT_SUPPORTED 1
261  #endif
262 #endif
263 
264 #if defined(_MSC_VER)
265     #if defined(__clang__)
266         #define CC_ALIGNED(x) __attribute__ ((aligned(x))) //clang compiler
267     #else
268         #define CC_ALIGNED(x) __declspec(align(x)) //MS complier
269     #endif
270 #else
271     #if defined(__clang__) || CCN_UNIT_SIZE==8
272         #define CC_ALIGNED(x) __attribute__ ((aligned(x)))
273     #else
274         #define CC_ALIGNED(x) __attribute__ ((aligned((x)>8?8:(x))))
275     #endif
276 #endif
277 
278 #if defined(__arm__) && (defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7S__) || defined (__ARM_ARCH_7F__) || defined (__ARM_ARCH_7K__) || defined(__ARM_ARCH_7EM__))
279     #define CC_ARM_ARCH_7 1
280 #else
281     #define CC_ARM_ARCH_7 0
282 #endif
283 
284 // DSP is only available on aarch32
285 #if CC_ARM_ARCH_7 && defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
286     #define CC_ARM_ARCH_7_DSP 1
287 #else
288     #define CC_ARM_ARCH_7_DSP 0
289 #endif
290 
291 #if defined(__arm__)
292  //This is copied from <arm/arch.h>, because <arm/arch.h> is not available on SEPROM environment
293  #if defined(__ARM_ARCH_6M__) || defined(__TARGET_ARCH_6S_M) || defined (__armv6m__)
294   #define _ARM_ARCH_6M
295  #endif
296 #endif
297 
298 #if !defined(CC_USE_HEAP_FOR_WORKSPACE)
299  #if CC_USE_SEPROM || CC_RTKITROM
300   #define CC_USE_HEAP_FOR_WORKSPACE 0
301  #else
302   #define CC_USE_HEAP_FOR_WORKSPACE 1
303  #endif
304 #endif
305 
306 // Secure memory zeroization functions
307 #if !defined(__APPLE__) || CC_RTKIT || CC_RTKITROM || CC_USE_SEPROM || defined(__CC_ARM) || defined(__hexagon__) || CC_EFI
308  #define CC_HAS_MEMSET_S 0
309 #else
310  #define CC_HAS_MEMSET_S 1
311 #endif
312 
313 #if defined(_WIN32) && !defined(__clang__)
314  // Clang with Microsoft CodeGen doesn't support SecureZeroMemory.
315  #define CC_HAS_SECUREZEROMEMORY 1
316 #else
317  #define CC_HAS_SECUREZEROMEMORY 0
318 #endif
319 
320 #if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
321  #define CC_HAS_EXPLICIT_BZERO 1
322 #else
323  #define CC_HAS_EXPLICIT_BZERO 0
324 #endif
325 
326 // Disable RSA Keygen on iBridge
327 #if CC_BRIDGE && CC_KERNEL
328 #define CC_DISABLE_RSAKEYGEN 1 /* for iBridge */
329 #else
330 #define CC_DISABLE_RSAKEYGEN 0 /* default */
331 #endif
332 
333 #if (CCN_UNIT_SIZE == 8) && !( defined(_MSC_VER) && defined(__clang__))
334 #define CCEC25519_CURVE25519_64BIT 1
335 #else
336 #define CCEC25519_CURVE25519_64BIT 0
337 #endif
338 
339 //- functions implemented in assembly ------------------------------------------
340 //this the list of corecrypto clients that use assembly and the clang compiler
341 #if !(CC_DARWIN || CC_KERNEL || CC_USE_L4 || CC_IBOOT || CC_RTKIT || CC_RTKITROM || CC_USE_SEPROM) && !defined(_WIN32) && CORECRYPTO_DEBUG
342  #warning "You are using the default corecrypto configuration, assembly optimizations may not be available for your platform"
343 #endif
344 
345 // Enable assembler in Linux if CC_LINUX_ASM is defined
346 #if (CC_LINUX || CC_SGX) && defined(CC_LINUX_ASM) && CC_LINUX_ASM
347 #define CC_USE_ASM 1
348 #endif
349 
350 // Use this macro to strictly disable assembly regardless of cpu/os/compiler/etc.
351 // Our assembly code is not gcc compatible. Clang defines the __GNUC__ macro as well.
352 #if !defined(CC_USE_ASM)
353  #if defined(_WIN32) || CC_EFI || CC_BASEBAND || CC_XNU_KERNEL_PRIVATE || (defined(__GNUC__) && !defined(__clang__)) || CC_LINUX
354   #define CC_USE_ASM 0
355  #else
356   #define CC_USE_ASM 1
357  #endif
358 #endif
359 
360 #ifndef CC_LOG
361 #define CC_LOG (CC_DARWIN && !CC_KERNEL && !CC_IBOOT && !CC_DRIVERKIT)
362 #endif
363 
364 #ifndef CC_EXTERN_MALLOC
365   #define CC_EXTERN_MALLOC 0
366 #endif
367 
368 #define CC_CACHE_DESCRIPTORS CC_KERNEL
369 
370 //-(1) ARM V7
371 #if CC_ARM_ARCH_7 && defined(__clang__) && CC_USE_ASM
372  #define CCN_MUL_KARATSUBA      0 // no performance improvement
373  #define CCN_ADD_ASM            1
374  #define CCN_SUB_ASM            1
375  #define CCN_MUL_ASM            0
376  #define CCN_ADDMUL1_ASM        1
377  #define CCN_MUL1_ASM           1
378  #define CCN_CMP_ASM            1
379  #define CCN_ADD1_ASM           1
380  #define CCN_SUB1_ASM           1
381  #define CCN_N_ASM              1
382  #define CCN_SET_ASM            1
383  #define CCN_SHIFT_RIGHT_ASM    1
384  #if defined(__ARM_NEON__)
385  #define CCN_SHIFT_LEFT_ASM     1
386  #else
387  #define CCN_SHIFT_LEFT_ASM     0
388  #endif
389  #define CCN_MULMOD_224_ASM     CC_ARM_ARCH_7_DSP
390  #define CCN_MULMOD_256_ASM     CC_ARM_ARCH_7_DSP
391  #define CCAES_ARM_ASM          1
392  #define CCAES_INTEL_ASM        0
393  #if CC_KERNEL || CC_USE_L4 || CC_IBOOT || CC_RTKIT || CC_RTKITROM || CC_USE_SEPROM || CC_DRIVERKIT
394   #define CCAES_MUX             0
395  #else
396   #define CCAES_MUX             1
397  #endif
398  #define CCSHA1_VNG_INTEL       0
399  #define CCSHA2_VNG_INTEL       0
400 
401  #if defined(__ARM_NEON__) || CC_KERNEL
402   #define CCSHA1_VNG_ARM        1
403   #define CCSHA2_VNG_ARM        1
404  #else /* !defined(__ARM_NEON__) */
405   #define CCSHA1_VNG_ARM        0
406   #define CCSHA2_VNG_ARM        0
407  #endif /* !defined(__ARM_NEON__) */
408 
409 //-(2) ARM 64
410 #elif defined(__arm64__) && defined(__clang__) && CC_USE_ASM
411  #define CCN_MUL_KARATSUBA      0 // 4*n CCN_UNIT extra memory required.
412  #define CCN_ADD_ASM            1
413  #define CCN_SUB_ASM            1
414  #define CCN_MUL_ASM            1
415  #define CCN_ADDMUL1_ASM        1
416  #define CCN_MUL1_ASM           1
417  #define CCN_CMP_ASM            1
418  #define CCN_ADD1_ASM           0
419  #define CCN_SUB1_ASM           0
420  #define CCN_N_ASM              1
421  #define CCN_SET_ASM            0
422  #define CCN_SHIFT_RIGHT_ASM    1
423  #define CCN_SHIFT_LEFT_ASM     1
424  #define CCN_MULMOD_224_ASM     1
425  #define CCN_MULMOD_256_ASM     1
426  #define CCAES_ARM_ASM          1
427  #define CCAES_INTEL_ASM        0
428  #define CCAES_MUX              0        // On 64bit SoC, asm is much faster than HW
429  #define CCSHA1_VNG_INTEL       0
430  #define CCSHA2_VNG_INTEL       0
431  #define CCSHA1_VNG_ARM         1
432  #define CCSHA2_VNG_ARM         1
433 
434 //-(3) Intel 32/64
435 #elif (defined(__x86_64__) || defined(__i386__)) && defined(__clang__) && CC_USE_ASM
436  #define CCN_MUL_KARATSUBA      0 // 4*n CCN_UNIT extra memory required.
437  /* These assembly routines only work for a single CCN_UNIT_SIZE. */
438  #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8) || (defined(__i386__) && CCN_UNIT_SIZE == 4)
439   #define CCN_ADD_ASM            1
440   #define CCN_SUB_ASM            1
441   #define CCN_MUL_ASM            1
442  #else
443   #define CCN_ADD_ASM            0
444   #define CCN_SUB_ASM            0
445   #define CCN_MUL_ASM            0
446  #endif
447 
448  #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8)
449   #define CCN_CMP_ASM            1
450   #define CCN_N_ASM              1
451   #define CCN_SHIFT_RIGHT_ASM    1
452   #define CCN_SHIFT_LEFT_ASM     1
453  #else
454   #define CCN_CMP_ASM            0
455   #define CCN_N_ASM              0
456   #define CCN_SHIFT_RIGHT_ASM    0
457   #define CCN_SHIFT_LEFT_ASM     0
458  #endif
459 
460  #define CCN_MULMOD_224_ASM     0
461  #if defined(__x86_64__) && CCN_UNIT_SIZE == 8 && !CC_SGX
462   #define CCN_MULMOD_256_ASM    1
463   #define CCN_ADDMUL1_ASM       1
464   #define CCN_MUL1_ASM          1
465  #else
466   #define CCN_MULMOD_256_ASM    0
467   #define CCN_ADDMUL1_ASM       0
468   #define CCN_MUL1_ASM          0
469  #endif
470  #define CCN_ADD1_ASM           0
471  #define CCN_SUB1_ASM           0
472  #define CCN_SET_ASM            0
473  #define CCAES_ARM_ASM          0
474  #define CCAES_INTEL_ASM        1
475  #define CCAES_MUX              0
476  #define CCSHA1_VNG_INTEL       1
477  #define CCSHA2_VNG_INTEL       1
478  #define CCSHA1_VNG_ARM         0
479  #define CCSHA2_VNG_ARM         0
480 
481 //-(4) disable assembly
482 #else
483  #define CCN_MUL_KARATSUBA      0 // 4*n CCN_UNIT extra memory required.
484  #define CCN_ADD_ASM            0
485  #define CCN_SUB_ASM            0
486  #define CCN_MUL_ASM            0
487  #define CCN_ADDMUL1_ASM        0
488  #define CCN_MUL1_ASM           0
489  #define CCN_CMP_ASM            0
490  #define CCN_ADD1_ASM           0
491  #define CCN_SUB1_ASM           0
492  #define CCN_N_ASM              0
493  #define CCN_SET_ASM            0
494  #define CCN_SHIFT_RIGHT_ASM    0
495  #define CCN_SHIFT_LEFT_ASM     0
496  #define CCN_MULMOD_224_ASM     0
497  #define CCN_MULMOD_256_ASM     0
498  #define CCAES_ARM_ASM          0
499  #define CCAES_INTEL_ASM        0
500  #define CCAES_MUX              0
501  #define CCSHA1_VNG_INTEL       0
502  #define CCSHA2_VNG_INTEL       0
503  #define CCSHA1_VNG_ARM         0
504  #define CCSHA2_VNG_ARM         0
505 
506 #endif
507 
508 #define CC_INLINE static inline
509 #define CC_NONNULL4 CC_NONNULL((4))
510 
511 #ifdef __GNUC__
512  #define CC_NORETURN __attribute__((__noreturn__))
513  #define CC_NOTHROW __attribute__((__nothrow__))
514  #define CC_NONNULL(N) __attribute__((__nonnull__ N))
515  #define CC_NONNULL_ALL __attribute__((__nonnull__))
516  #define CC_SENTINEL __attribute__((__sentinel__))
517  // 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.
518  // Specifically, do not apply CC_CONST if the function has any arguments that are pointers (directly, or indirectly)
519  #define CC_CONST __attribute__((__const__))
520  #define CC_PURE __attribute__((__pure__))
521  #define CC_NODISCARD __attribute__((warn_unused_result))
522  #define CC_WARN_RESULT __attribute__((__warn_unused_result__))
523  #define CC_MALLOC_CLEAR __attribute__((__malloc__))
524  #define CC_UNUSED __attribute__((unused))
525  #define CC_WEAK __attribute__((weak))
526 #elif defined(__KEIL__)
527  #define CC_NORETURN __attribute__((noreturn))
528  #define CC_NOTHROW __attribute__((nothrow))
529  #define CC_NONNULL(N) __attribute__((nonnull N))
530  #define CC_NONNULL_ALL __attribute__((nonnull))
531  #define CC_SENTINEL __attribute__((sentinel))
532  #define CC_CONST __attribute__((const))
533  #define CC_PURE __attribute__((pure))
534  #define CC_NODISCARD __attribute__((warn_unused_result))
535  #define CC_WARN_RESULT __attribute__((warn_unused_result))
536  #define CC_MALLOC_CLEAR __attribute__((malloc))
537  #define CC_UNUSED __attribute__((unused))
538  #define CC_WEAK __attribute__((weak))
539 #else /* !__GNUC__ */
540 /*! @parseOnly */
541  #define CC_UNUSED
542 /*! @parseOnly */
543  #define CC_NONNULL(N)
544 /*! @parseOnly */
545  #define CC_NORETURN
546 /*! @parseOnly */
547  #define CC_NOTHROW
548 /*! @parseOnly */
549  #define CC_NONNULL_ALL
550 /*! @parseOnly */
551  #define CC_SENTINEL
552 /*! @parseOnly */
553  #define CC_CONST
554 /*! @parseOnly */
555  #define CC_PURE
556 /*! @parseOnly */
557  #define CC_NODISCARD
558 /*! @parseOnly */
559  #define CC_WARN_RESULT
560 /*! @parseOnly */
561  #define CC_MALLOC_CLEAR
562 /*! @parseOnly */
563  #define CC_WEAK
564 #endif /* !__GNUC__ */
565 
566 // Use CC_WEAK_IF_SMALL_CODE to mark symbols as weak when compiling with
567 // CC_SMALL_CODE=1. This allows replacing faster but bigger code with smaller
568 // versions at link time.
569 #if CC_SMALL_CODE
570  #define CC_WEAK_IF_SMALL_CODE CC_WEAK
571 #else
572  #define CC_WEAK_IF_SMALL_CODE
573 #endif
574 
575 // Bridge differences between MachO and ELF compiler/assemblers. */
576 #if CC_LINUX || CC_SGX
577 #define CC_ASM_SECTION_CONST .rodata
578 #define CC_ASM_PRIVATE_EXTERN .hidden
579 #if CC_LINUX
580 // We need to be sure that assembler can access relocated C
581 // symbols. Sad but this is the quickest way to do that, at least with
582 // our current linux compiler (clang-3.4).
583 #define CC_C_LABEL(_sym) _sym@PLT
584 #else /* CC_SGX */
585 #define CC_C_LABEL(_sym) _sym
586 #endif
587 #define _IMM(x) $(x)
588 #else /* !CC_LINUX && !CC_SGX */
589 #define CC_ASM_SECTION_CONST .const
590 #define CC_ASM_PRIVATE_EXTERN .private_extern
591 #define CC_C_LABEL(_sym) _##_sym
592 #define _IMM(x) $$(x)
593 #endif /* !CC_LINUX && !CC_SGX */
594 
595 // Enable FIPSPOST function tracing only when supported. */
596 #ifdef CORECRYPTO_POST_TRACE
597 #define CC_FIPSPOST_TRACE 1
598 #else
599 #define CC_FIPSPOST_TRACE 0
600 #endif
601 
602 #ifndef CC_INTERNAL_SDK
603 #if __has_include(<System/i386/cpu_capabilities.h>)
604 #define CC_INTERNAL_SDK 1
605 #elif __has_include(<System/arm/cpu_capabilities.h>)
606 #define CC_INTERNAL_SDK 1
607 #else
608 #define CC_INTERNAL_SDK 0
609 #endif
610 #endif
611 
612 // Currently thread sanitizer is only supported in local builds.
613 // Please edit your "corecrypto_test" scheme to build with thread
614 // sanitizer and then remove *all* variants of corecrypto_static
615 // besides "normal"
616 
617 #if __has_feature(thread_sanitizer)
618     #define CC_TSAN 1
619 #else
620     #define CC_TSAN 0
621 #endif // __has_feature(thread_sanitizer)
622 
623 #if __has_feature(bounds_attributes)
624     #define CC_PTRCHECK                  1
625     #define CC_PTRCHECK_CAPABLE_HEADER()   _Pragma("clang abi_ptr_attr set(single)")
626     #define cc_counted_by(x)              __attribute__((counted_by(x)))
627     #define cc_sized_by(x)                __attribute__((sized_by(x)))
628     #define cc_bidi_indexable             __attribute__((bidi_indexable))
629     #define cc_indexable                  __attribute__((indexable))
630     #define cc_single                     __attribute__((single))
631     #define cc_unsafe_indexable           __attribute__((unsafe_indexable))
632     #define cc_unsafe_forge_bidi_indexable(P, S)     __builtin_unsafe_forge_bidi_indexable(P, S)
633     #define cc_unsafe_forge_single(P)     __builtin_unsafe_forge_single(P)
634     #define cc_cstring                    cc_unsafe_indexable
635     #define CC_WIDE_NULL                  ((void *cc_bidi_indexable)NULL)
636     #define cc_ended_by(x)                __attribute__((ended_by(x)))
637 #else
638     #define CC_PTRCHECK                  0
639     #define CC_PTRCHECK_CAPABLE_HEADER()
640     #define cc_counted_by(x)
641     #define cc_sized_by(x)
642     #define cc_bidi_indexable
643     #define cc_indexable
644     #define cc_single
645     #define cc_unsafe_indexable
646     #define cc_unsafe_forge_bidi_indexable(P, S) (P)
647     #define cc_unsafe_forge_single(P) (P)
648     #define cc_cstring
649     #define CC_WIDE_NULL NULL
650     #define cc_ended_by(x)
651 #endif // __has_feature(bounds_attributes)
652 
653 // Define endianess for GCC, if needed and applicable.
654 #if defined(__GNUC__) && !defined(__LITTLE_ENDIAN__)
655     #if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
656         #define __LITTLE_ENDIAN__ 1
657     #endif
658 #endif
659 
660 #if defined(ENABLE_CRYPTOKIT_PRIVATE_DEFINITIONS) && ENABLE_CRYPTOKIT_PRIVATE_DEFINITIONS
661 #define CC_PRIVATE_CRYPTOKIT 1
662 #else
663 #define CC_PRIVATE_CRYPTOKIT 0
664 #endif
665 
666 #if defined(__clang__)
667  #define CC_WORKSPACE_OVERRIDE_PRAGMA(x) _Pragma(#x)
668  #define CC_WORKSPACE_OVERRIDE(f, o) CC_WORKSPACE_OVERRIDE_PRAGMA(workspace-override f o)
669 #else
670  #define CC_WORKSPACE_OVERRIDE(f, o)
671 #endif
672 
673 #if defined(__ARM_ARCH_8_4__) && !CC_KERNEL && !CC_USE_L4 && !CC_USE_SEPROM
674  #define CC_DIT_SUPPORTED 1
675 #else
676  #define CC_DIT_SUPPORTED 0
677 #endif
678 
679 #endif /* _CORECRYPTO_CC_CONFIG_H_ */
680