1 /**
2  * \file mbedtls/config_adjust_legacy_from_psa.h
3  * \brief Adjust PSA configuration: activate legacy implementations
4  *
5  * When MBEDTLS_PSA_CRYPTO_CONFIG is enabled, activate legacy implementations
6  * of cryptographic mechanisms as needed to fulfill the needs of the PSA
7  * configuration. Generally speaking, we activate a legacy mechanism if
8  * it's needed for a requested PSA mechanism and there is no PSA driver
9  * for it.
10  */
11 /*
12  *  Copyright The Mbed TLS Contributors
13  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
14  */
15 
16 #ifndef MBEDTLS_CONFIG_ADJUST_LEGACY_FROM_PSA_H
17 #define MBEDTLS_CONFIG_ADJUST_LEGACY_FROM_PSA_H
18 
19 /* Define appropriate ACCEL macros for the p256-m driver.
20  * In the future, those should be generated from the drivers JSON description.
21  */
22 #if defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED)
23 #define MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256
24 #define MBEDTLS_PSA_ACCEL_ALG_ECDSA
25 #define MBEDTLS_PSA_ACCEL_ALG_ECDH
26 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY
27 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_BASIC
28 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_IMPORT
29 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_EXPORT
30 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_GENERATE
31 #endif
32 
33 /*
34  * ECC: support for a feature is controlled by a triplet or a pair:
35  * (curve, key_type public/basic, alg) or (curve, key_type_<action>).
36  *
37  * A triplet/pair is accelerated if all of is components are accelerated;
38  * otherwise each component needs to be built in.
39  *
40  * We proceed in two passes:
41  * 1. Check if acceleration is complete for curves, key types, algs.
42  * 2. Then enable built-ins for each thing that's either not accelerated of
43  * doesn't have complete acceleration of the other triplet/pair components.
44  *
45  * Note: this needs psa/crypto_adjust_keypair_types.h to have been included
46  * already, so that we know the full set of key types that are requested.
47  */
48 
49 /* ECC: curves: is acceleration complete? */
50 #if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256) && \
51     !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_256)
52 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
53 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
54 #endif
55 
56 #if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384) && \
57     !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_384)
58 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
59 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
60 #endif
61 
62 #if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512) && \
63     !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_512)
64 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
65 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
66 #endif
67 
68 #if defined(PSA_WANT_ECC_MONTGOMERY_255) && \
69     !defined(MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_255)
70 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
71 #endif
72 
73 #if defined(PSA_WANT_ECC_MONTGOMERY_448) && \
74     !defined(MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_448)
75 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
76 #endif
77 
78 #if defined(PSA_WANT_ECC_SECP_R1_192) && \
79     !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_192)
80 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
81 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
82 #endif
83 
84 #if defined(PSA_WANT_ECC_SECP_R1_224) && \
85     !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_224)
86 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
87 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
88 #endif
89 
90 #if defined(PSA_WANT_ECC_SECP_R1_256) && \
91     !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256)
92 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
93 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
94 #endif
95 
96 #if defined(PSA_WANT_ECC_SECP_R1_384) && \
97     !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_384)
98 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
99 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
100 #endif
101 
102 #if defined(PSA_WANT_ECC_SECP_R1_521) && \
103     !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_521)
104 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
105 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
106 #endif
107 
108 #if defined(PSA_WANT_ECC_SECP_K1_192) && \
109     !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_192)
110 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
111 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
112 #endif
113 
114 #if defined(PSA_WANT_ECC_SECP_K1_224) && \
115     !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_224)
116 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
117 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
118 #endif
119 
120 #if defined(PSA_WANT_ECC_SECP_K1_256) && \
121     !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256)
122 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES
123 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES
124 #endif
125 
126 /* ECC: algs: is acceleration complete? */
127 #if defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA) && \
128     !defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA)
129 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS
130 #endif
131 
132 #if defined(PSA_WANT_ALG_ECDH) && \
133     !defined(MBEDTLS_PSA_ACCEL_ALG_ECDH)
134 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS
135 #endif
136 
137 #if defined(PSA_WANT_ALG_ECDSA) && \
138     !defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA)
139 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS
140 #endif
141 
142 #if defined(PSA_WANT_ALG_JPAKE) && \
143     !defined(MBEDTLS_PSA_ACCEL_ALG_JPAKE)
144 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS
145 #endif
146 
147 /* ECC: key types: is acceleration complete? */
148 #if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) && \
149     !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY)
150 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES
151 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES_BASIC
152 #endif
153 
154 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC) && \
155     !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_BASIC)
156 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES
157 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES_BASIC
158 #endif
159 
160 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT) && \
161     !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_IMPORT)
162 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES
163 #endif
164 
165 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT) && \
166     !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_EXPORT)
167 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES
168 #endif
169 
170 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE) && \
171     !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_GENERATE)
172 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES
173 #endif
174 
175 /* Special case: we don't support cooked key derivation in drivers yet */
176 #if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_DERIVE)
177 #undef MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_DERIVE
178 #endif
179 
180 /* Note: the condition is always true as DERIVE can't be accelerated yet */
181 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE) && \
182     !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_DERIVE)
183 #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES
184 #endif
185 
186 /* ECC: curves: enable built-ins as needed.
187  *
188  * We need the curve built-in:
189  * - if it's not accelerated, or
190  * - if there's a key type with missing acceleration, or
191  * - if there's a alg with missing acceleration.
192  */
193 #if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
194 #if !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_256) || \
195     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
196     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
197 #define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_256 1
198 #define MBEDTLS_ECP_DP_BP256R1_ENABLED
199 #endif /* missing accel */
200 #endif /* PSA_WANT_ECC_BRAINPOOL_P_R1_256 */
201 
202 #if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
203 #if !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_384) || \
204     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
205     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
206 #define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_384 1
207 #define MBEDTLS_ECP_DP_BP384R1_ENABLED
208 #endif /* missing accel */
209 #endif /* PSA_WANT_ECC_BRAINPOOL_P_R1_384 */
210 
211 #if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
212 #if !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_512) || \
213     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
214     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
215 #define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_512 1
216 #define MBEDTLS_ECP_DP_BP512R1_ENABLED
217 #endif /* missing accel */
218 #endif /* PSA_WANT_ECC_BRAINPOOL_P_R1_512 */
219 
220 #if defined(PSA_WANT_ECC_MONTGOMERY_255)
221 #if !defined(MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_255) || \
222     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
223     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
224 #define MBEDTLS_PSA_BUILTIN_ECC_MONTGOMERY_255 1
225 #define MBEDTLS_ECP_DP_CURVE25519_ENABLED
226 #endif /* missing accel */
227 #endif /* PSA_WANT_ECC_MONTGOMERY_255 */
228 
229 #if defined(PSA_WANT_ECC_MONTGOMERY_448)
230 #if !defined(MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_448) || \
231     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
232     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
233 #define MBEDTLS_PSA_BUILTIN_ECC_MONTGOMERY_448 1
234 #define MBEDTLS_ECP_DP_CURVE448_ENABLED
235 #endif /* missing accel */
236 #endif /* PSA_WANT_ECC_MONTGOMERY_448 */
237 
238 #if defined(PSA_WANT_ECC_SECP_R1_192)
239 #if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_192) || \
240     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
241     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
242 #define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_192 1
243 #define MBEDTLS_ECP_DP_SECP192R1_ENABLED
244 #endif /* missing accel */
245 #endif /* PSA_WANT_ECC_SECP_R1_192 */
246 
247 #if defined(PSA_WANT_ECC_SECP_R1_224)
248 #if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_224) || \
249     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
250     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
251 #define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_224 1
252 #define MBEDTLS_ECP_DP_SECP224R1_ENABLED
253 #endif /* missing accel */
254 #endif /* PSA_WANT_ECC_SECP_R1_224 */
255 
256 #if defined(PSA_WANT_ECC_SECP_R1_256)
257 #if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256) || \
258     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
259     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
260 #define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_256 1
261 #define MBEDTLS_ECP_DP_SECP256R1_ENABLED
262 #endif /* missing accel */
263 #endif /* PSA_WANT_ECC_SECP_R1_256 */
264 
265 #if defined(PSA_WANT_ECC_SECP_R1_384)
266 #if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_384) || \
267     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
268     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
269 #define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_384 1
270 #define MBEDTLS_ECP_DP_SECP384R1_ENABLED
271 #endif /* missing accel */
272 #endif /* PSA_WANT_ECC_SECP_R1_384 */
273 
274 #if defined(PSA_WANT_ECC_SECP_R1_521)
275 #if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_521) || \
276     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
277     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
278 #define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_521 1
279 #define MBEDTLS_ECP_DP_SECP521R1_ENABLED
280 #endif /* missing accel */
281 #endif /* PSA_WANT_ECC_SECP_R1_521 */
282 
283 #if defined(PSA_WANT_ECC_SECP_K1_192)
284 #if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_192) || \
285     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
286     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
287 #define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_192 1
288 #define MBEDTLS_ECP_DP_SECP192K1_ENABLED
289 #endif /* missing accel */
290 #endif /* PSA_WANT_ECC_SECP_K1_192 */
291 
292 #if defined(PSA_WANT_ECC_SECP_K1_224)
293 #if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_224) || \
294     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
295     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
296 #define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_224 1
297 #define MBEDTLS_ECP_DP_SECP224K1_ENABLED
298 /* https://github.com/Mbed-TLS/mbedtls/issues/3541 */
299 #error "SECP224K1 is buggy via the PSA API in Mbed TLS."
300 #endif /* missing accel */
301 #endif /* PSA_WANT_ECC_SECP_K1_224 */
302 
303 #if defined(PSA_WANT_ECC_SECP_K1_256)
304 #if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256) || \
305     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \
306     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
307 #define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_256 1
308 #define MBEDTLS_ECP_DP_SECP256K1_ENABLED
309 #endif /* missing accel */
310 #endif /* PSA_WANT_ECC_SECP_K1_256 */
311 
312 /* ECC: algs: enable built-ins as needed.
313  *
314  * We need the alg built-in:
315  * - if it's not accelerated, or
316  * - if there's a relevant curve (see below) with missing acceleration, or
317  * - if there's a key type among (public, basic) with missing acceleration.
318  *
319  * Relevant curves are:
320  * - all curves for ECDH
321  * - Weierstrass curves for (deterministic) ECDSA
322  * - secp256r1 for EC J-PAKE
323  */
324 #if defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA)
325 #if !defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA) || \
326     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES) || \
327     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES_BASIC)
328 #define MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA 1
329 #define MBEDTLS_ECDSA_DETERMINISTIC
330 #define MBEDTLS_HMAC_DRBG_C
331 #define MBEDTLS_MD_C
332 #define MBEDTLS_ECDSA_C
333 #define MBEDTLS_ECP_C
334 #define MBEDTLS_BIGNUM_C
335 #define MBEDTLS_ASN1_PARSE_C
336 #define MBEDTLS_ASN1_WRITE_C
337 #endif /* missing accel */
338 #endif /* PSA_WANT_ALG_DETERMINISTIC_ECDSA */
339 
340 #if defined(PSA_WANT_ALG_ECDH)
341 #if !defined(MBEDTLS_PSA_ACCEL_ALG_ECDH) || \
342     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES) || \
343     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES_BASIC)
344 #define MBEDTLS_PSA_BUILTIN_ALG_ECDH 1
345 #define MBEDTLS_ECDH_C
346 #define MBEDTLS_ECP_C
347 #define MBEDTLS_BIGNUM_C
348 #endif /* missing accel */
349 #endif /* PSA_WANT_ALG_ECDH */
350 
351 #if defined(PSA_WANT_ALG_ECDSA)
352 #if !defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) || \
353     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES) || \
354     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES_BASIC)
355 #define MBEDTLS_PSA_BUILTIN_ALG_ECDSA 1
356 #define MBEDTLS_ECDSA_C
357 #define MBEDTLS_ECP_C
358 #define MBEDTLS_BIGNUM_C
359 #define MBEDTLS_ASN1_PARSE_C
360 #define MBEDTLS_ASN1_WRITE_C
361 #endif /* missing accel */
362 #endif /* PSA_WANT_ALG_ECDSA */
363 
364 #if defined(PSA_WANT_ALG_JPAKE)
365 #if !defined(MBEDTLS_PSA_ACCEL_ALG_JPAKE) || \
366     !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256) || \
367     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES_BASIC)
368 #define MBEDTLS_PSA_BUILTIN_PAKE 1
369 #define MBEDTLS_PSA_BUILTIN_ALG_JPAKE 1
370 #define MBEDTLS_ECP_DP_SECP256R1_ENABLED
371 #define MBEDTLS_BIGNUM_C
372 #define MBEDTLS_ECP_C
373 #define MBEDTLS_ECJPAKE_C
374 #endif /* missing accel */
375 #endif /* PSA_WANT_ALG_JPAKE */
376 
377 /* ECC: key types: enable built-ins as needed.
378  *
379  * We need the key type built-in:
380  * - if it's not accelerated, or
381  * - if there's a curve with missing acceleration, or
382  * - only for public/basic: if there's an alg with missing acceleration.
383  */
384 #if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
385 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) || \
386     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES) || \
387     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
388 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY 1
389 #define MBEDTLS_ECP_LIGHT
390 #define MBEDTLS_BIGNUM_C
391 #endif /* missing accel */
392 #endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */
393 
394 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC)
395 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_BASIC) || \
396     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES) || \
397     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS)
398 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR_BASIC 1
399 #define MBEDTLS_ECP_LIGHT
400 #define MBEDTLS_BIGNUM_C
401 #endif /* missing accel */
402 #endif /* PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC */
403 
404 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT)
405 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_IMPORT) || \
406     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES)
407 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR_IMPORT 1
408 #define MBEDTLS_ECP_LIGHT
409 #define MBEDTLS_BIGNUM_C
410 #endif /* missing accel */
411 #endif /* PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT */
412 
413 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT)
414 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_EXPORT) || \
415     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES)
416 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR_EXPORT 1
417 #define MBEDTLS_ECP_C
418 #define MBEDTLS_BIGNUM_C
419 #endif /* missing accel */
420 #endif /* PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT */
421 
422 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE)
423 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_GENERATE) || \
424     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES)
425 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR_GENERATE 1
426 #define MBEDTLS_ECP_C
427 #define MBEDTLS_BIGNUM_C
428 #endif /* missing accel */
429 #endif /* PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE */
430 
431 /* Note: the condition is always true as DERIVE can't be accelerated yet */
432 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE)
433 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_DERIVE) || \
434     defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES)
435 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR_DERIVE 1
436 #define MBEDTLS_ECP_LIGHT
437 #define MBEDTLS_BIGNUM_C
438 #endif /* missing accel */
439 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_DERIVE */
440 
441 /* End of ECC section */
442 
443 #if defined(PSA_WANT_ALG_FFDH)
444 #if !defined(MBEDTLS_PSA_ACCEL_ALG_FFDH)
445 #define MBEDTLS_PSA_BUILTIN_ALG_FFDH 1
446 #define MBEDTLS_BIGNUM_C
447 #endif /* !MBEDTLS_PSA_ACCEL_ALG_FFDH */
448 #endif /* PSA_WANT_ALG_FFDH */
449 
450 #if defined(PSA_WANT_ALG_HKDF)
451 #if !defined(MBEDTLS_PSA_ACCEL_ALG_HKDF)
452 /*
453  * The PSA implementation has its own implementation of HKDF, separate from
454  * hkdf.c. No need to enable MBEDTLS_HKDF_C here.
455  */
456 #define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
457 #define MBEDTLS_PSA_BUILTIN_ALG_HKDF 1
458 #endif /* !MBEDTLS_PSA_ACCEL_ALG_HKDF */
459 #endif /* PSA_WANT_ALG_HKDF */
460 
461 #if defined(PSA_WANT_ALG_HKDF_EXTRACT)
462 #if !defined(MBEDTLS_PSA_ACCEL_ALG_HKDF_EXTRACT)
463 /*
464  * The PSA implementation has its own implementation of HKDF, separate from
465  * hkdf.c. No need to enable MBEDTLS_HKDF_C here.
466  */
467 #define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
468 #define MBEDTLS_PSA_BUILTIN_ALG_HKDF_EXTRACT 1
469 #endif /* !MBEDTLS_PSA_ACCEL_ALG_HKDF_EXTRACT */
470 #endif /* PSA_WANT_ALG_HKDF_EXTRACT */
471 
472 #if defined(PSA_WANT_ALG_HKDF_EXPAND)
473 #if !defined(MBEDTLS_PSA_ACCEL_ALG_HKDF_EXPAND)
474 /*
475  * The PSA implementation has its own implementation of HKDF, separate from
476  * hkdf.c. No need to enable MBEDTLS_HKDF_C here.
477  */
478 #define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
479 #define MBEDTLS_PSA_BUILTIN_ALG_HKDF_EXPAND 1
480 #endif /* !MBEDTLS_PSA_ACCEL_ALG_HKDF_EXPAND */
481 #endif /* PSA_WANT_ALG_HKDF_EXPAND */
482 
483 #if defined(PSA_WANT_ALG_HMAC)
484 #if !defined(MBEDTLS_PSA_ACCEL_ALG_HMAC)
485 #define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
486 #endif /* !MBEDTLS_PSA_ACCEL_ALG_HMAC */
487 #endif /* PSA_WANT_ALG_HMAC */
488 
489 #if defined(PSA_WANT_ALG_MD5) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD5)
490 #define MBEDTLS_PSA_BUILTIN_ALG_MD5 1
491 #define MBEDTLS_MD5_C
492 #endif
493 
494 #if defined(PSA_WANT_ALG_RIPEMD160) && !defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160)
495 #define MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160 1
496 #define MBEDTLS_RIPEMD160_C
497 #endif
498 
499 #if defined(PSA_WANT_ALG_RSA_OAEP)
500 #if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP)
501 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP 1
502 #define MBEDTLS_RSA_C
503 #define MBEDTLS_BIGNUM_C
504 #define MBEDTLS_OID_C
505 #define MBEDTLS_PKCS1_V21
506 #endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP */
507 #endif /* PSA_WANT_ALG_RSA_OAEP */
508 
509 #if defined(PSA_WANT_ALG_RSA_PKCS1V15_CRYPT)
510 #if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT)
511 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT 1
512 #define MBEDTLS_RSA_C
513 #define MBEDTLS_BIGNUM_C
514 #define MBEDTLS_OID_C
515 #define MBEDTLS_PKCS1_V15
516 #endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT */
517 #endif /* PSA_WANT_ALG_RSA_PKCS1V15_CRYPT */
518 
519 #if defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN)
520 #if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN)
521 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN 1
522 #define MBEDTLS_RSA_C
523 #define MBEDTLS_BIGNUM_C
524 #define MBEDTLS_OID_C
525 #define MBEDTLS_PKCS1_V15
526 #endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN */
527 #endif /* PSA_WANT_ALG_RSA_PKCS1V15_SIGN */
528 
529 #if defined(PSA_WANT_ALG_RSA_PSS)
530 #if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS)
531 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS 1
532 #define MBEDTLS_RSA_C
533 #define MBEDTLS_BIGNUM_C
534 #define MBEDTLS_OID_C
535 #define MBEDTLS_PKCS1_V21
536 #endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_PSS */
537 #endif /* PSA_WANT_ALG_RSA_PSS */
538 
539 #if defined(PSA_WANT_ALG_SHA_1) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1)
540 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_1 1
541 #define MBEDTLS_SHA1_C
542 #endif
543 
544 #if defined(PSA_WANT_ALG_SHA_224) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224)
545 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_224 1
546 #define MBEDTLS_SHA224_C
547 #endif
548 
549 #if defined(PSA_WANT_ALG_SHA_256) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
550 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_256 1
551 #define MBEDTLS_SHA256_C
552 #endif
553 
554 #if defined(PSA_WANT_ALG_SHA_384) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
555 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_384 1
556 #define MBEDTLS_SHA384_C
557 #endif
558 
559 #if defined(PSA_WANT_ALG_SHA_512) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512)
560 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_512 1
561 #define MBEDTLS_SHA512_C
562 #endif
563 
564 #if defined(PSA_WANT_ALG_SHA3_224) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_224)
565 #define MBEDTLS_PSA_BUILTIN_ALG_SHA3_224 1
566 #define MBEDTLS_SHA3_C
567 #endif
568 
569 #if defined(PSA_WANT_ALG_SHA3_256) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_256)
570 #define MBEDTLS_PSA_BUILTIN_ALG_SHA3_256 1
571 #define MBEDTLS_SHA3_C
572 #endif
573 
574 #if defined(PSA_WANT_ALG_SHA3_384) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_384)
575 #define MBEDTLS_PSA_BUILTIN_ALG_SHA3_384 1
576 #define MBEDTLS_SHA3_C
577 #endif
578 
579 #if defined(PSA_WANT_ALG_SHA3_512) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_512)
580 #define MBEDTLS_PSA_BUILTIN_ALG_SHA3_512 1
581 #define MBEDTLS_SHA3_C
582 #endif
583 
584 #if defined(PSA_WANT_ALG_PBKDF2_HMAC)
585 #if !defined(MBEDTLS_PSA_ACCEL_ALG_PBKDF2_HMAC)
586 #define MBEDTLS_PSA_BUILTIN_ALG_PBKDF2_HMAC 1
587 #define PSA_HAVE_SOFT_PBKDF2_HMAC 1
588 #if !defined(MBEDTLS_PSA_ACCEL_ALG_HMAC)
589 #define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
590 #endif /* !MBEDTLS_PSA_ACCEL_ALG_HMAC */
591 #endif /* !MBEDTLS_PSA_BUILTIN_ALG_PBKDF2_HMAC */
592 #endif /* PSA_WANT_ALG_PBKDF2_HMAC */
593 
594 #if defined(PSA_WANT_ALG_TLS12_PRF)
595 #if !defined(MBEDTLS_PSA_ACCEL_ALG_TLS12_PRF)
596 #define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF 1
597 #endif /* !MBEDTLS_PSA_ACCEL_ALG_TLS12_PRF */
598 #endif /* PSA_WANT_ALG_TLS12_PRF */
599 
600 #if defined(PSA_WANT_ALG_TLS12_PSK_TO_MS)
601 #if !defined(MBEDTLS_PSA_ACCEL_ALG_TLS12_PSK_TO_MS)
602 #define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS 1
603 #endif /* !MBEDTLS_PSA_ACCEL_ALG_TLS12_PSK_TO_MS */
604 #endif /* PSA_WANT_ALG_TLS12_PSK_TO_MS */
605 
606 #if defined(PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS)
607 #if !defined(MBEDTLS_PSA_ACCEL_ALG_TLS12_ECJPAKE_TO_PMS)
608 #define MBEDTLS_PSA_BUILTIN_ALG_TLS12_ECJPAKE_TO_PMS 1
609 #endif /* !MBEDTLS_PSA_ACCEL_ALG_TLS12_ECJPAKE_TO_PMS */
610 #endif /* PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS */
611 
612 #if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT)
613 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_IMPORT)
614 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
615 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_IMPORT */
616 #endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT */
617 
618 #if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT)
619 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_EXPORT)
620 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
621 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_EXPORT */
622 #endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT */
623 
624 #if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE)
625 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_GENERATE)
626 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
627 #define MBEDTLS_GENPRIME
628 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_GENERATE */
629 #endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE */
630 
631 #if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC)
632 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_BASIC)
633 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
634 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_BASIC */
635 #endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC */
636 
637 #if defined(PSA_WANT_KEY_TYPE_DH_KEY_PAIR_IMPORT)
638 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_IMPORT)
639 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_DH_KEY_PAIR_IMPORT 1
640 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_IMPORT */
641 #endif /* PSA_WANT_KEY_TYPE_DH_KEY_PAIR_IMPORT */
642 
643 #if defined(PSA_WANT_KEY_TYPE_DH_KEY_PAIR_EXPORT)
644 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_EXPORT)
645 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_DH_KEY_PAIR_EXPORT 1
646 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_EXPORT */
647 #endif /* PSA_WANT_KEY_TYPE_DH_KEY_PAIR_EXPORT */
648 
649 #if defined(PSA_WANT_KEY_TYPE_DH_KEY_PAIR_GENERATE)
650 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_GENERATE)
651 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_DH_KEY_PAIR_GENERATE 1
652 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_GENERATE */
653 #endif /* PSA_WANT_KEY_TYPE_DH_KEY_PAIR_GENERATE */
654 
655 #if defined(PSA_WANT_KEY_TYPE_DH_KEY_PAIR_BASIC)
656 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_BASIC)
657 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_DH_KEY_PAIR_BASIC 1
658 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_BASIC */
659 #endif /* PSA_WANT_KEY_TYPE_DH_KEY_PAIR_BASIC */
660 
661 #if defined(PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY)
662 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_PUBLIC_KEY)
663 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_DH_PUBLIC_KEY 1
664 #define MBEDTLS_BIGNUM_C
665 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_PUBLIC_KEY */
666 #endif /* PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY */
667 
668 #if defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY)
669 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY)
670 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY 1
671 #define MBEDTLS_RSA_C
672 #define MBEDTLS_BIGNUM_C
673 #define MBEDTLS_OID_C
674 #define MBEDTLS_PK_PARSE_C
675 #define MBEDTLS_PK_WRITE_C
676 #define MBEDTLS_PK_C
677 #define MBEDTLS_ASN1_PARSE_C
678 #define MBEDTLS_ASN1_WRITE_C
679 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY */
680 #endif /* PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY */
681 
682 /* If any of the block modes are requested that don't have an
683  * associated HW assist, define PSA_HAVE_SOFT_BLOCK_MODE for checking
684  * in the block cipher key types. */
685 #if (defined(PSA_WANT_ALG_CTR) && !defined(MBEDTLS_PSA_ACCEL_ALG_CTR)) || \
686     (defined(PSA_WANT_ALG_CFB) && !defined(MBEDTLS_PSA_ACCEL_ALG_CFB)) || \
687     (defined(PSA_WANT_ALG_OFB) && !defined(MBEDTLS_PSA_ACCEL_ALG_OFB)) || \
688     defined(PSA_WANT_ALG_ECB_NO_PADDING) || \
689     (defined(PSA_WANT_ALG_CBC_NO_PADDING) && \
690     !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING)) || \
691     (defined(PSA_WANT_ALG_CBC_PKCS7) && \
692     !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7)) || \
693     (defined(PSA_WANT_ALG_CMAC) && !defined(MBEDTLS_PSA_ACCEL_ALG_CMAC))
694 #define PSA_HAVE_SOFT_BLOCK_MODE 1
695 #endif
696 
697 #if (defined(PSA_WANT_ALG_GCM) && !defined(MBEDTLS_PSA_ACCEL_ALG_GCM)) || \
698     (defined(PSA_WANT_ALG_CCM) && !defined(MBEDTLS_PSA_ACCEL_ALG_CCM))
699 #define PSA_HAVE_SOFT_BLOCK_AEAD 1
700 #endif
701 
702 #if defined(PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128)
703 #if !defined(MBEDTLS_PSA_ACCEL_ALG_PBKDF2_AES_CMAC_PRF_128)
704 #define MBEDTLS_PSA_BUILTIN_ALG_PBKDF2_AES_CMAC_PRF_128 1
705 #define PSA_HAVE_SOFT_PBKDF2_CMAC 1
706 #endif /* !MBEDTLS_PSA_ACCEL_ALG_PBKDF2_AES_CMAC_PRF_128 */
707 #endif /* PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 */
708 
709 #if defined(PSA_WANT_KEY_TYPE_AES)
710 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_AES)
711 #define PSA_HAVE_SOFT_KEY_TYPE_AES 1
712 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_AES */
713 #if defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \
714     defined(PSA_HAVE_SOFT_BLOCK_MODE) || \
715     defined(PSA_HAVE_SOFT_BLOCK_AEAD) || \
716     defined(PSA_HAVE_SOFT_PBKDF2_CMAC)
717 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_AES 1
718 #define MBEDTLS_AES_C
719 #endif /* PSA_HAVE_SOFT_KEY_TYPE_AES || PSA_HAVE_SOFT_BLOCK_MODE */
720 #endif /* PSA_WANT_KEY_TYPE_AES */
721 
722 #if defined(PSA_WANT_KEY_TYPE_ARIA)
723 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ARIA)
724 #define PSA_HAVE_SOFT_KEY_TYPE_ARIA 1
725 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_ARIA */
726 #if defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \
727     defined(PSA_HAVE_SOFT_BLOCK_MODE) || \
728     defined(PSA_HAVE_SOFT_BLOCK_AEAD)
729 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARIA 1
730 #define MBEDTLS_ARIA_C
731 #endif /* PSA_HAVE_SOFT_KEY_TYPE_ARIA || PSA_HAVE_SOFT_BLOCK_MODE */
732 #endif /* PSA_WANT_KEY_TYPE_ARIA */
733 
734 #if defined(PSA_WANT_KEY_TYPE_CAMELLIA)
735 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA)
736 #define PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA 1
737 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA */
738 #if defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA) || \
739     defined(PSA_HAVE_SOFT_BLOCK_MODE) || \
740     defined(PSA_HAVE_SOFT_BLOCK_AEAD)
741 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CAMELLIA 1
742 #define MBEDTLS_CAMELLIA_C
743 #endif /* PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA || PSA_HAVE_SOFT_BLOCK_MODE */
744 #endif /* PSA_WANT_KEY_TYPE_CAMELLIA */
745 
746 #if defined(PSA_WANT_KEY_TYPE_DES)
747 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_DES)
748 #define PSA_HAVE_SOFT_KEY_TYPE_DES 1
749 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_DES */
750 #if defined(PSA_HAVE_SOFT_KEY_TYPE_DES) || \
751     defined(PSA_HAVE_SOFT_BLOCK_MODE)
752 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES 1
753 #define MBEDTLS_DES_C
754 #endif /*PSA_HAVE_SOFT_KEY_TYPE_DES || PSA_HAVE_SOFT_BLOCK_MODE */
755 #endif /* PSA_WANT_KEY_TYPE_DES */
756 
757 #if defined(PSA_WANT_KEY_TYPE_CHACHA20)
758 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CHACHA20)
759 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CHACHA20 1
760 #define MBEDTLS_CHACHA20_C
761 #endif /*!MBEDTLS_PSA_ACCEL_KEY_TYPE_CHACHA20 */
762 #endif /* PSA_WANT_KEY_TYPE_CHACHA20 */
763 
764 /* If any of the software block ciphers are selected, define
765  * PSA_HAVE_SOFT_BLOCK_CIPHER, which can be used in any of these
766  * situations. */
767 #if defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \
768     defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \
769     defined(PSA_HAVE_SOFT_KEY_TYPE_DES) || \
770     defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA)
771 #define PSA_HAVE_SOFT_BLOCK_CIPHER 1
772 #endif
773 
774 #if defined(PSA_WANT_ALG_STREAM_CIPHER)
775 #define MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER 1
776 #endif /* PSA_WANT_ALG_STREAM_CIPHER */
777 
778 #if defined(PSA_WANT_ALG_CBC_MAC)
779 #if !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_MAC)
780 #error "CBC-MAC is not yet supported via the PSA API in Mbed TLS."
781 #define MBEDTLS_PSA_BUILTIN_ALG_CBC_MAC 1
782 #endif /* !MBEDTLS_PSA_ACCEL_ALG_CBC_MAC */
783 #endif /* PSA_WANT_ALG_CBC_MAC */
784 
785 #if defined(PSA_WANT_ALG_CMAC)
786 #if !defined(MBEDTLS_PSA_ACCEL_ALG_CMAC) || \
787     defined(PSA_HAVE_SOFT_BLOCK_CIPHER) || \
788     defined(PSA_HAVE_SOFT_PBKDF2_CMAC)
789 #define MBEDTLS_PSA_BUILTIN_ALG_CMAC 1
790 #define MBEDTLS_CMAC_C
791 #endif /* !MBEDTLS_PSA_ACCEL_ALG_CMAC */
792 #endif /* PSA_WANT_ALG_CMAC */
793 
794 #if defined(PSA_HAVE_SOFT_PBKDF2_HMAC) || \
795     defined(PSA_HAVE_SOFT_PBKDF2_CMAC)
796 #define PSA_HAVE_SOFT_PBKDF2 1
797 #endif /* PSA_HAVE_SOFT_PBKDF2_HMAC || PSA_HAVE_SOFT_PBKDF2_CMAC */
798 
799 #if defined(PSA_WANT_ALG_CTR)
800 #if !defined(MBEDTLS_PSA_ACCEL_ALG_CTR) || \
801     defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
802 #define MBEDTLS_PSA_BUILTIN_ALG_CTR 1
803 #define MBEDTLS_CIPHER_MODE_CTR
804 #endif
805 #endif /* PSA_WANT_ALG_CTR */
806 
807 #if defined(PSA_WANT_ALG_CFB)
808 #if !defined(MBEDTLS_PSA_ACCEL_ALG_CFB) || \
809     defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
810 #define MBEDTLS_PSA_BUILTIN_ALG_CFB 1
811 #define MBEDTLS_CIPHER_MODE_CFB
812 #endif
813 #endif /* PSA_WANT_ALG_CFB */
814 
815 #if defined(PSA_WANT_ALG_OFB)
816 #if !defined(MBEDTLS_PSA_ACCEL_ALG_OFB) || \
817     defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
818 #define MBEDTLS_PSA_BUILTIN_ALG_OFB 1
819 #define MBEDTLS_CIPHER_MODE_OFB
820 #endif
821 #endif /* PSA_WANT_ALG_OFB */
822 
823 #if defined(PSA_WANT_ALG_ECB_NO_PADDING) &&     \
824     !defined(MBEDTLS_PSA_ACCEL_ALG_ECB_NO_PADDING)
825 #define MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING 1
826 #endif
827 
828 #if defined(PSA_WANT_ALG_CBC_NO_PADDING)
829 #if !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING) || \
830     defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
831 #define MBEDTLS_CIPHER_MODE_CBC
832 #define MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING 1
833 #endif
834 #endif /* PSA_WANT_ALG_CBC_NO_PADDING */
835 
836 #if defined(PSA_WANT_ALG_CBC_PKCS7)
837 #if !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7) || \
838     defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
839 #define MBEDTLS_CIPHER_MODE_CBC
840 #define MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7 1
841 #define MBEDTLS_CIPHER_PADDING_PKCS7
842 #endif
843 #endif /* PSA_WANT_ALG_CBC_PKCS7 */
844 
845 #if defined(PSA_WANT_ALG_CCM)
846 #if !defined(MBEDTLS_PSA_ACCEL_ALG_CCM) || \
847     defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \
848     defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \
849     defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA)
850 #define MBEDTLS_PSA_BUILTIN_ALG_CCM 1
851 #define MBEDTLS_PSA_BUILTIN_ALG_CCM_STAR_NO_TAG 1
852 #define MBEDTLS_CCM_C
853 #endif
854 #endif /* PSA_WANT_ALG_CCM */
855 
856 #if defined(PSA_WANT_ALG_GCM)
857 #if !defined(MBEDTLS_PSA_ACCEL_ALG_GCM) || \
858     defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \
859     defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \
860     defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA)
861 #define MBEDTLS_PSA_BUILTIN_ALG_GCM 1
862 #define MBEDTLS_GCM_C
863 #endif
864 #endif /* PSA_WANT_ALG_GCM */
865 
866 #if defined(PSA_WANT_ALG_CHACHA20_POLY1305)
867 #if !defined(MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305)
868 #if defined(PSA_WANT_KEY_TYPE_CHACHA20)
869 #define MBEDTLS_CHACHAPOLY_C
870 #define MBEDTLS_CHACHA20_C
871 #define MBEDTLS_POLY1305_C
872 #define MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 1
873 #endif /* PSA_WANT_KEY_TYPE_CHACHA20 */
874 #endif /* !MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305 */
875 #endif /* PSA_WANT_ALG_CHACHA20_POLY1305 */
876 
877 #endif /* MBEDTLS_CONFIG_ADJUST_LEGACY_FROM_PSA_H */
878