]> git.saurik.com Git - apple/xnu.git/blame - EXTERNAL_HEADERS/corecrypto/cc_config.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / corecrypto / cc_config.h
CommitLineData
f427ee49 1/* Copyright (c) (2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020) Apple Inc. All rights reserved.
316670eb 2 *
f427ee49
A
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.
316670eb 10 */
fe8ab488 11
316670eb
A
12#ifndef _CORECRYPTO_CC_CONFIG_H_
13#define _CORECRYPTO_CC_CONFIG_H_
14
fe8ab488 15/* A word about configuration macros:
d9a64523 16
fe8ab488 17 Conditional configuration macros specific to corecrypto should be named CORECRYPTO_xxx
d9a64523 18 or CCxx_yyy and be defined to be either 0 or 1 in this file. You can add an
fe8ab488
A
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.
d9a64523 27
fe8ab488
A
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:
d9a64523 31
fe8ab488
A
32 #if defined(DEBUG) && (DEBUG)
33 #define CORECRYPTO_DEBUG 1
34 #else
35 #define CORECRYPTO_DEBUG 0
36 #endif
d9a64523 37
fe8ab488
A
38
39 It is acceptable to define a conditional CC_xxxx macro in an implementation file,
40 to be used only in this file.
d9a64523 41
fe8ab488 42 The current code is not guaranteed to follow those rules, but should be fixed to.
d9a64523 43
fe8ab488
A
44 Corecrypto requires GNU and C99 compatibility.
45 Typically enabled by passing --gnu --c99 to the compiler (eg. armcc)
46
47*/
48
5ba3f43e
A
49//Do not set this macros to 1, unless you are developing/testing for Linux under macOS
50#define CORECRYPTO_SIMULATE_POSIX_ENVIRONMENT 0
51
52//Do not set these macros to 1, unless you are developing/testing for Windows under macOS
39037602 53#define CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT 0
f427ee49 54#define CORECRYPTO_HACK_FOR_WINDOWS_DEVELOPMENT 0
39037602 55
39037602 56#if (defined(DEBUG) && (DEBUG)) || defined(_DEBUG) //MSVC defines _DEBUG
fe8ab488 57/* CC_DEBUG is already used in CommonCrypto */
39037602 58 #define CORECRYPTO_DEBUG 1
fe8ab488 59#else
39037602 60 #define CORECRYPTO_DEBUG 0
fe8ab488
A
61#endif
62
39037602
A
63// This macro can be used to enable prints when a condition in the macro "cc_require"
64// is false. This is especially useful to confirm that negative testing fails
65// at the intended location
66#define CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS 0
67
fe8ab488 68#if defined(KERNEL) && (KERNEL)
39037602 69 #define CC_KERNEL 1 // KEXT, XNU repo or kernel components such as AppleKeyStore
fe8ab488 70#else
39037602 71 #define CC_KERNEL 0
fe8ab488
A
72#endif
73
f427ee49
A
74#if defined(LINUX_SGX) && (LINUX_SGX)
75 #define CC_SGX 1
76#else
77 #define CC_SGX 0
78#endif
79
80#if (defined(__linux__) && !(CC_SGX)) || CORECRYPTO_SIMULATE_POSIX_ENVIRONMENT
39037602 81 #define CC_LINUX 1
3e170ce0 82#else
39037602 83 #define CC_LINUX 0
3e170ce0
A
84#endif
85
f427ee49
A
86#if defined(__ANDROID__) && (__ANDROID__)
87 #define CC_ANDROID 1
88#else
89 #define CC_ANDROID 0
90#endif
91
fe8ab488 92#if defined(USE_L4) && (USE_L4)
39037602 93 #define CC_USE_L4 1
fe8ab488 94#else
39037602 95 #define CC_USE_L4 0
fe8ab488
A
96#endif
97
5ba3f43e
A
98#if defined(RTKIT) && (RTKIT)
99 #define CC_RTKIT 1
100#else
101 #define CC_RTKIT 0
102#endif
103
d9a64523
A
104#if defined(RTKITROM) && (RTKITROM)
105#define CC_RTKITROM 1
106#else
107#define CC_RTKITROM 0
108#endif
109
3e170ce0 110#if defined(USE_SEPROM) && (USE_SEPROM)
39037602 111 #define CC_USE_SEPROM 1
3e170ce0 112#else
39037602 113 #define CC_USE_SEPROM 0
3e170ce0
A
114#endif
115
116#if defined(USE_S3) && (USE_S3)
39037602 117 #define CC_USE_S3 1
3e170ce0 118#else
39037602 119 #define CC_USE_S3 0
3e170ce0
A
120#endif
121
39037602
A
122#if (defined(ICE_FEATURES_ENABLED)) || (defined(MAVERICK) && (MAVERICK))
123 #define CC_BASEBAND 1
fe8ab488 124#else
39037602
A
125 #define CC_BASEBAND 0
126#endif
127
128#if defined(EFI) && (EFI)
129 #define CC_EFI 1
130#else
131 #define CC_EFI 0
fe8ab488
A
132#endif
133
134#if defined(IBOOT) && (IBOOT)
39037602 135 #define CC_IBOOT 1
fe8ab488 136#else
39037602 137 #define CC_IBOOT 0
fe8ab488
A
138#endif
139
f427ee49
A
140#if defined(TARGET_OS_BRIDGE)
141 #define CC_BRIDGE TARGET_OS_BRIDGE
142#else
143 #define CC_BRIDGE 0
144#endif
145
146// Check if we're running on a generic, userspace platform, i.e., not in the kernel, SEP, etc.
147#ifndef CC_GENERIC_PLATFORM
148 #define CC_GENERIC_PLATFORM \
149 (!CC_RTKIT && !CC_KERNEL && !CC_USE_L4 && \
150 !CC_RTKITROM && !CC_EFI && !CC_IBOOT && \
151 !CC_USE_SEPROM && !CC_ANDROID && !CC_LINUX && \
152 !CC_BRIDGE)
153#endif
154
155// Check for availability of internal Darwin SPIs.
156#ifndef CC_DARWIN_SPIS_AVAILABLE
157 #if defined(__has_include)
158 #define CC_DARWIN_SPIS_AVAILABLE __has_include(<os/log_private.h>)
159 #else
160 #define CC_DARWIN_SPIS_AVAILABLE 0
161 #endif
162#endif
163
164// Check for open source builds
165
166// ccringbuffer availability
167// Only enable the ccringbuffer data structure in generic, userspace builds where memory allocation is not an issue.
168#ifndef CC_RINGBUFFER_AVAILABLE
169 #define CC_RINGBUFFER_AVAILABLE (CC_GENERIC_PLATFORM && CC_DARWIN_SPIS_AVAILABLE && !CC_OPEN_SOURCE)
170#endif
171
172// os_log integration
173// Only enable logging support in generic, userspace builds with the desired Darwin SPIs.
174#ifndef CC_LOGGING_AVAILABLE
175 #define CC_LOGGING_AVAILABLE (CC_GENERIC_PLATFORM && CC_DARWIN_SPIS_AVAILABLE && !CC_OPEN_SOURCE)
176#endif
177
178// FeatureFlag integration
179// Only enable feature flag support in generic, userspace builds with the desired Darwin SPIs.
180// This requires linking against libsystem_featureflags to function correctly.
181#ifndef CC_FEATURE_FLAGS_AVAILABLE
182 #if defined(__has_include)
183 #define CC_FEATURE_FLAGS_AVAILABLE __has_include(<os/feature_private.h>)
184 #else
185 #define CC_FEATURE_FLAGS_AVAILABLE 0
186 #endif
187#endif
188
189// Macro to determine if a specific feature is available.
190// Turn off all features at compile time if desired and avoid the runtime check by changing this
191// definition to 0. Limit this functionality to the same environments wherein the ringbuffer is available.
192#ifndef CC_FEATURE_ENABLED
193 #if (CC_RINGBUFFER_AVAILABLE && CC_FEATURE_FLAGS_AVAILABLE && !defined(__i386__))
194 #define CC_FEATURE_ENABLED(FEATURE) os_feature_enabled(Cryptography, FEATURE)
195 #else
196 #define CC_FEATURE_ENABLED(FEATURE) 0
197 #endif
198#endif
199
200// Trace usage of deprecated or obscure functions. For now, this is
201// completely disabled.
202#ifndef CC_LOG_TRACE
203 #define CC_LOG_TRACE 0
204#endif
205
5ba3f43e
A
206// Defined by the XNU build scripts
207// Applies to code embedded in XNU but NOT to the kext
208#if defined(XNU_KERNEL_PRIVATE)
209 #define CC_XNU_KERNEL_PRIVATE 1
210#else
211 #define CC_XNU_KERNEL_PRIVATE 0
212#endif
213
214// handle unaligned data, if the cpu cannot. Currently for gladman AES and the C version of the SHA256
215#define CC_HANDLE_UNALIGNED_DATA CC_BASEBAND
216
217// BaseBand configuration
39037602 218#if CC_BASEBAND
fe8ab488
A
219
220// -- ENDIANESS
5ba3f43e 221#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
39037602
A
222 #if defined(ENDIAN_LITTLE) || (defined(__arm__) && !defined(__BIG_ENDIAN))
223 #define __LITTLE_ENDIAN__
224 #elif !defined(ENDIAN_BIG) && !defined(__BIG_ENDIAN)
225 #error Baseband endianess not defined.
226 #endif
227 #define AESOPT_ENDIAN_NO_FILE
5ba3f43e 228#endif
fe8ab488
A
229
230// -- Architecture
39037602 231 #define CCN_UNIT_SIZE 4 // 32 bits
fe8ab488
A
232
233// -- External function
39037602 234 #define assert ASSERT // sanity
fe8ab488
A
235
236// -- Warnings
237// Ignore irrelevant warnings after verification
238// #1254-D: arithmetic on pointer to void or function type
239// #186-D: pointless comparison of unsigned integer with zero
240// #546-D: transfer of control bypasses initialization of
5ba3f43e
A
241 #ifdef __arm__
242 #pragma diag_suppress 186, 1254,546
243 #elif defined(__GNUC__)
fe8ab488 244// warning: pointer of type 'void *' used in arithmetic
39037602 245 #pragma GCC diagnostic ignored "-Wpointer-arith"
5ba3f43e 246 #endif // __arm__
d9a64523
A
247#define CC_SMALL_CODE 1
248
39037602 249#endif // CC_BASEBAND
fe8ab488 250
d9a64523
A
251#if CC_RTKIT || CC_RTKITROM
252#define CC_SMALL_CODE 1
253#endif
254
255
256#ifndef CC_SMALL_CODE
257#define CC_SMALL_CODE 0
258#endif
259
39037602
A
260//CC_XNU_KERNEL_AVAILABLE indicates the availibity of XNU kernel functions,
261//like what we have on OSX, iOS, tvOS, Watch OS
d9a64523 262#if defined(__APPLE__) && defined(__MACH__)
39037602 263 #define CC_XNU_KERNEL_AVAILABLE 1
316670eb 264#else
39037602 265 #define CC_XNU_KERNEL_AVAILABLE 0
316670eb 266#endif
39037602 267
5ba3f43e
A
268//arm arch64 definition for gcc
269#if defined(__GNUC__) && defined(__aarch64__) && !defined(__arm64__)
270 #define __arm64__
271#endif
272
39037602 273#if !defined(CCN_UNIT_SIZE)
d9a64523 274 #if defined(__arm64__) || defined(__x86_64__) || defined(_WIN64)
39037602
A
275 #define CCN_UNIT_SIZE 8
276 #elif defined(__arm__) || defined(__i386__) || defined(_WIN32)
277 #define CCN_UNIT_SIZE 4
278 #else
279 #error undefined architecture
280 #endif
316670eb
A
281#endif /* !defined(CCN_UNIT_SIZE) */
282
39037602
A
283
284//this allows corecrypto Windows development using xcode
285#if defined(CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT)
286 #if CORECRYPTO_SIMULATE_WINDOWS_ENVIRONMENT && CC_XNU_KERNEL_AVAILABLE && CORECRYPTO_DEBUG
287 #define CC_USE_ASM 0
288 #define CC_USE_HEAP_FOR_WORKSPACE 1
289 #if (CCN_UNIT_SIZE==8)
290 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 0
291 #else
292 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1
293 #endif
294 #endif
295#endif
296
297#if !defined(CCN_UINT128_SUPPORT_FOR_64BIT_ARCH)
298 #if defined(_WIN64) && defined(_WIN32) && (CCN_UNIT_SIZE==8)
299 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 0
300 #elif defined(_WIN32)
301 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1//should not be a problem
302 #else
303 #define CCN_UINT128_SUPPORT_FOR_64BIT_ARCH 1
304 #endif
305#endif
306
5ba3f43e
A
307#if defined(_MSC_VER)
308 #if defined(__clang__)
d9a64523 309 #define CC_ALIGNED(x) __attribute__ ((aligned(x))) //clang compiler
5ba3f43e
A
310 #else
311 #define CC_ALIGNED(x) __declspec(align(x)) //MS complier
312 #endif
39037602 313#else
5ba3f43e
A
314 #if __clang__ || CCN_UNIT_SIZE==8
315 #define CC_ALIGNED(x) __attribute__ ((aligned(x)))
316 #else
317 #define CC_ALIGNED(x) __attribute__ ((aligned((x)>8?8:(x))))
318 #endif
39037602
A
319#endif
320
5ba3f43e
A
321#if defined(__arm__)
322//this is copied from <arm/arch.h>, because <arm/arch.h> is not available on SEPROM environment
d9a64523 323#if defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7S__) || defined (__ARM_ARCH_7F__) || defined (__ARM_ARCH_7K__) || defined(__ARM_ARCH_7EM__)
5ba3f43e
A
324 #define _ARM_ARCH_7
325 #endif
326
327 #if defined(__ARM_ARCH_6M__) || defined(__TARGET_ARCH_6S_M) || defined (__armv6m__)
328 #define _ARM_ARCH_6M
329 #endif
330#endif
39037602 331
5ba3f43e
A
332#if defined(__arm64__) || defined(__arm__)
333 #define CCN_IOS 1
334 #define CCN_OSX 0
335#elif defined(__x86_64__) || defined(__i386__)
39037602
A
336 #define CCN_IOS 0
337 #define CCN_OSX 1
d9a64523 338#endif
fe8ab488 339
cb323159 340#if CC_USE_S3
3e170ce0 341/* For corecrypto kext, CC_STATIC should be undefined */
39037602 342 #define CC_STATIC 1
fe8ab488 343#endif
316670eb 344
39037602 345#if !defined(CC_USE_HEAP_FOR_WORKSPACE)
d9a64523 346 #if CC_USE_S3 || CC_USE_SEPROM || CC_RTKITROM
39037602 347 #define CC_USE_HEAP_FOR_WORKSPACE 0
5ba3f43e
A
348 #else
349 #define CC_USE_HEAP_FOR_WORKSPACE 1
39037602 350 #endif
fe8ab488
A
351#endif
352
3e170ce0 353/* memset_s is only available in few target */
5ba3f43e 354#if CC_USE_SEPROM || defined(__CC_ARM) \
39037602
A
355 || defined(__hexagon__) || CC_EFI
356 #define CC_HAS_MEMSET_S 0
3e170ce0 357#else
39037602 358 #define CC_HAS_MEMSET_S 1
3e170ce0
A
359#endif
360
39037602
A
361// Include target conditionals if available.
362#if defined(__has_include) /* portability */
363#if __has_include(<TargetConditionals.h>)
364#include <TargetConditionals.h>
365#endif /* __has_include(<TargetConditionals.h>) */
366#endif /* defined(__has_include) */
367
5ba3f43e 368// Disable RSA Keygen on iBridge
743345f9
A
369#if defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE && CC_KERNEL
370#define CC_DISABLE_RSAKEYGEN 1 /* for iBridge */
371#else
372#define CC_DISABLE_RSAKEYGEN 0 /* default */
373#endif
374
d9a64523 375#if (CCN_UNIT_SIZE == 8) && !( defined(_MSC_VER) && defined(__clang__))
cb323159 376#define CCEC25519_CURVE25519_64BIT 1
d9a64523 377#else
cb323159 378#define CCEC25519_CURVE25519_64BIT 0
d9a64523
A
379#endif
380
39037602
A
381//- functions implemented in assembly ------------------------------------------
382//this the list of corecrypto clients that use assembly and the clang compiler
d9a64523 383#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
39037602 384 #warning "You are using the default corecrypto configuration, assembly optimizations may not be available for your platform"
316670eb
A
385#endif
386
cb323159 387// Enable assembler in Linux if CC_LINUX_ASM is defined
f427ee49 388#if (CC_LINUX || CC_SGX) && defined(CC_LINUX_ASM) && CC_LINUX_ASM
cb323159
A
389#define CC_USE_ASM 1
390#endif
391
5ba3f43e
A
392// Use this macro to strictly disable assembly regardless of cpu/os/compiler/etc.
393// Our assembly code is not gcc compatible. Clang defines the __GNUC__ macro as well.
39037602 394#if !defined(CC_USE_ASM)
cb323159 395 #if defined(_WIN32) || CC_EFI || CC_BASEBAND || CC_XNU_KERNEL_PRIVATE || (defined(__GNUC__) && !defined(__clang__)) || defined(__ANDROID_API__) || CC_LINUX
39037602
A
396 #define CC_USE_ASM 0
397 #else
398 #define CC_USE_ASM 1
399 #endif
3e170ce0
A
400#endif
401
f427ee49
A
402#define CC_CACHE_DESCRIPTORS CC_KERNEL
403
39037602
A
404//-(1) ARM V7
405#if defined(_ARM_ARCH_7) && __clang__ && CC_USE_ASM
d9a64523 406 #define CCN_DEDICATED_SQR CC_SMALL_CODE
39037602
A
407 #define CCN_MUL_KARATSUBA 0 // no performance improvement
408 #define CCN_ADD_ASM 1
409 #define CCN_SUB_ASM 1
410 #define CCN_MUL_ASM 0
411 #define CCN_ADDMUL1_ASM 1
412 #define CCN_MUL1_ASM 1
413 #define CCN_CMP_ASM 1
cb323159
A
414 #define CCN_ADD1_ASM 1
415 #define CCN_SUB1_ASM 1
39037602
A
416 #define CCN_N_ASM 1
417 #define CCN_SET_ASM 1
418 #define CCN_SHIFT_RIGHT_ASM 1
cb323159
A
419 #if defined(__ARM_NEON__)
420 #define CCN_SHIFT_LEFT_ASM 1
421 #else
422 #define CCN_SHIFT_LEFT_ASM 0
423 #endif
f427ee49 424 #define CCN_MULMOD_224_ASM 1
cb323159 425 #define CCN_MULMOD_256_ASM 1
39037602
A
426 #define CCAES_ARM_ASM 1
427 #define CCAES_INTEL_ASM 0
d9a64523 428 #if CC_KERNEL || CC_USE_L4 || CC_IBOOT || CC_RTKIT || CC_RTKITROM || CC_USE_SEPROM || CC_USE_S3
39037602
A
429 #define CCAES_MUX 0
430 #else
431 #define CCAES_MUX 1
432 #endif
433 #define CCN_USE_BUILTIN_CLZ 1
434 #define CCSHA1_VNG_INTEL 0
435 #define CCSHA2_VNG_INTEL 0
436
437 #if defined(__ARM_NEON__) || CC_KERNEL
cb323159
A
438 #define CCSHA1_VNG_ARM 1
439 #define CCSHA2_VNG_ARM 1
39037602 440 #else /* !defined(__ARM_NEON__) */
cb323159
A
441 #define CCSHA1_VNG_ARM 0
442 #define CCSHA2_VNG_ARM 0
39037602
A
443 #endif /* !defined(__ARM_NEON__) */
444 #define CCSHA256_ARMV6M_ASM 0
445
cb323159
A
446 #define CC_ACCELERATECRYPTO 1
447
39037602 448//-(2) ARM 64
5ba3f43e 449#elif defined(__arm64__) && __clang__ && CC_USE_ASM
d9a64523 450 #define CCN_DEDICATED_SQR CC_SMALL_CODE
f427ee49 451 #define CCN_MUL_KARATSUBA 0 // 4*n CCN_UNIT extra memory required.
5ba3f43e
A
452 #define CCN_ADD_ASM 1
453 #define CCN_SUB_ASM 1
454 #define CCN_MUL_ASM 1
455 #define CCN_ADDMUL1_ASM 0
456 #define CCN_MUL1_ASM 0
457 #define CCN_CMP_ASM 1
458 #define CCN_ADD1_ASM 0
459 #define CCN_SUB1_ASM 0
460 #define CCN_N_ASM 1
461 #define CCN_SET_ASM 0
462 #define CCN_SHIFT_RIGHT_ASM 1
cb323159 463 #define CCN_SHIFT_LEFT_ASM 1
f427ee49 464 #define CCN_MULMOD_224_ASM 1
cb323159 465 #define CCN_MULMOD_256_ASM 1
5ba3f43e
A
466 #define CCAES_ARM_ASM 1
467 #define CCAES_INTEL_ASM 0
468 #define CCAES_MUX 0 // On 64bit SoC, asm is much faster than HW
469 #define CCN_USE_BUILTIN_CLZ 1
470 #define CCSHA1_VNG_INTEL 0
471 #define CCSHA2_VNG_INTEL 0
cb323159
A
472 #define CCSHA1_VNG_ARM 1
473 #define CCSHA2_VNG_ARM 1
5ba3f43e
A
474 #define CCSHA256_ARMV6M_ASM 0
475
cb323159
A
476 #define CC_ACCELERATECRYPTO 1
477
5ba3f43e 478//-(3) Intel 32/64
39037602
A
479#elif (defined(__x86_64__) || defined(__i386__)) && __clang__ && CC_USE_ASM
480 #define CCN_DEDICATED_SQR 1
f427ee49 481 #define CCN_MUL_KARATSUBA 0 // 4*n CCN_UNIT extra memory required.
39037602
A
482 /* These assembly routines only work for a single CCN_UNIT_SIZE. */
483 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8) || (defined(__i386__) && CCN_UNIT_SIZE == 4)
484 #define CCN_ADD_ASM 1
485 #define CCN_SUB_ASM 1
486 #define CCN_MUL_ASM 1
487 #else
488 #define CCN_ADD_ASM 0
489 #define CCN_SUB_ASM 0
490 #define CCN_MUL_ASM 0
491 #endif
492
493 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8)
494 #define CCN_CMP_ASM 1
495 #define CCN_N_ASM 1
496 #define CCN_SHIFT_RIGHT_ASM 1
cb323159 497 #define CCN_SHIFT_LEFT_ASM 1
39037602
A
498 #else
499 #define CCN_CMP_ASM 0
500 #define CCN_N_ASM 0
501 #define CCN_SHIFT_RIGHT_ASM 0
cb323159 502 #define CCN_SHIFT_LEFT_ASM 0
39037602
A
503 #endif
504
f427ee49
A
505 #define CCN_MULMOD_224_ASM 0
506 #if defined(__x86_64__) && CCN_UNIT_SIZE == 8 && !CC_SGX
507 #define CCN_MULMOD_256_ASM 1
508 #define CCN_ADDMUL1_ASM 1
509 #define CCN_MUL1_ASM 1
510 #else
511 #define CCN_MULMOD_256_ASM 0
512 #define CCN_ADDMUL1_ASM 0
513 #define CCN_MUL1_ASM 0
514 #endif
39037602
A
515 #define CCN_ADD1_ASM 0
516 #define CCN_SUB1_ASM 0
517 #define CCN_SET_ASM 0
518 #define CCAES_ARM_ASM 0
519 #define CCAES_INTEL_ASM 1
520 #define CCAES_MUX 0
521 #define CCN_USE_BUILTIN_CLZ 0
522 #define CCSHA1_VNG_INTEL 1
523 #define CCSHA2_VNG_INTEL 1
cb323159
A
524 #define CCSHA1_VNG_ARM 0
525 #define CCSHA2_VNG_ARM 0
39037602
A
526 #define CCSHA256_ARMV6M_ASM 0
527
cb323159
A
528 #define CC_ACCELERATECRYPTO 1
529
d9a64523 530//-(4) disable assembly
316670eb 531#else
39037602
A
532 #if CCN_UINT128_SUPPORT_FOR_64BIT_ARCH
533 #define CCN_DEDICATED_SQR 1
534 #else
535 #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
536 #endif
f427ee49 537 #define CCN_MUL_KARATSUBA 0 // 4*n CCN_UNIT extra memory required.
39037602
A
538 #define CCN_ADD_ASM 0
539 #define CCN_SUB_ASM 0
540 #define CCN_MUL_ASM 0
541 #define CCN_ADDMUL1_ASM 0
542 #define CCN_MUL1_ASM 0
543 #define CCN_CMP_ASM 0
544 #define CCN_ADD1_ASM 0
545 #define CCN_SUB1_ASM 0
546 #define CCN_N_ASM 0
547 #define CCN_SET_ASM 0
548 #define CCN_SHIFT_RIGHT_ASM 0
cb323159 549 #define CCN_SHIFT_LEFT_ASM 0
f427ee49 550 #define CCN_MULMOD_224_ASM 0
cb323159 551 #define CCN_MULMOD_256_ASM 0
39037602
A
552 #define CCAES_ARM_ASM 0
553 #define CCAES_INTEL_ASM 0
554 #define CCAES_MUX 0
555 #define CCN_USE_BUILTIN_CLZ 0
556 #define CCSHA1_VNG_INTEL 0
557 #define CCSHA2_VNG_INTEL 0
cb323159
A
558 #define CCSHA1_VNG_ARM 0
559 #define CCSHA2_VNG_ARM 0
39037602
A
560 #define CCSHA256_ARMV6M_ASM 0
561
cb323159
A
562 #define CC_ACCELERATECRYPTO 0
563
39037602 564#endif
316670eb 565
316670eb
A
566#define CC_INLINE static inline
567
39037602
A
568#ifdef __GNUC__
569 #define CC_NORETURN __attribute__((__noreturn__))
570 #define CC_NOTHROW __attribute__((__nothrow__))
571 #define CC_NONNULL(N) __attribute__((__nonnull__ N))
d9a64523 572 #define CC_NONNULL4 CC_NONNULL((4))
39037602
A
573 #define CC_NONNULL_ALL __attribute__((__nonnull__))
574 #define CC_SENTINEL __attribute__((__sentinel__))
cb323159
A
575 // 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.
576 // Specifically, do not apply CC_CONST if the function has any arguments that are pointers (directly, or indirectly)
39037602
A
577 #define CC_CONST __attribute__((__const__))
578 #define CC_PURE __attribute__((__pure__))
579 #define CC_WARN_RESULT __attribute__((__warn_unused_result__))
cb323159 580 #define CC_MALLOC_CLEAR __attribute__((__malloc__))
39037602 581 #define CC_UNUSED __attribute__((unused))
316670eb
A
582#else /* !__GNUC__ */
583/*! @parseOnly */
39037602 584 #define CC_UNUSED
fe8ab488 585/*! @parseOnly */
39037602 586 #define CC_NONNULL(N)
316670eb 587/*! @parseOnly */
39037602 588 #define CC_NONNULL4
316670eb 589/*! @parseOnly */
d9a64523 590 #define CC_NORETURN
316670eb 591/*! @parseOnly */
d9a64523 592 #define CC_NOTHROW
316670eb 593/*! @parseOnly */
39037602 594 #define CC_NONNULL_ALL
316670eb 595/*! @parseOnly */
39037602 596 #define CC_SENTINEL
316670eb 597/*! @parseOnly */
39037602 598 #define CC_CONST
316670eb 599/*! @parseOnly */
39037602 600 #define CC_PURE
316670eb 601/*! @parseOnly */
39037602 602 #define CC_WARN_RESULT
316670eb 603/*! @parseOnly */
cb323159 604 #define CC_MALLOC_CLEAR
316670eb
A
605#endif /* !__GNUC__ */
606
cb323159
A
607
608// Bridge differences between MachO and ELF compiler/assemblers. */
f427ee49 609#if CC_LINUX || CC_SGX
cb323159
A
610#define CC_ASM_SECTION_CONST .rodata
611#define CC_ASM_PRIVATE_EXTERN .hidden
f427ee49
A
612#if CC_LINUX
613// We need to be sure that assembler can access relocated C
614// symbols. Sad but this is the quickest way to do that, at least with
615// our current linux compiler (clang-3.4).
616#define CC_C_LABEL(_sym) _sym@PLT
617#else /* CC_SGX */
cb323159 618#define CC_C_LABEL(_sym) _sym
f427ee49
A
619#endif
620#define _IMM(x) $(x)
621#else /* !CC_LINUX && !CC_SGX */
cb323159
A
622#define CC_ASM_SECTION_CONST .const
623#define CC_ASM_PRIVATE_EXTERN .private_extern
624#define CC_C_LABEL(_sym) _##_sym
f427ee49
A
625#define _IMM(x) $$(x)
626#endif /* !CC_LINUX && !CC_SGX */
cb323159 627
5ba3f43e
A
628// Enable FIPSPOST function tracing only when supported. */
629#ifdef CORECRYPTO_POST_TRACE
630#define CC_FIPSPOST_TRACE 1
631#else
632#define CC_FIPSPOST_TRACE 0
633#endif
3e170ce0 634
f427ee49
A
635#ifndef CC_INTERNAL_SDK
636#if __has_include(<System/i386/cpu_capabilities.h>)
637#define CC_INTERNAL_SDK 1
638#elif __has_include(<System/arm/cpu_capabilities.h>)
639#define CC_INTERNAL_SDK 1
640#else
641#define CC_INTERNAL_SDK 0
642#endif
643#endif
644
316670eb 645#endif /* _CORECRYPTO_CC_CONFIG_H_ */