blob: 833f1526882b6e4588d3cb603360ea27ce7cea59 [file] [log] [blame]
Gilles Peskine9d6a63b2023-09-04 17:49:07 +02001/**
2 * \file mbedtls/config_adjust_legacy_crypto.h
3 * \brief Adjust legacy configuration configuration
4 *
5 * Automatically enable certain dependencies. Generally, MBEDLTS_xxx
6 * configurations need to be explicitly enabled by the user: enabling
7 * MBEDTLS_xxx_A but not MBEDTLS_xxx_B when A requires B results in a
8 * compilation error. However, we do automatically enable certain options
9 * in some circumstances. One case is if MBEDTLS_xxx_B is an internal option
10 * used to identify parts of a module that are used by other module, and we
11 * don't want to make the symbol MBEDTLS_xxx_B part of the public API.
12 * Another case is if A didn't depend on B in earlier versions, and we
13 * want to use B in A but we need to preserve backward compatibility with
14 * configurations that explicitly activate MBEDTLS_xxx_A but not
15 * MBEDTLS_xxx_B.
16 */
17/*
18 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +000019 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine9d6a63b2023-09-04 17:49:07 +020020 */
21
22#ifndef MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H
23#define MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H
24
Valerio Setti97726422023-12-28 09:55:09 +010025/* Auto-enable CIPHER_C when any of the unauthenticated ciphers is builtin
26 * in PSA. */
27#if defined(MBEDTLS_PSA_CRYPTO_C) && \
28 (defined(MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER) || \
29 defined(MBEDTLS_PSA_BUILTIN_ALG_CTR) || \
30 defined(MBEDTLS_PSA_BUILTIN_ALG_CFB) || \
31 defined(MBEDTLS_PSA_BUILTIN_ALG_OFB) || \
32 defined(MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING) || \
33 defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \
34 defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7) || \
35 defined(MBEDTLS_PSA_BUILTIN_ALG_CCM_STAR_NO_TAG))
36#define MBEDTLS_CIPHER_C
37#endif
38
Gilles Peskine9d6a63b2023-09-04 17:49:07 +020039/* Auto-enable MBEDTLS_MD_LIGHT based on MBEDTLS_MD_C.
40 * This allows checking for MD_LIGHT rather than MD_LIGHT || MD_C.
41 */
42#if defined(MBEDTLS_MD_C)
43#define MBEDTLS_MD_LIGHT
44#endif
45
46/* Auto-enable MBEDTLS_MD_LIGHT if needed by a module that didn't require it
47 * in a previous release, to ensure backwards compatibility.
48 */
49#if defined(MBEDTLS_ECJPAKE_C) || \
50 defined(MBEDTLS_PEM_PARSE_C) || \
51 defined(MBEDTLS_ENTROPY_C) || \
52 defined(MBEDTLS_PK_C) || \
53 defined(MBEDTLS_PKCS12_C) || \
54 defined(MBEDTLS_RSA_C) || \
55 defined(MBEDTLS_SSL_TLS_C) || \
56 defined(MBEDTLS_X509_USE_C) || \
57 defined(MBEDTLS_X509_CREATE_C)
58#define MBEDTLS_MD_LIGHT
59#endif
60
Valerio Setti85d2a982023-10-06 16:04:49 +020061#if defined(MBEDTLS_MD_LIGHT)
62/*
63 * - MBEDTLS_MD_CAN_xxx is defined if the md module can perform xxx.
64 * - MBEDTLS_MD_xxx_VIA_PSA is defined if the md module may perform xxx via PSA
65 * (see below).
66 * - MBEDTLS_MD_SOME_PSA is defined if at least one algorithm may be performed
67 * via PSA (see below).
68 * - MBEDTLS_MD_SOME_LEGACY is defined if at least one algorithm may be performed
69 * via a direct legacy call (see below).
70 *
71 * The md module performs an algorithm via PSA if there is a PSA hash
72 * accelerator and the PSA driver subsytem is initialized at the time the
73 * operation is started, and makes a direct legacy call otherwise.
74 */
75
76/* PSA accelerated implementations */
77#if defined(MBEDTLS_PSA_CRYPTO_C)
78
79#if defined(MBEDTLS_PSA_ACCEL_ALG_MD5)
80#define MBEDTLS_MD_CAN_MD5
81#define MBEDTLS_MD_MD5_VIA_PSA
82#define MBEDTLS_MD_SOME_PSA
83#endif
84#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1)
85#define MBEDTLS_MD_CAN_SHA1
86#define MBEDTLS_MD_SHA1_VIA_PSA
87#define MBEDTLS_MD_SOME_PSA
88#endif
89#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224)
90#define MBEDTLS_MD_CAN_SHA224
91#define MBEDTLS_MD_SHA224_VIA_PSA
92#define MBEDTLS_MD_SOME_PSA
93#endif
94#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
95#define MBEDTLS_MD_CAN_SHA256
96#define MBEDTLS_MD_SHA256_VIA_PSA
97#define MBEDTLS_MD_SOME_PSA
98#endif
99#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
100#define MBEDTLS_MD_CAN_SHA384
101#define MBEDTLS_MD_SHA384_VIA_PSA
102#define MBEDTLS_MD_SOME_PSA
103#endif
104#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512)
105#define MBEDTLS_MD_CAN_SHA512
106#define MBEDTLS_MD_SHA512_VIA_PSA
107#define MBEDTLS_MD_SOME_PSA
108#endif
109#if defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160)
110#define MBEDTLS_MD_CAN_RIPEMD160
111#define MBEDTLS_MD_RIPEMD160_VIA_PSA
112#define MBEDTLS_MD_SOME_PSA
113#endif
114#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_224)
115#define MBEDTLS_MD_CAN_SHA3_224
116#define MBEDTLS_MD_SHA3_224_VIA_PSA
117#define MBEDTLS_MD_SOME_PSA
118#endif
119#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_256)
120#define MBEDTLS_MD_CAN_SHA3_256
121#define MBEDTLS_MD_SHA3_256_VIA_PSA
122#define MBEDTLS_MD_SOME_PSA
123#endif
124#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_384)
125#define MBEDTLS_MD_CAN_SHA3_384
126#define MBEDTLS_MD_SHA3_384_VIA_PSA
127#define MBEDTLS_MD_SOME_PSA
128#endif
129#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_512)
130#define MBEDTLS_MD_CAN_SHA3_512
131#define MBEDTLS_MD_SHA3_512_VIA_PSA
132#define MBEDTLS_MD_SOME_PSA
133#endif
134#endif /* MBEDTLS_PSA_CRYPTO_C */
135
136/* Built-in implementations */
137#if defined(MBEDTLS_MD5_C)
138#define MBEDTLS_MD_CAN_MD5
139#define MBEDTLS_MD_SOME_LEGACY
140#endif
141#if defined(MBEDTLS_SHA1_C)
142#define MBEDTLS_MD_CAN_SHA1
143#define MBEDTLS_MD_SOME_LEGACY
144#endif
145#if defined(MBEDTLS_SHA224_C)
146#define MBEDTLS_MD_CAN_SHA224
147#define MBEDTLS_MD_SOME_LEGACY
148#endif
149#if defined(MBEDTLS_SHA256_C)
150#define MBEDTLS_MD_CAN_SHA256
151#define MBEDTLS_MD_SOME_LEGACY
152#endif
153#if defined(MBEDTLS_SHA384_C)
154#define MBEDTLS_MD_CAN_SHA384
155#define MBEDTLS_MD_SOME_LEGACY
156#endif
157#if defined(MBEDTLS_SHA512_C)
158#define MBEDTLS_MD_CAN_SHA512
159#define MBEDTLS_MD_SOME_LEGACY
160#endif
161#if defined(MBEDTLS_SHA3_C)
162#define MBEDTLS_MD_CAN_SHA3_224
163#define MBEDTLS_MD_CAN_SHA3_256
164#define MBEDTLS_MD_CAN_SHA3_384
165#define MBEDTLS_MD_CAN_SHA3_512
166#define MBEDTLS_MD_SOME_LEGACY
167#endif
168#if defined(MBEDTLS_RIPEMD160_C)
169#define MBEDTLS_MD_CAN_RIPEMD160
170#define MBEDTLS_MD_SOME_LEGACY
171#endif
172
173#endif /* MBEDTLS_MD_LIGHT */
174
Valerio Setti8bba0872023-12-12 11:49:02 +0100175/* BLOCK_CIPHER module can dispatch to PSA when:
176 * - PSA is enabled and drivers have been initialized
177 * - desired key type is supported on the PSA side
178 * If the above conditions are not met, but the legacy support is enabled, then
Valerio Setti2684e3f2023-12-13 16:53:02 +0100179 * BLOCK_CIPHER will dynamically fallback to it.
Valerio Setti4a5d57d2023-12-14 09:34:15 +0100180 *
181 * In case BLOCK_CIPHER is defined (see below) the following symbols/helpers
182 * can be used to define its capabilities:
183 * - MBEDTLS_BLOCK_CIPHER_SOME_PSA: there is at least 1 key type between AES,
184 * ARIA and Camellia which is supported through a driver;
185 * - MBEDTLS_BLOCK_CIPHER_xxx_VIA_PSA: xxx key type is supported through a
186 * driver;
187 * - MBEDTLS_BLOCK_CIPHER_xxx_VIA_LEGACY: xxx key type is supported through
188 * a legacy module (i.e. MBEDTLS_xxx_C)
Valerio Setti8bba0872023-12-12 11:49:02 +0100189 */
Valerio Setti8bba0872023-12-12 11:49:02 +0100190#if defined(MBEDTLS_PSA_CRYPTO_C)
191#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_AES)
192#define MBEDTLS_BLOCK_CIPHER_AES_VIA_PSA
193#define MBEDTLS_BLOCK_CIPHER_SOME_PSA
194#endif
195#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ARIA)
196#define MBEDTLS_BLOCK_CIPHER_ARIA_VIA_PSA
197#define MBEDTLS_BLOCK_CIPHER_SOME_PSA
198#endif
199#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA)
200#define MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_PSA
201#define MBEDTLS_BLOCK_CIPHER_SOME_PSA
202#endif
203#endif /* MBEDTLS_PSA_CRYPTO_C */
204
205#if defined(MBEDTLS_AES_C)
206#define MBEDTLS_BLOCK_CIPHER_AES_VIA_LEGACY
207#endif
208#if defined(MBEDTLS_ARIA_C)
209#define MBEDTLS_BLOCK_CIPHER_ARIA_VIA_LEGACY
210#endif
211#if defined(MBEDTLS_CAMELLIA_C)
212#define MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_LEGACY
213#endif
214
Valerio Setti4a5d57d2023-12-14 09:34:15 +0100215/* Helpers to state that BLOCK_CIPHER module supports AES, ARIA and/or Camellia
216 * block ciphers via either PSA or legacy. */
Valerio Setti8bba0872023-12-12 11:49:02 +0100217#if defined(MBEDTLS_BLOCK_CIPHER_AES_VIA_PSA) || \
218 defined(MBEDTLS_BLOCK_CIPHER_AES_VIA_LEGACY)
219#define MBEDTLS_BLOCK_CIPHER_CAN_AES
220#endif
221#if defined(MBEDTLS_BLOCK_CIPHER_ARIA_VIA_PSA) || \
222 defined(MBEDTLS_BLOCK_CIPHER_ARIA_VIA_LEGACY)
223#define MBEDTLS_BLOCK_CIPHER_CAN_ARIA
224#endif
225#if defined(MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_PSA) || \
226 defined(MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_LEGACY)
227#define MBEDTLS_BLOCK_CIPHER_CAN_CAMELLIA
228#endif
229
Valerio Setti4a5d57d2023-12-14 09:34:15 +0100230/* GCM_C and CCM_C can either depend on (in order of preference) BLOCK_CIPHER_C
231 * or CIPHER_C. The former is auto-enabled when:
232 * - CIPHER_C is not defined, which is also the legacy solution;
233 * - BLOCK_CIPHER_SOME_PSA because in this case BLOCK_CIPHER can take advantage
234 * of the driver's acceleration.
235 */
236#if (defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C)) && \
237 (!defined(MBEDTLS_CIPHER_C) || defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA))
238#define MBEDTLS_BLOCK_CIPHER_C
239#endif
240
Valerio Settibfa675f2023-12-20 09:52:08 +0100241/* Helpers for GCM/CCM capabilities */
242#if (defined(MBEDTLS_CIPHER_C) && defined(MBEDTLS_AES_C)) || \
243 (defined(MBEDTLS_BLOCK_CIPHER_C) && defined(MBEDTLS_BLOCK_CIPHER_CAN_AES))
244#define MBEDTLS_CCM_GCM_CAN_AES
245#endif
246
247#if (defined(MBEDTLS_CIPHER_C) && defined(MBEDTLS_ARIA_C)) || \
248 (defined(MBEDTLS_BLOCK_CIPHER_C) && defined(MBEDTLS_BLOCK_CIPHER_CAN_ARIA))
249#define MBEDTLS_CCM_GCM_CAN_ARIA
250#endif
251
252#if (defined(MBEDTLS_CIPHER_C) && defined(MBEDTLS_CAMELLIA_C)) || \
253 (defined(MBEDTLS_BLOCK_CIPHER_C) && defined(MBEDTLS_BLOCK_CIPHER_CAN_CAMELLIA))
254#define MBEDTLS_CCM_GCM_CAN_CAMELLIA
255#endif
256
Gilles Peskine9d6a63b2023-09-04 17:49:07 +0200257/* MBEDTLS_ECP_LIGHT is auto-enabled by the following symbols:
258 * - MBEDTLS_ECP_C because now it consists of MBEDTLS_ECP_LIGHT plus functions
259 * for curve arithmetic. As a consequence if MBEDTLS_ECP_C is required for
260 * some reason, then MBEDTLS_ECP_LIGHT should be enabled as well.
261 * - MBEDTLS_PK_PARSE_EC_EXTENDED and MBEDTLS_PK_PARSE_EC_COMPRESSED because
262 * these features are not supported in PSA so the only way to have them is
263 * to enable the built-in solution.
264 * Both of them are temporary dependencies:
265 * - PK_PARSE_EC_EXTENDED will be removed after #7779 and #7789
266 * - support for compressed points should also be added to PSA, but in this
267 * case there is no associated issue to track it yet.
268 * - PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE because Weierstrass key derivation
269 * still depends on ECP_LIGHT.
270 * - PK_C + USE_PSA + PSA_WANT_ALG_ECDSA is a temporary dependency which will
271 * be fixed by #7453.
272 */
273#if defined(MBEDTLS_ECP_C) || \
274 defined(MBEDTLS_PK_PARSE_EC_EXTENDED) || \
275 defined(MBEDTLS_PK_PARSE_EC_COMPRESSED) || \
276 defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR_DERIVE)
277#define MBEDTLS_ECP_LIGHT
278#endif
279
Thomas Daubney540324c2023-10-06 17:07:24 +0100280/* MBEDTLS_PK_PARSE_EC_COMPRESSED is introduced in Mbed TLS version 3.5, while
Gilles Peskine9d6a63b2023-09-04 17:49:07 +0200281 * in previous version compressed points were automatically supported as long
282 * as PK_PARSE_C and ECP_C were enabled. As a consequence, for backward
283 * compatibility, we auto-enable PK_PARSE_EC_COMPRESSED when these conditions
284 * are met. */
285#if defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_ECP_C)
286#define MBEDTLS_PK_PARSE_EC_COMPRESSED
287#endif
288
289/* Helper symbol to state that there is support for ECDH, either through
290 * library implementation (ECDH_C) or through PSA. */
291#if (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_ECDH)) || \
292 (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_ECDH_C))
293#define MBEDTLS_CAN_ECDH
294#endif
295
296/* PK module can achieve ECDSA functionalities by means of either software
297 * implementations (ECDSA_C) or through a PSA driver. The following defines
298 * are meant to list these capabilities in a general way which abstracts how
299 * they are implemented under the hood. */
300#if !defined(MBEDTLS_USE_PSA_CRYPTO)
301#if defined(MBEDTLS_ECDSA_C)
302#define MBEDTLS_PK_CAN_ECDSA_SIGN
303#define MBEDTLS_PK_CAN_ECDSA_VERIFY
304#endif /* MBEDTLS_ECDSA_C */
305#else /* MBEDTLS_USE_PSA_CRYPTO */
306#if defined(PSA_WANT_ALG_ECDSA)
307#if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC)
308#define MBEDTLS_PK_CAN_ECDSA_SIGN
309#endif /* PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC */
310#if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
311#define MBEDTLS_PK_CAN_ECDSA_VERIFY
312#endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */
313#endif /* PSA_WANT_ALG_ECDSA */
314#endif /* MBEDTLS_USE_PSA_CRYPTO */
315
316#if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY) || defined(MBEDTLS_PK_CAN_ECDSA_SIGN)
317#define MBEDTLS_PK_CAN_ECDSA_SOME
318#endif
319
320/* If MBEDTLS_PSA_CRYPTO_C is defined, make sure MBEDTLS_PSA_CRYPTO_CLIENT
321 * is defined as well to include all PSA code.
322 */
323#if defined(MBEDTLS_PSA_CRYPTO_C)
324#define MBEDTLS_PSA_CRYPTO_CLIENT
325#endif /* MBEDTLS_PSA_CRYPTO_C */
326
Tomi Fontanilles81746622023-07-16 13:06:06 +0300327/* The PK wrappers need pk_write/pk_parse functions to format RSA key objects
328 * when they are dispatching to the PSA API. This happens under MBEDTLS_USE_PSA_CRYPTO,
329 * and even under just MBEDTLS_PSA_CRYPTO_C in psa_crypto_rsa.c. */
Gilles Peskine9d6a63b2023-09-04 17:49:07 +0200330#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_RSA_C)
331#define MBEDTLS_PK_C
332#define MBEDTLS_PK_WRITE_C
333#define MBEDTLS_PK_PARSE_C
334#endif
335
Valerio Setti67d82e72023-08-16 17:11:53 +0200336/* Helpers to state that each key is supported either on the builtin or PSA side. */
337#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_521)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200338#define MBEDTLS_ECP_HAVE_SECP521R1
Valerio Setti67d82e72023-08-16 17:11:53 +0200339#endif
340#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) || defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200341#define MBEDTLS_ECP_HAVE_BP512R1
Valerio Setti67d82e72023-08-16 17:11:53 +0200342#endif
343#if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) || defined(PSA_WANT_ECC_MONTGOMERY_448)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200344#define MBEDTLS_ECP_HAVE_CURVE448
Valerio Setti67d82e72023-08-16 17:11:53 +0200345#endif
346#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200347#define MBEDTLS_ECP_HAVE_BP384R1
Valerio Setti67d82e72023-08-16 17:11:53 +0200348#endif
349#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_384)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200350#define MBEDTLS_ECP_HAVE_SECP384R1
Valerio Setti67d82e72023-08-16 17:11:53 +0200351#endif
352#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200353#define MBEDTLS_ECP_HAVE_BP256R1
Valerio Setti67d82e72023-08-16 17:11:53 +0200354#endif
355#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) || defined(PSA_WANT_ECC_SECP_K1_256)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200356#define MBEDTLS_ECP_HAVE_SECP256K1
Valerio Setti67d82e72023-08-16 17:11:53 +0200357#endif
358#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_256)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200359#define MBEDTLS_ECP_HAVE_SECP256R1
Valerio Setti67d82e72023-08-16 17:11:53 +0200360#endif
361#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || defined(PSA_WANT_ECC_MONTGOMERY_255)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200362#define MBEDTLS_ECP_HAVE_CURVE25519
Valerio Setti67d82e72023-08-16 17:11:53 +0200363#endif
364#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || defined(PSA_WANT_ECC_SECP_K1_224)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200365#define MBEDTLS_ECP_HAVE_SECP224K1
Valerio Setti67d82e72023-08-16 17:11:53 +0200366#endif
367#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_224)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200368#define MBEDTLS_ECP_HAVE_SECP224R1
Valerio Setti67d82e72023-08-16 17:11:53 +0200369#endif
370#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || defined(PSA_WANT_ECC_SECP_K1_192)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200371#define MBEDTLS_ECP_HAVE_SECP192K1
Valerio Setti67d82e72023-08-16 17:11:53 +0200372#endif
373#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_192)
Valerio Settidb6b4db2023-09-01 09:20:51 +0200374#define MBEDTLS_ECP_HAVE_SECP192R1
Valerio Setti67d82e72023-08-16 17:11:53 +0200375#endif
376
Gilles Peskine9d6a63b2023-09-04 17:49:07 +0200377/* Helper symbol to state that the PK module has support for EC keys. This
378 * can either be provided through the legacy ECP solution or through the
379 * PSA friendly MBEDTLS_PK_USE_PSA_EC_DATA (see pk.h for its description). */
380#if defined(MBEDTLS_ECP_C) || \
381 (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY))
382#define MBEDTLS_PK_HAVE_ECC_KEYS
383#endif /* MBEDTLS_PK_USE_PSA_EC_DATA || MBEDTLS_ECP_C */
384
Gilles Peskineca1e6052023-09-25 16:16:26 +0200385/* Historically pkparse did not check the CBC padding when decrypting
386 * a key. This was a bug, which is now fixed. As a consequence, pkparse
387 * now needs PKCS7 padding support, but existing configurations might not
388 * enable it, so we enable it here. */
389#if defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_PKCS5_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
390#define MBEDTLS_CIPHER_PADDING_PKCS7
391#endif
392
Dave Rodgman94a634d2023-10-10 12:59:29 +0100393/* Backwards compatibility for some macros which were renamed to reflect that
394 * they are related to Armv8, not aarch64. */
Dave Rodgmanc5861d52023-10-10 14:01:54 +0100395#if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) && \
Dave Rodgman5b89c552023-10-10 14:59:02 +0100396 !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT)
397#define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgman94a634d2023-10-10 12:59:29 +0100398#endif
Dave Rodgman5b89c552023-10-10 14:59:02 +0100399#if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY) && !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY)
400#define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
Dave Rodgman94a634d2023-10-10 12:59:29 +0100401#endif
Dave Rodgman94a634d2023-10-10 12:59:29 +0100402
Valerio Settif4d2dc22024-01-16 10:57:48 +0100403/* psa_util file features some ECDSA conversion functions, to convert between
404 * legacy's ASN.1 DER format and PSA's raw one. */
405#if defined(MBEDTLS_ECDSA_C) || defined(MBEDTLS_PSA_CRYPTO_C) && \
406 (defined(PSA_WANT_ALG_ECDSA) || defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA))
407#define MBEDTLS_PSA_UTIL_HAVE_ECDSA
408#endif
409
Yanray Wang4ed86912023-11-16 15:20:56 +0800410/* Some internal helpers to determine which keys are availble. */
411#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_AES_C)) || \
412 (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_AES))
413#define MBEDTLS_SSL_HAVE_AES
414#endif
415#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_ARIA_C)) || \
416 (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ARIA))
417#define MBEDTLS_SSL_HAVE_ARIA
418#endif
419#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CAMELLIA_C)) || \
420 (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_CAMELLIA))
421#define MBEDTLS_SSL_HAVE_CAMELLIA
422#endif
423
424/* Some internal helpers to determine which operation modes are availble. */
425#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CIPHER_MODE_CBC)) || \
426 (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CBC_NO_PADDING))
427#define MBEDTLS_SSL_HAVE_CBC
428#endif
429
Valerio Settie5707042023-10-11 11:54:42 +0200430#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_GCM_C)) || \
431 (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_GCM))
432#define MBEDTLS_SSL_HAVE_GCM
433#endif
434
435#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CCM_C)) || \
436 (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CCM))
437#define MBEDTLS_SSL_HAVE_CCM
438#endif
439
440#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CHACHAPOLY_C)) || \
441 (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CHACHA20_POLY1305))
442#define MBEDTLS_SSL_HAVE_CHACHAPOLY
443#endif
444
445#if defined(MBEDTLS_SSL_HAVE_GCM) || defined(MBEDTLS_SSL_HAVE_CCM) || \
446 defined(MBEDTLS_SSL_HAVE_CHACHAPOLY)
447#define MBEDTLS_SSL_HAVE_AEAD
448#endif
449
Gilles Peskine9d6a63b2023-09-04 17:49:07 +0200450#endif /* MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H */