]> git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/cc_config.h
45979d8cf81c60174c06a304fb7b61f3867025f7
[apple/xnu.git] / EXTERNAL_HEADERS / corecrypto / cc_config.h
1 /*
2 * cc_config.h
3 * corecrypto
4 *
5 * Created on 11/16/2010
6 *
7 * Copyright (c) 2010,2011,2012,2013,2014,2015 Apple Inc. All rights reserved.
8 *
9 */
10
11 #ifndef _CORECRYPTO_CC_CONFIG_H_
12 #define _CORECRYPTO_CC_CONFIG_H_
13
14 /* A word about configuration macros:
15
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.
19
20 They should always be tested using the #if directive, never the #ifdef directive.
21
22 No other conditional macros shall ever be used (except in this file)
23
24 Configuration Macros that are defined outside of corecrypto (eg: KERNEL, DEBUG, ...)
25 shall only be used in this file to define CCxxx macros.
26
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:
30
31 #if defined(DEBUG) && (DEBUG)
32 #define CORECRYPTO_DEBUG 1
33 #else
34 #define CORECRYPTO_DEBUG 0
35 #endif
36
37
38 It is acceptable to define a conditional CC_xxxx macro in an implementation file,
39 to be used only in this file.
40
41 The current code is not guaranteed to follow those rules, but should be fixed to.
42
43 Corecrypto requires GNU and C99 compatibility.
44 Typically enabled by passing --gnu --c99 to the compiler (eg. armcc)
45
46 */
47
48 #if (defined(DEBUG) && (DEBUG))
49 /* CC_DEBUG is already used in CommonCrypto */
50 #define CORECRYPTO_DEBUG 1
51 #else
52 #define CORECRYPTO_DEBUG 0
53 #endif
54
55 #if defined(KERNEL) && (KERNEL)
56 #define CC_KERNEL 1 // KEXT, XNU repo or kernel components such as AppleKeyStore
57 #else
58 #define CC_KERNEL 0
59 #endif
60
61 // LINUX_BUILD_TEST is for sanity check of the configuration
62 // > xcodebuild -scheme "corecrypto_test" OTHER_CFLAGS="$(values) -DLINUX_BUILD_TEST"
63 #if defined(__linux__) || defined(LINUX_BUILD_TEST)
64 #define CC_LINUX 1
65 #else
66 #define CC_LINUX 0
67 #endif
68
69 #if defined(USE_L4) && (USE_L4)
70 #define CC_USE_L4 1
71 #else
72 #define CC_USE_L4 0
73 #endif
74
75 #if defined(USE_SEPROM) && (USE_SEPROM)
76 #define CC_USE_SEPROM 1
77 #else
78 #define CC_USE_SEPROM 0
79 #endif
80
81 #if defined(USE_S3) && (USE_S3)
82 #define CC_USE_S3 1
83 #else
84 #define CC_USE_S3 0
85 #endif
86
87 #if defined(MAVERICK) && (MAVERICK)
88 #define CC_MAVERICK 1
89 #else
90 #define CC_MAVERICK 0
91 #endif
92
93 #if defined(IBOOT) && (IBOOT)
94 #define CC_IBOOT 1
95 #else
96 #define CC_IBOOT 0
97 #endif
98
99 // BB configuration
100 #if CC_MAVERICK
101
102 // -- ENDIANESS
103 #if defined(ENDIAN_LITTLE) || (defined(__arm__) && !defined(__BIG_ENDIAN))
104 #define __LITTLE_ENDIAN__
105 #elif !defined(ENDIAN_BIG) && !defined(__BIG_ENDIAN)
106 #error Baseband endianess not defined.
107 #endif
108 #define AESOPT_ENDIAN_NO_FILE
109
110 // -- Architecture
111 #define CCN_UNIT_SIZE 4 // 32 bits
112 #define aligned(x) aligned((x)>8?8:(x)) // Alignment on 8 bytes max
113 #define SAFE_IO // AES support for unaligned Input/Output
114
115 // -- External function
116 #define assert ASSERT // sanity
117
118 // -- Warnings
119 // Ignore irrelevant warnings after verification
120 // #1254-D: arithmetic on pointer to void or function type
121 // #186-D: pointless comparison of unsigned integer with zero
122 // #546-D: transfer of control bypasses initialization of
123 #if defined(__GNUC__)
124 // warning: pointer of type 'void *' used in arithmetic
125 #pragma GCC diagnostic ignored "-Wpointer-arith"
126 #endif // arm or gnuc
127
128 #endif // MAVERICK
129
130 #if !defined(CCN_UNIT_SIZE)
131 #if defined(__arm64__) || defined(__x86_64__)
132 #define CCN_UNIT_SIZE 8
133 #elif defined(__arm__) || defined(__i386__)
134 #define CCN_UNIT_SIZE 4
135 #else
136 #define CCN_UNIT_SIZE 2
137 #endif
138 #endif /* !defined(CCN_UNIT_SIZE) */
139
140 #if defined(__x86_64__) || defined(__i386__)
141 #define CCN_IOS 0
142 #define CCN_OSX 1
143 #endif
144
145 #if CC_USE_L4 || CC_USE_S3
146 /* No dynamic linking allowed in L4, e.g. avoid nonlazy symbols */
147 /* For corecrypto kext, CC_STATIC should be undefined */
148 #define CC_STATIC 1
149 #endif
150
151 #if CC_USE_L4 || CC_IBOOT
152 /* For L4, stack is too short, need to use HEAP for some computations */
153 /* CC_USE_HEAP_FOR_WORKSPACE not supported for KERNEL! */
154 #define CC_USE_HEAP_FOR_WORKSPACE 1
155 #else
156 #define CC_USE_HEAP_FOR_WORKSPACE 0
157 #endif
158
159 /* L4 do not have bzero, neither does hexagon of ARMCC even with gnu compatibility mode */
160 #if CC_USE_L4 || defined(__CC_ARM) || defined(__hexagon__)
161 #define CC_HAS_BZERO 0
162 #else
163 #define CC_HAS_BZERO 1
164 #endif
165
166 /* memset_s is only available in few target */
167 #if CC_USE_L4 || CC_KERNEL || CC_IBOOT || CC_USE_SEPROM || defined(__CC_ARM) || defined(__hexagon__)
168 #define CC_HAS_MEMSET_S 0
169 #else
170 #define CC_HAS_MEMSET_S 1
171 #endif
172
173
174 #if defined(__CC_ARM) || defined(__hexagon__) || CC_LINUX || defined(__NO_ASM__)
175 // ARMASM.exe does not to like the file syntax of the asm implementation
176 #define CCN_DEDICATED_SQR 1
177 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
178 #define CCN_ADD_ASM 0
179 #define CCN_SUB_ASM 0
180 #define CCN_MUL_ASM 0
181 #define CCN_ADDMUL1_ASM 0
182 #define CCN_MUL1_ASM 0
183 #define CCN_CMP_ASM 0
184 #define CCN_ADD1_ASM 0
185 #define CCN_SUB1_ASM 0
186 #define CCN_N_ASM 0
187 #define CCN_SET_ASM 0
188 #define CCAES_ARM 0
189 #define CCAES_INTEL 0
190 #define CCN_USE_BUILTIN_CLZ 0
191 #if !defined(__NO_ASM__)
192 #define CCSHA1_VNG_INTEL 0
193 #define CCSHA2_VNG_INTEL 0
194 #define CCSHA1_VNG_ARMV7NEON 0
195 #define CCSHA2_VNG_ARMV7NEON 0
196 #endif
197 #define CCAES_MUX 0
198
199 #elif defined(__x86_64__) || defined(__i386__)
200 #define CCN_DEDICATED_SQR 1
201 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
202 /* These assembly routines only work for a single CCN_UNIT_SIZE. */
203 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8) || (defined(__i386__) && CCN_UNIT_SIZE == 4)
204 #define CCN_ADD_ASM 1
205 #define CCN_SUB_ASM 1
206 #define CCN_MUL_ASM 0
207 #else
208 #define CCN_ADD_ASM 0
209 #define CCN_SUB_ASM 0
210 #define CCN_MUL_ASM 0
211 #endif
212
213 #if (defined(__x86_64__) && CCN_UNIT_SIZE == 8)
214 #define CCN_CMP_ASM 1
215 #define CCN_N_ASM 1
216 #else
217 #define CCN_CMP_ASM 0
218 #define CCN_N_ASM 0
219 #endif
220
221 #define CCN_ADDMUL1_ASM 0
222 #define CCN_MUL1_ASM 0
223 #define CCN_ADD1_ASM 0
224 #define CCN_SUB1_ASM 0
225 #define CCN_SET_ASM 0
226 #define CCAES_ARM 0
227 #define CCAES_INTEL 1
228 #define CCAES_MUX 0
229 #define CCN_USE_BUILTIN_CLZ 0
230 #define CCSHA1_VNG_INTEL 1
231 #define CCSHA2_VNG_INTEL 1
232 #define CCSHA1_VNG_ARMV7NEON 0
233 #define CCSHA2_VNG_ARMV7NEON 0
234
235 #else
236 #define CCN_DEDICATED_SQR 1
237 #define CCN_MUL_KARATSUBA 1 // 4*n CCN_UNIT extra memory required.
238 #define CCN_ADD_ASM 0
239 #define CCN_SUB_ASM 0
240 #define CCN_MUL_ASM 0
241 #define CCN_ADDMUL1_ASM 0
242 #define CCN_MUL1_ASM 0
243 #define CCN_CMP_ASM 0
244 #define CCN_ADD1_ASM 0
245 #define CCN_SUB1_ASM 0
246 #define CCN_N_ASM 0
247 #define CCN_SET_ASM 0
248 #define CCAES_ARM 0
249 #define CCAES_INTEL 0
250 #define CCAES_MUX 0
251 #define CCN_USE_BUILTIN_CLZ 0
252 #define CCSHA1_VNG_INTEL 0
253 #define CCSHA2_VNG_INTEL 0
254 #define CCSHA1_VNG_ARMV7NEON 0
255 #define CCSHA2_VNG_ARMV7NEON 0
256
257 #endif /* !defined(__i386__) */
258
259 #define CC_INLINE static inline
260
261 #ifdef __GNUC__
262 #define CC_NORETURN __attribute__((__noreturn__))
263 #define CC_NOTHROW __attribute__((__nothrow__))
264 // Transparent Union
265 #if defined(__CC_ARM) || defined(__hexagon__)
266 #define CC_NONNULL_TU(N)
267 #else
268 #define CC_NONNULL_TU(N) __attribute__((__nonnull__ N))
269 #endif
270 #define CC_NONNULL(N) __attribute__((__nonnull__ N))
271 #define CC_NONNULL1 __attribute__((__nonnull__(1)))
272 #define CC_NONNULL2 __attribute__((__nonnull__(2)))
273 #define CC_NONNULL3 __attribute__((__nonnull__(3)))
274 #define CC_NONNULL4 __attribute__((__nonnull__(4)))
275 #define CC_NONNULL5 __attribute__((__nonnull__(5)))
276 #define CC_NONNULL6 __attribute__((__nonnull__(6)))
277 #define CC_NONNULL7 __attribute__((__nonnull__(7)))
278 #define CC_NONNULL_ALL __attribute__((__nonnull__))
279 #define CC_SENTINEL __attribute__((__sentinel__))
280 #define CC_CONST __attribute__((__const__))
281 #define CC_PURE __attribute__((__pure__))
282 #define CC_WARN_RESULT __attribute__((__warn_unused_result__))
283 #define CC_MALLOC __attribute__((__malloc__))
284 #define CC_UNUSED __attribute__((unused))
285 #else /* !__GNUC__ */
286 /*! @parseOnly */
287 #define CC_UNUSED
288 /*! @parseOnly */
289 #define CC_NONNULL_TU(N)
290 /*! @parseOnly */
291 #define CC_NONNULL(N)
292 /*! @parseOnly */
293 #define CC_NORETURN
294 /*! @parseOnly */
295 #define CC_NOTHROW
296 /*! @parseOnly */
297 #define CC_NONNULL1
298 /*! @parseOnly */
299 #define CC_NONNULL2
300 /*! @parseOnly */
301 #define CC_NONNULL3
302 /*! @parseOnly */
303 #define CC_NONNULL4
304 /*! @parseOnly */
305 #define CC_NONNULL5
306 /*! @parseOnly */
307 #define CC_NONNULL6
308 /*! @parseOnly */
309 #define CC_NONNULL7
310 /*! @parseOnly */
311 #define CC_NONNULL_ALL
312 /*! @parseOnly */
313 #define CC_SENTINEL
314 /*! @parseOnly */
315 #define CC_CONST
316 /*! @parseOnly */
317 #define CC_PURE
318 /*! @parseOnly */
319 #define CC_WARN_RESULT
320 /*! @parseOnly */
321 #define CC_MALLOC
322 #endif /* !__GNUC__ */
323
324
325 #endif /* _CORECRYPTO_CC_CONFIG_H_ */