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