Gilles Peskine | 9d6a63b | 2023-09-04 17:49:07 +0200 | [diff] [blame] | 1 | /** |
| 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 Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 19 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | 9d6a63b | 2023-09-04 17:49:07 +0200 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H |
| 23 | #define MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H |
| 24 | |
| 25 | /* Auto-enable MBEDTLS_MD_LIGHT based on MBEDTLS_MD_C. |
| 26 | * This allows checking for MD_LIGHT rather than MD_LIGHT || MD_C. |
| 27 | */ |
| 28 | #if defined(MBEDTLS_MD_C) |
| 29 | #define MBEDTLS_MD_LIGHT |
| 30 | #endif |
| 31 | |
| 32 | /* Auto-enable MBEDTLS_MD_LIGHT if needed by a module that didn't require it |
| 33 | * in a previous release, to ensure backwards compatibility. |
| 34 | */ |
| 35 | #if defined(MBEDTLS_ECJPAKE_C) || \ |
| 36 | defined(MBEDTLS_PEM_PARSE_C) || \ |
| 37 | defined(MBEDTLS_ENTROPY_C) || \ |
| 38 | defined(MBEDTLS_PK_C) || \ |
| 39 | defined(MBEDTLS_PKCS12_C) || \ |
| 40 | defined(MBEDTLS_RSA_C) || \ |
| 41 | defined(MBEDTLS_SSL_TLS_C) || \ |
| 42 | defined(MBEDTLS_X509_USE_C) || \ |
| 43 | defined(MBEDTLS_X509_CREATE_C) |
| 44 | #define MBEDTLS_MD_LIGHT |
| 45 | #endif |
| 46 | |
Valerio Setti | 85d2a98 | 2023-10-06 16:04:49 +0200 | [diff] [blame] | 47 | #if defined(MBEDTLS_MD_LIGHT) |
| 48 | /* |
| 49 | * - MBEDTLS_MD_CAN_xxx is defined if the md module can perform xxx. |
| 50 | * - MBEDTLS_MD_xxx_VIA_PSA is defined if the md module may perform xxx via PSA |
| 51 | * (see below). |
| 52 | * - MBEDTLS_MD_SOME_PSA is defined if at least one algorithm may be performed |
| 53 | * via PSA (see below). |
| 54 | * - MBEDTLS_MD_SOME_LEGACY is defined if at least one algorithm may be performed |
| 55 | * via a direct legacy call (see below). |
| 56 | * |
| 57 | * The md module performs an algorithm via PSA if there is a PSA hash |
| 58 | * accelerator and the PSA driver subsytem is initialized at the time the |
| 59 | * operation is started, and makes a direct legacy call otherwise. |
| 60 | */ |
| 61 | |
| 62 | /* PSA accelerated implementations */ |
| 63 | #if defined(MBEDTLS_PSA_CRYPTO_C) |
| 64 | |
| 65 | #if defined(MBEDTLS_PSA_ACCEL_ALG_MD5) |
| 66 | #define MBEDTLS_MD_CAN_MD5 |
| 67 | #define MBEDTLS_MD_MD5_VIA_PSA |
| 68 | #define MBEDTLS_MD_SOME_PSA |
| 69 | #endif |
| 70 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1) |
| 71 | #define MBEDTLS_MD_CAN_SHA1 |
| 72 | #define MBEDTLS_MD_SHA1_VIA_PSA |
| 73 | #define MBEDTLS_MD_SOME_PSA |
| 74 | #endif |
| 75 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) |
| 76 | #define MBEDTLS_MD_CAN_SHA224 |
| 77 | #define MBEDTLS_MD_SHA224_VIA_PSA |
| 78 | #define MBEDTLS_MD_SOME_PSA |
| 79 | #endif |
| 80 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) |
| 81 | #define MBEDTLS_MD_CAN_SHA256 |
| 82 | #define MBEDTLS_MD_SHA256_VIA_PSA |
| 83 | #define MBEDTLS_MD_SOME_PSA |
| 84 | #endif |
| 85 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) |
| 86 | #define MBEDTLS_MD_CAN_SHA384 |
| 87 | #define MBEDTLS_MD_SHA384_VIA_PSA |
| 88 | #define MBEDTLS_MD_SOME_PSA |
| 89 | #endif |
| 90 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) |
| 91 | #define MBEDTLS_MD_CAN_SHA512 |
| 92 | #define MBEDTLS_MD_SHA512_VIA_PSA |
| 93 | #define MBEDTLS_MD_SOME_PSA |
| 94 | #endif |
| 95 | #if defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160) |
| 96 | #define MBEDTLS_MD_CAN_RIPEMD160 |
| 97 | #define MBEDTLS_MD_RIPEMD160_VIA_PSA |
| 98 | #define MBEDTLS_MD_SOME_PSA |
| 99 | #endif |
| 100 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_224) |
| 101 | #define MBEDTLS_MD_CAN_SHA3_224 |
| 102 | #define MBEDTLS_MD_SHA3_224_VIA_PSA |
| 103 | #define MBEDTLS_MD_SOME_PSA |
| 104 | #endif |
| 105 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_256) |
| 106 | #define MBEDTLS_MD_CAN_SHA3_256 |
| 107 | #define MBEDTLS_MD_SHA3_256_VIA_PSA |
| 108 | #define MBEDTLS_MD_SOME_PSA |
| 109 | #endif |
| 110 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_384) |
| 111 | #define MBEDTLS_MD_CAN_SHA3_384 |
| 112 | #define MBEDTLS_MD_SHA3_384_VIA_PSA |
| 113 | #define MBEDTLS_MD_SOME_PSA |
| 114 | #endif |
| 115 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA3_512) |
| 116 | #define MBEDTLS_MD_CAN_SHA3_512 |
| 117 | #define MBEDTLS_MD_SHA3_512_VIA_PSA |
| 118 | #define MBEDTLS_MD_SOME_PSA |
| 119 | #endif |
| 120 | #endif /* MBEDTLS_PSA_CRYPTO_C */ |
| 121 | |
| 122 | /* Built-in implementations */ |
| 123 | #if defined(MBEDTLS_MD5_C) |
| 124 | #define MBEDTLS_MD_CAN_MD5 |
| 125 | #define MBEDTLS_MD_SOME_LEGACY |
| 126 | #endif |
| 127 | #if defined(MBEDTLS_SHA1_C) |
| 128 | #define MBEDTLS_MD_CAN_SHA1 |
| 129 | #define MBEDTLS_MD_SOME_LEGACY |
| 130 | #endif |
| 131 | #if defined(MBEDTLS_SHA224_C) |
| 132 | #define MBEDTLS_MD_CAN_SHA224 |
| 133 | #define MBEDTLS_MD_SOME_LEGACY |
| 134 | #endif |
| 135 | #if defined(MBEDTLS_SHA256_C) |
| 136 | #define MBEDTLS_MD_CAN_SHA256 |
| 137 | #define MBEDTLS_MD_SOME_LEGACY |
| 138 | #endif |
| 139 | #if defined(MBEDTLS_SHA384_C) |
| 140 | #define MBEDTLS_MD_CAN_SHA384 |
| 141 | #define MBEDTLS_MD_SOME_LEGACY |
| 142 | #endif |
| 143 | #if defined(MBEDTLS_SHA512_C) |
| 144 | #define MBEDTLS_MD_CAN_SHA512 |
| 145 | #define MBEDTLS_MD_SOME_LEGACY |
| 146 | #endif |
| 147 | #if defined(MBEDTLS_SHA3_C) |
| 148 | #define MBEDTLS_MD_CAN_SHA3_224 |
| 149 | #define MBEDTLS_MD_CAN_SHA3_256 |
| 150 | #define MBEDTLS_MD_CAN_SHA3_384 |
| 151 | #define MBEDTLS_MD_CAN_SHA3_512 |
| 152 | #define MBEDTLS_MD_SOME_LEGACY |
| 153 | #endif |
| 154 | #if defined(MBEDTLS_RIPEMD160_C) |
| 155 | #define MBEDTLS_MD_CAN_RIPEMD160 |
| 156 | #define MBEDTLS_MD_SOME_LEGACY |
| 157 | #endif |
| 158 | |
| 159 | #endif /* MBEDTLS_MD_LIGHT */ |
| 160 | |
Valerio Setti | 8bba087 | 2023-12-12 11:49:02 +0100 | [diff] [blame] | 161 | /* BLOCK_CIPHER module can dispatch to PSA when: |
| 162 | * - PSA is enabled and drivers have been initialized |
| 163 | * - desired key type is supported on the PSA side |
| 164 | * If the above conditions are not met, but the legacy support is enabled, then |
Valerio Setti | 2684e3f | 2023-12-13 16:53:02 +0100 | [diff] [blame] | 165 | * BLOCK_CIPHER will dynamically fallback to it. |
Valerio Setti | 4a5d57d | 2023-12-14 09:34:15 +0100 | [diff] [blame^] | 166 | * |
| 167 | * In case BLOCK_CIPHER is defined (see below) the following symbols/helpers |
| 168 | * can be used to define its capabilities: |
| 169 | * - MBEDTLS_BLOCK_CIPHER_SOME_PSA: there is at least 1 key type between AES, |
| 170 | * ARIA and Camellia which is supported through a driver; |
| 171 | * - MBEDTLS_BLOCK_CIPHER_xxx_VIA_PSA: xxx key type is supported through a |
| 172 | * driver; |
| 173 | * - MBEDTLS_BLOCK_CIPHER_xxx_VIA_LEGACY: xxx key type is supported through |
| 174 | * a legacy module (i.e. MBEDTLS_xxx_C) |
Valerio Setti | 8bba087 | 2023-12-12 11:49:02 +0100 | [diff] [blame] | 175 | */ |
Valerio Setti | 8bba087 | 2023-12-12 11:49:02 +0100 | [diff] [blame] | 176 | #if defined(MBEDTLS_PSA_CRYPTO_C) |
| 177 | #if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_AES) |
| 178 | #define MBEDTLS_BLOCK_CIPHER_AES_VIA_PSA |
| 179 | #define MBEDTLS_BLOCK_CIPHER_SOME_PSA |
| 180 | #endif |
| 181 | #if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ARIA) |
| 182 | #define MBEDTLS_BLOCK_CIPHER_ARIA_VIA_PSA |
| 183 | #define MBEDTLS_BLOCK_CIPHER_SOME_PSA |
| 184 | #endif |
| 185 | #if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA) |
| 186 | #define MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_PSA |
| 187 | #define MBEDTLS_BLOCK_CIPHER_SOME_PSA |
| 188 | #endif |
| 189 | #endif /* MBEDTLS_PSA_CRYPTO_C */ |
| 190 | |
| 191 | #if defined(MBEDTLS_AES_C) |
| 192 | #define MBEDTLS_BLOCK_CIPHER_AES_VIA_LEGACY |
| 193 | #endif |
| 194 | #if defined(MBEDTLS_ARIA_C) |
| 195 | #define MBEDTLS_BLOCK_CIPHER_ARIA_VIA_LEGACY |
| 196 | #endif |
| 197 | #if defined(MBEDTLS_CAMELLIA_C) |
| 198 | #define MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_LEGACY |
| 199 | #endif |
| 200 | |
Valerio Setti | 4a5d57d | 2023-12-14 09:34:15 +0100 | [diff] [blame^] | 201 | /* Helpers to state that BLOCK_CIPHER module supports AES, ARIA and/or Camellia |
| 202 | * block ciphers via either PSA or legacy. */ |
Valerio Setti | 8bba087 | 2023-12-12 11:49:02 +0100 | [diff] [blame] | 203 | #if defined(MBEDTLS_BLOCK_CIPHER_AES_VIA_PSA) || \ |
| 204 | defined(MBEDTLS_BLOCK_CIPHER_AES_VIA_LEGACY) |
| 205 | #define MBEDTLS_BLOCK_CIPHER_CAN_AES |
| 206 | #endif |
| 207 | #if defined(MBEDTLS_BLOCK_CIPHER_ARIA_VIA_PSA) || \ |
| 208 | defined(MBEDTLS_BLOCK_CIPHER_ARIA_VIA_LEGACY) |
| 209 | #define MBEDTLS_BLOCK_CIPHER_CAN_ARIA |
| 210 | #endif |
| 211 | #if defined(MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_PSA) || \ |
| 212 | defined(MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_LEGACY) |
| 213 | #define MBEDTLS_BLOCK_CIPHER_CAN_CAMELLIA |
| 214 | #endif |
| 215 | |
Valerio Setti | 4a5d57d | 2023-12-14 09:34:15 +0100 | [diff] [blame^] | 216 | /* GCM_C and CCM_C can either depend on (in order of preference) BLOCK_CIPHER_C |
| 217 | * or CIPHER_C. The former is auto-enabled when: |
| 218 | * - CIPHER_C is not defined, which is also the legacy solution; |
| 219 | * - BLOCK_CIPHER_SOME_PSA because in this case BLOCK_CIPHER can take advantage |
| 220 | * of the driver's acceleration. |
| 221 | */ |
| 222 | #if (defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C)) && \ |
| 223 | (!defined(MBEDTLS_CIPHER_C) || defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA)) |
| 224 | #define MBEDTLS_BLOCK_CIPHER_C |
| 225 | #endif |
| 226 | |
Gilles Peskine | 9d6a63b | 2023-09-04 17:49:07 +0200 | [diff] [blame] | 227 | /* MBEDTLS_ECP_LIGHT is auto-enabled by the following symbols: |
| 228 | * - MBEDTLS_ECP_C because now it consists of MBEDTLS_ECP_LIGHT plus functions |
| 229 | * for curve arithmetic. As a consequence if MBEDTLS_ECP_C is required for |
| 230 | * some reason, then MBEDTLS_ECP_LIGHT should be enabled as well. |
| 231 | * - MBEDTLS_PK_PARSE_EC_EXTENDED and MBEDTLS_PK_PARSE_EC_COMPRESSED because |
| 232 | * these features are not supported in PSA so the only way to have them is |
| 233 | * to enable the built-in solution. |
| 234 | * Both of them are temporary dependencies: |
| 235 | * - PK_PARSE_EC_EXTENDED will be removed after #7779 and #7789 |
| 236 | * - support for compressed points should also be added to PSA, but in this |
| 237 | * case there is no associated issue to track it yet. |
| 238 | * - PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE because Weierstrass key derivation |
| 239 | * still depends on ECP_LIGHT. |
| 240 | * - PK_C + USE_PSA + PSA_WANT_ALG_ECDSA is a temporary dependency which will |
| 241 | * be fixed by #7453. |
| 242 | */ |
| 243 | #if defined(MBEDTLS_ECP_C) || \ |
| 244 | defined(MBEDTLS_PK_PARSE_EC_EXTENDED) || \ |
| 245 | defined(MBEDTLS_PK_PARSE_EC_COMPRESSED) || \ |
| 246 | defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR_DERIVE) |
| 247 | #define MBEDTLS_ECP_LIGHT |
| 248 | #endif |
| 249 | |
Thomas Daubney | 540324c | 2023-10-06 17:07:24 +0100 | [diff] [blame] | 250 | /* MBEDTLS_PK_PARSE_EC_COMPRESSED is introduced in Mbed TLS version 3.5, while |
Gilles Peskine | 9d6a63b | 2023-09-04 17:49:07 +0200 | [diff] [blame] | 251 | * in previous version compressed points were automatically supported as long |
| 252 | * as PK_PARSE_C and ECP_C were enabled. As a consequence, for backward |
| 253 | * compatibility, we auto-enable PK_PARSE_EC_COMPRESSED when these conditions |
| 254 | * are met. */ |
| 255 | #if defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_ECP_C) |
| 256 | #define MBEDTLS_PK_PARSE_EC_COMPRESSED |
| 257 | #endif |
| 258 | |
| 259 | /* Helper symbol to state that there is support for ECDH, either through |
| 260 | * library implementation (ECDH_C) or through PSA. */ |
| 261 | #if (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_ECDH)) || \ |
| 262 | (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_ECDH_C)) |
| 263 | #define MBEDTLS_CAN_ECDH |
| 264 | #endif |
| 265 | |
| 266 | /* PK module can achieve ECDSA functionalities by means of either software |
| 267 | * implementations (ECDSA_C) or through a PSA driver. The following defines |
| 268 | * are meant to list these capabilities in a general way which abstracts how |
| 269 | * they are implemented under the hood. */ |
| 270 | #if !defined(MBEDTLS_USE_PSA_CRYPTO) |
| 271 | #if defined(MBEDTLS_ECDSA_C) |
| 272 | #define MBEDTLS_PK_CAN_ECDSA_SIGN |
| 273 | #define MBEDTLS_PK_CAN_ECDSA_VERIFY |
| 274 | #endif /* MBEDTLS_ECDSA_C */ |
| 275 | #else /* MBEDTLS_USE_PSA_CRYPTO */ |
| 276 | #if defined(PSA_WANT_ALG_ECDSA) |
| 277 | #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC) |
| 278 | #define MBEDTLS_PK_CAN_ECDSA_SIGN |
| 279 | #endif /* PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC */ |
| 280 | #if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) |
| 281 | #define MBEDTLS_PK_CAN_ECDSA_VERIFY |
| 282 | #endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */ |
| 283 | #endif /* PSA_WANT_ALG_ECDSA */ |
| 284 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
| 285 | |
| 286 | #if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY) || defined(MBEDTLS_PK_CAN_ECDSA_SIGN) |
| 287 | #define MBEDTLS_PK_CAN_ECDSA_SOME |
| 288 | #endif |
| 289 | |
| 290 | /* If MBEDTLS_PSA_CRYPTO_C is defined, make sure MBEDTLS_PSA_CRYPTO_CLIENT |
| 291 | * is defined as well to include all PSA code. |
| 292 | */ |
| 293 | #if defined(MBEDTLS_PSA_CRYPTO_C) |
| 294 | #define MBEDTLS_PSA_CRYPTO_CLIENT |
| 295 | #endif /* MBEDTLS_PSA_CRYPTO_C */ |
| 296 | |
| 297 | /* The PK wrappers need pk_write functions to format RSA key objects |
| 298 | * when they are dispatching to the PSA API. This happens under USE_PSA_CRYPTO, |
| 299 | * and also even without USE_PSA_CRYPTO for mbedtls_pk_sign_ext(). */ |
| 300 | #if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_RSA_C) |
| 301 | #define MBEDTLS_PK_C |
| 302 | #define MBEDTLS_PK_WRITE_C |
| 303 | #define MBEDTLS_PK_PARSE_C |
| 304 | #endif |
| 305 | |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 306 | /* Helpers to state that each key is supported either on the builtin or PSA side. */ |
| 307 | #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_521) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 308 | #define MBEDTLS_ECP_HAVE_SECP521R1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 309 | #endif |
| 310 | #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) || defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 311 | #define MBEDTLS_ECP_HAVE_BP512R1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 312 | #endif |
| 313 | #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) || defined(PSA_WANT_ECC_MONTGOMERY_448) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 314 | #define MBEDTLS_ECP_HAVE_CURVE448 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 315 | #endif |
| 316 | #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 317 | #define MBEDTLS_ECP_HAVE_BP384R1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 318 | #endif |
| 319 | #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_384) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 320 | #define MBEDTLS_ECP_HAVE_SECP384R1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 321 | #endif |
| 322 | #if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 323 | #define MBEDTLS_ECP_HAVE_BP256R1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 324 | #endif |
| 325 | #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) || defined(PSA_WANT_ECC_SECP_K1_256) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 326 | #define MBEDTLS_ECP_HAVE_SECP256K1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 327 | #endif |
| 328 | #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_256) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 329 | #define MBEDTLS_ECP_HAVE_SECP256R1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 330 | #endif |
| 331 | #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || defined(PSA_WANT_ECC_MONTGOMERY_255) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 332 | #define MBEDTLS_ECP_HAVE_CURVE25519 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 333 | #endif |
| 334 | #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || defined(PSA_WANT_ECC_SECP_K1_224) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 335 | #define MBEDTLS_ECP_HAVE_SECP224K1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 336 | #endif |
| 337 | #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_224) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 338 | #define MBEDTLS_ECP_HAVE_SECP224R1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 339 | #endif |
| 340 | #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || defined(PSA_WANT_ECC_SECP_K1_192) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 341 | #define MBEDTLS_ECP_HAVE_SECP192K1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 342 | #endif |
| 343 | #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_192) |
Valerio Setti | db6b4db | 2023-09-01 09:20:51 +0200 | [diff] [blame] | 344 | #define MBEDTLS_ECP_HAVE_SECP192R1 |
Valerio Setti | 67d82e7 | 2023-08-16 17:11:53 +0200 | [diff] [blame] | 345 | #endif |
| 346 | |
Gilles Peskine | 9d6a63b | 2023-09-04 17:49:07 +0200 | [diff] [blame] | 347 | /* Helper symbol to state that the PK module has support for EC keys. This |
| 348 | * can either be provided through the legacy ECP solution or through the |
| 349 | * PSA friendly MBEDTLS_PK_USE_PSA_EC_DATA (see pk.h for its description). */ |
| 350 | #if defined(MBEDTLS_ECP_C) || \ |
| 351 | (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)) |
| 352 | #define MBEDTLS_PK_HAVE_ECC_KEYS |
| 353 | #endif /* MBEDTLS_PK_USE_PSA_EC_DATA || MBEDTLS_ECP_C */ |
| 354 | |
Gilles Peskine | ca1e605 | 2023-09-25 16:16:26 +0200 | [diff] [blame] | 355 | /* Historically pkparse did not check the CBC padding when decrypting |
| 356 | * a key. This was a bug, which is now fixed. As a consequence, pkparse |
| 357 | * now needs PKCS7 padding support, but existing configurations might not |
| 358 | * enable it, so we enable it here. */ |
| 359 | #if defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_PKCS5_C) && defined(MBEDTLS_CIPHER_MODE_CBC) |
| 360 | #define MBEDTLS_CIPHER_PADDING_PKCS7 |
| 361 | #endif |
| 362 | |
Dave Rodgman | 94a634d | 2023-10-10 12:59:29 +0100 | [diff] [blame] | 363 | /* Backwards compatibility for some macros which were renamed to reflect that |
| 364 | * they are related to Armv8, not aarch64. */ |
Dave Rodgman | c5861d5 | 2023-10-10 14:01:54 +0100 | [diff] [blame] | 365 | #if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) && \ |
Dave Rodgman | 5b89c55 | 2023-10-10 14:59:02 +0100 | [diff] [blame] | 366 | !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) |
| 367 | #define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT |
Dave Rodgman | 94a634d | 2023-10-10 12:59:29 +0100 | [diff] [blame] | 368 | #endif |
Dave Rodgman | 5b89c55 | 2023-10-10 14:59:02 +0100 | [diff] [blame] | 369 | #if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY) && !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY) |
| 370 | #define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY |
Dave Rodgman | 94a634d | 2023-10-10 12:59:29 +0100 | [diff] [blame] | 371 | #endif |
Dave Rodgman | 94a634d | 2023-10-10 12:59:29 +0100 | [diff] [blame] | 372 | |
Yanray Wang | 4ed8691 | 2023-11-16 15:20:56 +0800 | [diff] [blame] | 373 | /* Some internal helpers to determine which keys are availble. */ |
| 374 | #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_AES_C)) || \ |
| 375 | (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_AES)) |
| 376 | #define MBEDTLS_SSL_HAVE_AES |
| 377 | #endif |
| 378 | #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_ARIA_C)) || \ |
| 379 | (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ARIA)) |
| 380 | #define MBEDTLS_SSL_HAVE_ARIA |
| 381 | #endif |
| 382 | #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CAMELLIA_C)) || \ |
| 383 | (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_CAMELLIA)) |
| 384 | #define MBEDTLS_SSL_HAVE_CAMELLIA |
| 385 | #endif |
| 386 | |
| 387 | /* Some internal helpers to determine which operation modes are availble. */ |
| 388 | #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CIPHER_MODE_CBC)) || \ |
| 389 | (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CBC_NO_PADDING)) |
| 390 | #define MBEDTLS_SSL_HAVE_CBC |
| 391 | #endif |
| 392 | |
Valerio Setti | e570704 | 2023-10-11 11:54:42 +0200 | [diff] [blame] | 393 | #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_GCM_C)) || \ |
| 394 | (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_GCM)) |
| 395 | #define MBEDTLS_SSL_HAVE_GCM |
| 396 | #endif |
| 397 | |
| 398 | #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CCM_C)) || \ |
| 399 | (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CCM)) |
| 400 | #define MBEDTLS_SSL_HAVE_CCM |
| 401 | #endif |
| 402 | |
| 403 | #if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CHACHAPOLY_C)) || \ |
| 404 | (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CHACHA20_POLY1305)) |
| 405 | #define MBEDTLS_SSL_HAVE_CHACHAPOLY |
| 406 | #endif |
| 407 | |
| 408 | #if defined(MBEDTLS_SSL_HAVE_GCM) || defined(MBEDTLS_SSL_HAVE_CCM) || \ |
| 409 | defined(MBEDTLS_SSL_HAVE_CHACHAPOLY) |
| 410 | #define MBEDTLS_SSL_HAVE_AEAD |
| 411 | #endif |
| 412 | |
Gilles Peskine | 9d6a63b | 2023-09-04 17:49:07 +0200 | [diff] [blame] | 413 | #endif /* MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H */ |