1/* Copyright (c) (2010-2023) 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_extension)
54 #define __has_extension(EXT) 0
55#endif
56
57#if !defined(__has_attribute)
58 #define __has_attribute(ATTR) 0
59#endif
60
61#ifndef __cc_printflike
62 #define __cc_printflike(fmtarg, firstvararg) __attribute__((format(printf, fmtarg, firstvararg)))
63#endif
64
65//Do not set this macros to 1, unless you are developing/testing for Linux under macOS
66#define CORECRYPTO_SIMULATE_POSIX_ENVIRONMENT 0
67
68//Do not set these macros to 1, unless you are developing/testing for Windows under macOS
69#define CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT 0
70#define CORECRYPTO_HACK_FOR_WINDOWS_DEVELOPMENT 0
71
72#if (defined(DEBUG) && (DEBUG)) || defined(_DEBUG) //MSVC defines _DEBUG
73/* CC_DEBUG is already used in CommonCrypto */
74 #define CORECRYPTO_DEBUG 1
75#else
76 #define CORECRYPTO_DEBUG 0
77#endif
78
79// Enable specific configurations only relevant in test builds
80#if defined(CORECRYPTO_BUILT_FOR_TESTING) && CORECRYPTO_BUILT_FOR_TESTING
81 #define CC_BUILT_FOR_TESTING 1
82#else
83 #define CC_BUILT_FOR_TESTING 0
84#endif
85
86// This macro can be used to enable prints when a condition in the macro "cc_require"
87// is false. This is especially useful to confirm that negative testing fails
88// at the intended location
89#define CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS 0
90
91#ifndef CC_TXM
92 #if defined(TXM) && (TXM)
93 #define CC_TXM 1
94 #else
95 #define CC_TXM 0
96 #endif
97#endif
98
99#ifndef CC_SPTM
100 #if defined(SPTM) && (SPTM)
101 #define CC_SPTM 1
102 #else
103 #define CC_SPTM 0
104 #endif
105#endif
106
107#if defined(KERNEL) && (KERNEL)
108 #define CC_KERNEL 1 // KEXT, XNU repo or kernel components such as AppleKeyStore
109#else
110 #define CC_KERNEL 0
111#endif
112
113#if defined(LINUX_SGX) && (LINUX_SGX)
114 #define CC_SGX 1
115#else
116 #define CC_SGX 0
117#endif
118
119#if (defined(__linux__) && !(CC_SGX)) || CORECRYPTO_SIMULATE_POSIX_ENVIRONMENT
120 #define CC_LINUX 1
121#else
122 #define CC_LINUX 0
123#endif
124
125#if defined(USE_L4) && (USE_L4)
126 #define CC_USE_L4 1
127#else
128 #define CC_USE_L4 0
129#endif
130
131#if defined(RTKIT) && (RTKIT)
132 #define CC_RTKIT 1
133#else
134 #define CC_RTKIT 0
135#endif
136
137#if defined(RTKITROM) && (RTKITROM)
138#define CC_RTKITROM 1
139#else
140#define CC_RTKITROM 0
141#endif
142
143#if defined(USE_SEPROM) && (USE_SEPROM)
144 #define CC_USE_SEPROM 1
145#else
146 #define CC_USE_SEPROM 0
147#endif
148
149#if (defined(ICE_FEATURES_ENABLED)) || (defined(MAVERICK) && (MAVERICK))
150 #define CC_BASEBAND 1
151#else
152 #define CC_BASEBAND 0
153#endif
154
155#if defined(EFI) && (EFI)
156 #define CC_EFI 1
157#else
158 #define CC_EFI 0
159#endif
160
161#if defined(IBOOT) && (IBOOT)
162 #define CC_IBOOT 1
163#else
164 #define CC_IBOOT 0
165#endif
166
167// Include target conditionals if available.
168#if defined(__has_include) /* portability */
169#if __has_include(<TargetConditionals.h>)
170#include <TargetConditionals.h>
171#endif /* __has_include(<TargetConditionals.h>) */
172#endif /* defined(__has_include) */
173
174#if defined(TARGET_OS_DRIVERKIT)
175 #define CC_DRIVERKIT TARGET_OS_DRIVERKIT
176#else
177 #define CC_DRIVERKIT 0
178#endif
179
180#if defined(TARGET_OS_BRIDGE)
181 #define CC_BRIDGE TARGET_OS_BRIDGE
182#else
183 #define CC_BRIDGE 0
184#endif
185
186// TARGET_OS_EXCLAVECORE && TARGET_OS_EXCLAVEKIT
187#if defined(TARGET_OS_EXCLAVECORE) && TARGET_OS_EXCLAVECORE
188 #define CC_EXCLAVE 1
189 #define CC_EXCLAVECORE 1
190 #define CC_EXCLAVEKIT 0
191#elif defined(TARGET_OS_EXCLAVEKIT) && TARGET_OS_EXCLAVEKIT
192 #define CC_EXCLAVE 1
193 #define CC_EXCLAVECORE 0
194 #define CC_EXCLAVEKIT 1
195#else
196 #define CC_EXCLAVE 0
197 #define CC_EXCLAVECORE 0
198 #define CC_EXCLAVEKIT 0
199#endif
200
201// ARMv6-M
202#if defined(__arm__) && (defined(__ARM_ARCH_6M__) || defined(__TARGET_ARCH_6S_M) || defined (__armv6m__))
203 #define CC_ARM_ARCH_6M 1
204#else
205 #define CC_ARM_ARCH_6M 0
206#endif
207
208// ARMv7
209#if defined(__arm__) && (defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7S__) || defined (__ARM_ARCH_7F__) || defined (__ARM_ARCH_7K__) || defined(__ARM_ARCH_7EM__))
210 #define CC_ARM_ARCH_7 1
211#else
212 #define CC_ARM_ARCH_7 0
213#endif
214
215// DSP is only available on aarch32
216#if CC_ARM_ARCH_7 && defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
217 #define CC_ARM_ARCH_7_DSP 1
218#else
219 #define CC_ARM_ARCH_7_DSP 0
220#endif
221
222#if defined(__ARM_NEON) && __ARM_NEON
223 #define CC_ARM_NEON 1
224#else
225 #define CC_ARM_NEON 0
226#endif
227
228#if defined(__ARM_FEATURE_AES) && __ARM_FEATURE_AES
229 #define CC_ARM_FEATURE_AES 1
230#else
231 #define CC_ARM_FEATURE_AES 0
232#endif
233
234#if defined(__ARM_FEATURE_SHA2) && __ARM_FEATURE_SHA2
235 #define CC_ARM_FEATURE_SHA2 1
236#else
237 #define CC_ARM_FEATURE_SHA2 0
238#endif
239
240#if defined(__ARM_FEATURE_SHA512) && __ARM_FEATURE_SHA512
241 #define CC_ARM_FEATURE_SHA512 1
242#else
243 #define CC_ARM_FEATURE_SHA512 0
244#endif
245
246#if defined(__ARM_FEATURE_SHA3) && __ARM_FEATURE_SHA3
247 #define CC_ARM_FEATURE_SHA3 1
248#else
249 #define CC_ARM_FEATURE_SHA3 0
250#endif
251
252// Check for open source builds
253
254// Defined by the XNU build scripts
255// Applies to code embedded in XNU but NOT to the kext
256#if defined(XNU_KERNEL_PRIVATE)
257 #define CC_XNU_KERNEL_PRIVATE 1
258#else
259 #define CC_XNU_KERNEL_PRIVATE 0
260#endif
261
262// Handle unaligned data, if the CPU cannot. (For Gladman AES.)
263#define CC_HANDLE_UNALIGNED_DATA CC_BASEBAND
264
265// BaseBand configuration
266#if CC_BASEBAND
267
268// -- ENDIANESS
269#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
270 #if defined(ENDIAN_LITTLE) || (defined(__arm__) && !defined(__BIG_ENDIAN))
271 #define __LITTLE_ENDIAN__
272 #elif !defined(ENDIAN_BIG) && !defined(__BIG_ENDIAN)
273 #error Baseband endianess not defined.
274 #endif
275 #define AESOPT_ENDIAN_NO_FILE
276#endif
277
278#if !defined(__x86_64__) && !defined(__arm64__)
279// -- Architecture
280 #define CCN_UNIT_SIZE 4 // 32 bits
281#endif
282
283// -- Warnings
284// Ignore irrelevant warnings after verification
285// #186-D: pointless comparison of unsigned integer with zero
286// #546-D: transfer of control bypasses initialization of
287 #ifdef __arm__
288 #pragma diag_suppress 186, 546
289 #endif // __arm__
290#define CC_SMALL_CODE 1
291
292#endif // CC_BASEBAND
293
294#if CC_RTKIT || CC_RTKITROM
295#define CC_SMALL_CODE 1
296#endif
297
298
299#ifndef CC_SMALL_CODE
300#define CC_SMALL_CODE 0
301#endif
302
303#ifndef CC_DARWIN
304 //CC_DARWIN indicates the availability of XNU kernel functions,
305 //like what we have on OSX, iOS, tvOS, Watch OS
306 #if (CC_USE_L4 || CC_RTKIT || CC_RTKITROM || CC_USE_SEPROM || CC_EFI || CC_LINUX || defined(_WIN32) || CC_BASEBAND || CC_SGX || CC_ARM_ARCH_6M)
307 #define CC_DARWIN 0
308 #elif CC_TXM
309 #define CC_DARWIN 0
310 #elif CC_SPTM
311 #define CC_DARWIN 0
312 #else
313 #define CC_DARWIN 1
314 #endif
315#endif
316
317//arm arch64 definition for gcc
318#if defined(__GNUC__) && defined(__aarch64__) && !defined(__arm64__)
319 #define __arm64__
320#endif
321
322#if !defined(CCN_UNIT_SIZE)
323 #if defined(__arm64__) || defined(__x86_64__) || defined(_WIN64)
324 #define CCN_UNIT_SIZE 8
325 #elif defined(__arm__) || defined(__i386__) || defined(_WIN32)
326 #define CCN_UNIT_SIZE 4
327 #else
328 #error undefined architecture
329 #endif
330#endif /* !defined(CCN_UNIT_SIZE) */
331
332
333//this allows corecrypto Windows development using xcode
334#if defined(CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT)
335 #if CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT && CC_DARWIN && CORECRYPTO_DEBUG
336 #define CC_USE_ASM 0
337 #define CC_USE_HEAP_FOR_WORKSPACE 1
338 #if (CCN_UNIT_SIZE == 8)
339 #define CC_DUNIT_SUPPORTED 0
340 #else
341 #define CC_DUNIT_SUPPORTED 1
342 #endif
343 #endif
344#endif
345
346#if !defined(CC_DUNIT_SUPPORTED)
347 #if defined(_WIN64) && defined(_WIN32) && (CCN_UNIT_SIZE == 8)
348 #define CC_DUNIT_SUPPORTED 0
349 #else
350 #define CC_DUNIT_SUPPORTED 1
351 #endif
352#endif
353
354#if defined(_MSC_VER)
355 #if defined(__clang__)
356 #define CC_ALIGNED(x) __attribute__ ((aligned(x))) //clang compiler
357 #else
358 #define CC_ALIGNED(x) __declspec(align(x)) //MS complier
359 #endif
360#else
361 #if defined(__clang__) || CCN_UNIT_SIZE==8
362 #define CC_ALIGNED(x) __attribute__ ((aligned(x)))
363 #else
364 #define CC_ALIGNED(x) __attribute__ ((aligned((x)>8?8:(x))))
365 #endif
366#endif
367
368#if !defined(CC_USE_HEAP_FOR_WORKSPACE)
369 #if CC_USE_SEPROM || CC_RTKITROM || CC_EFI
370 #define CC_USE_HEAP_FOR_WORKSPACE 0
371 #else
372 #define CC_USE_HEAP_FOR_WORKSPACE 1
373 #endif
374#endif
375
376// Secure memory zeroization functions
377#if !defined(__APPLE__) || CC_RTKIT || CC_RTKITROM || CC_USE_SEPROM || defined(__CC_ARM) || defined(__hexagon__) || CC_EFI
378 #define CC_HAS_MEMSET_S 0
379#else
380 #define CC_HAS_MEMSET_S 1
381#endif
382
383#if defined(_WIN32) && !defined(__clang__)
384 // Clang with Microsoft CodeGen doesn't support SecureZeroMemory.
385 #define CC_HAS_SECUREZEROMEMORY 1
386#else
387 #define CC_HAS_SECUREZEROMEMORY 0
388#endif
389
390#if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
391 #define CC_HAS_EXPLICIT_BZERO 1
392#else
393 #define CC_HAS_EXPLICIT_BZERO 0
394#endif
395
396// Disable RSA keygen on iBridge.
397#if !defined(CC_DISABLE_RSAKEYGEN)
398 #if CC_BRIDGE && CC_KERNEL
399 #define CC_DISABLE_RSAKEYGEN 1
400 #else
401 #define CC_DISABLE_RSAKEYGEN 0
402 #endif
403#endif
404
405// Enable assembler in Linux if CC_LINUX_ASM is defined
406#if (CC_LINUX || CC_SGX) && defined(CC_LINUX_ASM) && CC_LINUX_ASM
407#define CC_USE_ASM 1
408#endif
409
410// Use this macro to strictly disable assembly regardless of cpu/os/compiler/etc.
411// Our assembly code is not gcc compatible. Clang defines the __GNUC__ macro as well.
412#if !defined(CC_USE_ASM)
413 #if defined(_WIN32) || CC_EFI || CC_BASEBAND || CC_XNU_KERNEL_PRIVATE || (defined(__GNUC__) && !defined(__clang__)) || CC_LINUX
414 #define CC_USE_ASM 0
415 #else
416 #define CC_USE_ASM 1
417 #endif
418#endif
419
420#ifndef CC_LOG
421#define CC_LOG (CC_DARWIN && !CC_KERNEL && !CC_IBOOT && !CC_DRIVERKIT && !CC_EXCLAVE)
422#endif
423
424#ifndef CC_EXTERN_MALLOC
425 #if CC_TXM
426 #define CC_EXTERN_MALLOC 1
427 #else
428 #define CC_EXTERN_MALLOC 0
429 #endif
430#endif
431
432#ifndef CC_MALLOC_ABORT
433 #if CC_SPTM
434 #define CC_MALLOC_ABORT 1
435 #else
436 #define CC_MALLOC_ABORT 0
437 #endif
438#endif
439
440#define CC_CACHE_DESCRIPTORS CC_KERNEL
441
442//-(1) ARM V7
443#if CC_ARM_ARCH_7 && defined(__clang__) && CC_USE_ASM
444 #define CCN_ADD_ASM 1
445 #define CCN_SUB_ASM 1
446 #define CCN_MUL_ASM 0
447 #define CCN_ADDMUL1_ASM 1
448 #define CCN_MUL1_ASM 1
449 #define CCN_CMP_ASM 1
450 #define CCN_ADD1_ASM 1
451 #define CCN_SUB1_ASM 1
452 #define CCN_N_ASM 1
453 #define CCN_SET_ASM 1
454 #define CCN_SHIFT_RIGHT_ASM 1
455 #if defined(__ARM_NEON__)
456 #define CCN_SHIFT_LEFT_ASM 1
457 #else
458 #define CCN_SHIFT_LEFT_ASM 0
459 #endif
460 #define CCN_MULMOD_224_ASM CC_ARM_ARCH_7_DSP
461 #define CCN_MULMOD_256_ASM CC_ARM_ARCH_7_DSP
462 #define CCN_MULMOD_384_ASM CC_ARM_ARCH_7_DSP
463 #define CCN_MULMOD_25519_ASM 0
464 #define CCN_MULMOD_448_ASM 0
465
466 // Clang cross-compiling for ARMv7/Linux can't handle the indirect symbol
467 // directives we use to reference AES tables. Skip AES assembly for now.
468 #if CC_LINUX && CC_BUILT_FOR_TESTING
469 #define CCAES_ARM_ASM 0
470 #else
471 #define CCAES_ARM_ASM 1
472 #endif
473
474 #define CCAES_INTEL_ASM 0
475 #define CCSHA1_VNG_INTEL 0
476 #define CCSHA2_VNG_INTEL 0
477 #define CCSHA3_VNG_INTEL 0
478 #define CCSHA3_VNG_ARM 0
479 #define CCSHA256_ARMV6M_ASM 0
480
481 #if defined(__ARM_NEON__) || CC_KERNEL
482 #define CCSHA1_VNG_ARM 1
483 #define CCSHA2_VNG_ARM 1
484 #else /* !defined(__ARM_NEON__) */
485 #define CCSHA1_VNG_ARM 0
486 #define CCSHA2_VNG_ARM 0
487 #endif /* !defined(__ARM_NEON__) */
488
489//-(2) ARM 64
490#elif defined(__arm64__) && defined(__clang__) && CC_USE_ASM
491 #define CCN_ADD_ASM 1
492 #define CCN_SUB_ASM 1
493 #define CCN_MUL_ASM 1
494 #define CCN_ADDMUL1_ASM 1
495 #define CCN_MUL1_ASM 1
496 #define CCN_CMP_ASM 1
497 #define CCN_ADD1_ASM 1
498 #define CCN_SUB1_ASM 0
499 #define CCN_N_ASM 1
500 #define CCN_SET_ASM 0
501 #define CCN_SHIFT_RIGHT_ASM CC_ARM_NEON
502 #define CCN_SHIFT_LEFT_ASM CC_ARM_NEON
503 #define CCN_MULMOD_224_ASM 1
504 #define CCN_MULMOD_256_ASM 1
505 #define CCN_MULMOD_384_ASM 1
506 #define CCN_MULMOD_25519_ASM 1
507 #define CCN_MULMOD_448_ASM 1
508 #define CCAES_ARM_ASM (CC_ARM_NEON && CC_ARM_FEATURE_AES)
509 #define CCAES_INTEL_ASM 0
510 #define CCSHA1_VNG_INTEL 0
511 #define CCSHA2_VNG_INTEL 0
512 #define CCSHA3_VNG_INTEL 0
513 #define CCSHA1_VNG_ARM 1
514 #define CCSHA2_VNG_ARM (CC_ARM_NEON && CC_ARM_FEATURE_SHA2)
515 #define CCSHA256_ARMV6M_ASM 0
516 #if CC_USE_L4 || CC_KERNEL
517 #define CCSHA3_VNG_ARM 0
518 #else
519 #define CCSHA3_VNG_ARM 1
520 #endif
521//-(3) Intel 32/64
522#elif (defined(__x86_64__) || defined(__i386__)) && defined(__clang__) && CC_USE_ASM
523 /* These assembly routines only work for a single CCN_UNIT_SIZE. */
524 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8) || (defined(__i386__) && CCN_UNIT_SIZE == 4)
525 #define CCN_ADD_ASM 1
526 #define CCN_SUB_ASM 1
527 #define CCN_MUL_ASM 1
528 #else
529 #define CCN_ADD_ASM 0
530 #define CCN_SUB_ASM 0
531 #define CCN_MUL_ASM 0
532 #endif
533
534 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8)
535 #define CCN_CMP_ASM 1
536 #define CCN_N_ASM 1
537 #define CCN_SHIFT_RIGHT_ASM 1
538 #define CCN_SHIFT_LEFT_ASM 1
539 #else
540 #define CCN_CMP_ASM 0
541 #define CCN_N_ASM 0
542 #define CCN_SHIFT_RIGHT_ASM 0
543 #define CCN_SHIFT_LEFT_ASM 0
544 #endif
545
546 #define CCN_MULMOD_384_ASM 0
547 #define CCN_MULMOD_448_ASM 0
548 #if defined(__x86_64__) && CCN_UNIT_SIZE == 8 && !CC_SGX
549 #define CCN_MULMOD_224_ASM 1
550 #define CCN_MULMOD_256_ASM 1
551 #define CCN_MULMOD_25519_ASM 1
552 #define CCN_ADDMUL1_ASM 1
553 #define CCN_MUL1_ASM 1
554 #else
555 #define CCN_MULMOD_224_ASM 0
556 #define CCN_MULMOD_256_ASM 0
557 #define CCN_MULMOD_25519_ASM 0
558 #define CCN_ADDMUL1_ASM 0
559 #define CCN_MUL1_ASM 0
560 #endif
561 #define CCN_ADD1_ASM 0
562 #define CCN_SUB1_ASM 0
563 #define CCN_SET_ASM 0
564 #define CCAES_ARM_ASM 0
565 #define CCAES_INTEL_ASM 1
566 #define CCSHA1_VNG_INTEL 1
567 #define CCSHA2_VNG_INTEL 1
568 #define CCSHA3_VNG_INTEL 1
569 #define CCSHA1_VNG_ARM 0
570 #define CCSHA2_VNG_ARM 0
571 #define CCSHA3_VNG_ARM 0
572 #define CCSHA256_ARMV6M_ASM 0
573//-(4) ARMv6-M
574#elif CC_ARM_ARCH_6M
575 #define CCN_ADD_ASM 0
576 #define CCN_SUB_ASM 0
577 #define CCN_MUL_ASM 0
578 #define CCN_ADDMUL1_ASM 0
579 #define CCN_MUL1_ASM 0
580 #define CCN_CMP_ASM 0
581 #define CCN_ADD1_ASM 0
582 #define CCN_SUB1_ASM 0
583 #define CCN_N_ASM 0
584 #define CCN_SET_ASM 0
585 #define CCN_SHIFT_RIGHT_ASM 0
586 #define CCN_SHIFT_LEFT_ASM 0
587 #define CCN_MULMOD_224_ASM 0
588 #define CCN_MULMOD_256_ASM 0
589 #define CCN_MULMOD_384_ASM 0
590 #define CCN_MULMOD_25519_ASM 0
591 #define CCN_MULMOD_448_ASM 0
592 #define CCAES_ARM_ASM 0
593 #define CCAES_INTEL_ASM 0
594 #define CCSHA1_VNG_INTEL 0
595 #define CCSHA2_VNG_INTEL 0
596 #define CCSHA3_VNG_INTEL 0
597 #define CCSHA1_VNG_ARM 0
598 #define CCSHA2_VNG_ARM 0
599 #define CCSHA3_VNG_ARM 0
600 #define CCSHA256_ARMV6M_ASM 1
601//-(5) disable assembly
602#else
603 #define CCN_ADD_ASM 0
604 #define CCN_SUB_ASM 0
605 #define CCN_MUL_ASM 0
606 #define CCN_ADDMUL1_ASM 0
607 #define CCN_MUL1_ASM 0
608 #define CCN_CMP_ASM 0
609 #define CCN_ADD1_ASM 0
610 #define CCN_SUB1_ASM 0
611 #define CCN_N_ASM 0
612 #define CCN_SET_ASM 0
613 #define CCN_SHIFT_RIGHT_ASM 0
614 #define CCN_SHIFT_LEFT_ASM 0
615 #define CCN_MULMOD_224_ASM 0
616 #define CCN_MULMOD_256_ASM 0
617 #define CCN_MULMOD_384_ASM 0
618 #define CCN_MULMOD_25519_ASM 0
619 #define CCN_MULMOD_448_ASM 0
620 #define CCAES_ARM_ASM 0
621 #define CCAES_INTEL_ASM 0
622 #define CCSHA1_VNG_INTEL 0
623 #define CCSHA2_VNG_INTEL 0
624 #define CCSHA3_VNG_INTEL 0
625 #define CCSHA1_VNG_ARM 0
626 #define CCSHA2_VNG_ARM 0
627 #define CCSHA3_VNG_ARM 0
628 #define CCSHA256_ARMV6M_ASM 0
629#endif
630
631#define CC_INLINE static inline
632#define CC_NONNULL4 CC_NONNULL((4))
633
634#ifdef __GNUC__
635 #define CC_NORETURN __attribute__((__noreturn__))
636 #define CC_NOTHROW __attribute__((__nothrow__))
637 #define CC_NONNULL(N) __attribute__((__nonnull__ N))
638 #define CC_NONNULL_ALL __attribute__((__nonnull__))
639 #define CC_SENTINEL __attribute__((__sentinel__))
640 // 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.
641 // Specifically, do not apply CC_CONST if the function has any arguments that are pointers (directly, or indirectly)
642 #define CC_CONST __attribute__((__const__))
643 #define CC_PURE __attribute__((__pure__))
644 #define CC_NODISCARD __attribute__((warn_unused_result))
645 #define CC_WARN_RESULT __attribute__((__warn_unused_result__))
646 #define CC_MALLOC_CLEAR __attribute__((__malloc__))
647 #define CC_UNUSED __attribute__((unused))
648 #define CC_WEAK __attribute__((weak))
649#elif defined(__KEIL__)
650 #define CC_NORETURN __attribute__((noreturn))
651 #define CC_NOTHROW __attribute__((nothrow))
652 #define CC_NONNULL(N) __attribute__((nonnull N))
653 #define CC_NONNULL_ALL __attribute__((nonnull))
654 #define CC_SENTINEL __attribute__((sentinel))
655 #define CC_CONST __attribute__((const))
656 #define CC_PURE __attribute__((pure))
657 #define CC_NODISCARD __attribute__((warn_unused_result))
658 #define CC_WARN_RESULT __attribute__((warn_unused_result))
659 #define CC_MALLOC_CLEAR __attribute__((malloc))
660 #define CC_UNUSED __attribute__((unused))
661 #define CC_WEAK __attribute__((weak))
662#else /* !__GNUC__ */
663/*! @parseOnly */
664 #define CC_UNUSED
665/*! @parseOnly */
666 #define CC_NONNULL(N)
667/*! @parseOnly */
668 #define CC_NORETURN
669/*! @parseOnly */
670 #define CC_NOTHROW
671/*! @parseOnly */
672 #define CC_NONNULL_ALL
673/*! @parseOnly */
674 #define CC_SENTINEL
675/*! @parseOnly */
676 #define CC_CONST
677/*! @parseOnly */
678 #define CC_PURE
679/*! @parseOnly */
680 #define CC_NODISCARD
681/*! @parseOnly */
682 #define CC_WARN_RESULT
683/*! @parseOnly */
684 #define CC_MALLOC_CLEAR
685/*! @parseOnly */
686 #define CC_WEAK
687#endif /* !__GNUC__ */
688
689// Use CC_WEAK_IF_SMALL_CODE to mark symbols as weak when compiling with
690// CC_SMALL_CODE=1. This allows replacing faster but bigger code with smaller
691// versions at link time.
692#if CC_SMALL_CODE && !CC_BUILT_FOR_TESTING
693 #define CC_WEAK_IF_SMALL_CODE CC_WEAK
694#else
695 #define CC_WEAK_IF_SMALL_CODE
696#endif
697
698// Bridge differences between MachO and ELF compiler/assemblers. */
699#if CC_LINUX || CC_SGX
700#define CC_ASM_SECTION_CONST .rodata
701#define CC_ASM_PRIVATE_EXTERN .hidden
702#define CC_ASM_SUBSECTIONS_VIA_SYMBOLS
703#if CC_LINUX
704// We need to be sure that assembler can access relocated C
705// symbols. Sad but this is the quickest way to do that, at least with
706// our current linux compiler (clang-3.4).
707#define CC_C_LABEL(_sym) _sym@PLT
708#else /* CC_SGX */
709#define CC_C_LABEL(_sym) _sym
710#endif
711#define _IMM(x) $(x)
712#else /* !CC_LINUX && !CC_SGX */
713#define CC_ASM_SECTION_CONST .const
714#define CC_ASM_PRIVATE_EXTERN .private_extern
715#define CC_ASM_SUBSECTIONS_VIA_SYMBOLS .subsections_via_symbols
716#define CC_C_LABEL(_sym) _##_sym
717#define _IMM(x) $$(x)
718#endif /* !CC_LINUX && !CC_SGX */
719
720// Enable FIPSPOST function tracing only when supported. */
721#ifdef CORECRYPTO_POST_TRACE
722#define CC_FIPSPOST_TRACE 1
723#else
724#define CC_FIPSPOST_TRACE 0
725#endif
726
727#ifndef CC_INTERNAL_SDK
728#if __has_include(<System/i386/cpu_capabilities.h>)
729#define CC_INTERNAL_SDK 1
730#elif __has_include(<System/arm/cpu_capabilities.h>)
731#define CC_INTERNAL_SDK 1
732#else
733#define CC_INTERNAL_SDK 0
734#endif
735#endif
736
737#if __has_feature(address_sanitizer)
738 #define CC_ASAN 1
739#else
740 #define CC_ASAN 0
741#endif
742
743#ifdef CORECRYPTO_COVERAGE
744#define CC_COVERAGE 1
745#else
746#define CC_COVERAGE 0
747#endif
748
749// Currently thread sanitizer is only supported in local builds.
750// Please edit your "corecrypto_test" scheme to build with thread
751// sanitizer and then remove *all* variants of corecrypto_static
752// besides "normal"
753
754#if __has_feature(thread_sanitizer)
755 #define CC_TSAN 1
756#else
757 #define CC_TSAN 0
758#endif // __has_feature(thread_sanitizer)
759
760#if __has_feature(bounds_attributes)
761 #define CC_PTRCHECK 1
762 #define CC_PTRCHECK_CAPABLE_HEADER() _Pragma("clang abi_ptr_attr set(single)")
763 #define cc_counted_by(x) __attribute__((counted_by(x)))
764 #define cc_sized_by(x) __attribute__((sized_by(x)))
765 #define cc_bidi_indexable __attribute__((bidi_indexable))
766 #define cc_indexable __attribute__((indexable))
767 #define cc_single __attribute__((single))
768 #define cc_unsafe_indexable __attribute__((unsafe_indexable))
769 #define cc_unsafe_forge_bidi_indexable(P, S) __builtin_unsafe_forge_bidi_indexable(P, S)
770 #define cc_unsafe_forge_single(P) __builtin_unsafe_forge_single(P)
771 #define cc_cstring cc_unsafe_indexable
772 #define CC_WIDE_NULL ((void *cc_bidi_indexable)NULL)
773 #define cc_ended_by(x) __attribute__((ended_by(x)))
774 #define cc_ptrcheck_unavailable_r(r) __ptrcheck_unavailable_r(r)
775#else
776 #define CC_PTRCHECK 0
777 #define CC_PTRCHECK_CAPABLE_HEADER()
778 #define cc_counted_by(x)
779 #define cc_sized_by(x)
780 #define cc_bidi_indexable
781 #define cc_indexable
782 #define cc_single
783 #define cc_unsafe_indexable
784 #define cc_unsafe_forge_bidi_indexable(P, S) (P)
785 #define cc_unsafe_forge_single(P) (P)
786 #define cc_cstring
787 #define CC_WIDE_NULL NULL
788 #define cc_ended_by(x)
789 #define cc_ptrcheck_unavailable_r(r)
790#endif // __has_feature(bounds_attributes)
791
792// Define endianess for GCC, if needed and applicable.
793#if defined(__GNUC__) && !defined(__LITTLE_ENDIAN__)
794 #if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
795 #define __LITTLE_ENDIAN__ 1
796 #endif
797#endif
798
799#if defined(ENABLE_CRYPTOKIT_PRIVATE_DEFINITIONS) && ENABLE_CRYPTOKIT_PRIVATE_DEFINITIONS
800#define CC_PRIVATE_CRYPTOKIT 1
801#else
802#define CC_PRIVATE_CRYPTOKIT 0
803#endif
804
805#if defined(__clang__)
806 #define CC_WORKSPACE_OVERRIDE_PRAGMA(x) _Pragma(#x)
807 #define CC_WORKSPACE_OVERRIDE(f, o) CC_WORKSPACE_OVERRIDE_PRAGMA(workspace-override f o)
808#else
809 #define CC_WORKSPACE_OVERRIDE(f, o)
810#endif
811
812#ifndef CC_DIT_MAYBE_SUPPORTED
813 #if defined(__arm64__) && !CC_USE_L4 && !CC_USE_SEPROM && !CC_IBOOT
814 #define CC_DIT_MAYBE_SUPPORTED 1
815 #else
816 #define CC_DIT_MAYBE_SUPPORTED 0
817 #endif
818#endif
819
820#endif /* _CORECRYPTO_CC_CONFIG_H_ */
821