| 1 | /* |
| 2 | * Copyright (c) 2018-2023, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | /** |
| 8 | * \file psa/crypto_config.h |
| 9 | * \brief PSA crypto configuration options (set of defines) |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #ifndef PROFILE_M_PSA_CRYPTO_CONFIG_H |
| 14 | #define PROFILE_M_PSA_CRYPTO_CONFIG_H |
| 15 | |
| 16 | /** |
| 17 | * \name SECTION: SECTION Cryptographic mechanism selection (PSA API) |
| 18 | * |
| 19 | * This section sets PSA API settings. |
| 20 | * \{ |
| 21 | */ |
| 22 | /* |
| 23 | * CBC-MAC is not yet supported via the PSA API in Mbed TLS. |
| 24 | */ |
| 25 | //#define PSA_WANT_ALG_CBC_MAC 1 |
| 26 | //#define PSA_WANT_ALG_CBC_NO_PADDING 1 |
| 27 | //#define PSA_WANT_ALG_CBC_PKCS7 1 |
| 28 | #define PSA_WANT_ALG_CCM 1 |
| 29 | //#define PSA_WANT_ALG_CCM_STAR_NO_TAG 1 |
| 30 | //#define PSA_WANT_ALG_CMAC 1 |
| 31 | //#define PSA_WANT_ALG_CFB 1 |
| 32 | //#define PSA_WANT_ALG_CHACHA20_POLY1305 1 |
| 33 | //#define PSA_WANT_ALG_CTR 1 |
| 34 | //#define PSA_WANT_ALG_DETERMINISTIC_ECDSA 1 |
| 35 | //#define PSA_WANT_ALG_ECB_NO_PADDING 1 |
| 36 | #define PSA_WANT_ALG_ECDH 1 |
| 37 | //#define PSA_WANT_ALG_FFDH 1 |
| 38 | #define PSA_WANT_ALG_ECDSA 1 |
| 39 | //#define PSA_WANT_ALG_JPAKE 1 |
| 40 | //#define PSA_WANT_ALG_GCM 1 |
| 41 | #define PSA_WANT_ALG_HKDF 1 |
| 42 | //#define PSA_WANT_ALG_HKDF_EXTRACT 1 |
| 43 | //#define PSA_WANT_ALG_HKDF_EXPAND 1 |
| 44 | #define PSA_WANT_ALG_HMAC 1 |
| 45 | //#define PSA_WANT_ALG_MD5 1 |
| 46 | //#define PSA_WANT_ALG_OFB 1 |
| 47 | //#define PSA_WANT_ALG_PBKDF2_HMAC 1 |
| 48 | //#define PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 1 |
| 49 | //#define PSA_WANT_ALG_RIPEMD160 1 |
| 50 | //#define PSA_WANT_ALG_RSA_OAEP 1 |
| 51 | //#define PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1 |
| 52 | //#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1 |
| 53 | //#define PSA_WANT_ALG_RSA_PSS 1 |
| 54 | //#define PSA_WANT_ALG_SHA_1 1 |
| 55 | #define PSA_WANT_ALG_SHA_224 1 |
| 56 | #define PSA_WANT_ALG_SHA_256 1 |
| 57 | //#define PSA_WANT_ALG_SHA_384 1 |
| 58 | //#define PSA_WANT_ALG_SHA_512 1 |
| 59 | //#define PSA_WANT_ALG_SHA3_224 1 |
| 60 | //#define PSA_WANT_ALG_SHA3_256 1 |
| 61 | //#define PSA_WANT_ALG_SHA3_384 1 |
| 62 | //#define PSA_WANT_ALG_SHA3_512 1 |
| 63 | //#define PSA_WANT_ALG_STREAM_CIPHER 1 |
| 64 | #define PSA_WANT_ALG_TLS12_PRF 1 |
| 65 | #define PSA_WANT_ALG_TLS12_PSK_TO_MS 1 |
| 66 | //#define PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS 1 |
| 67 | |
| 68 | //#define PSA_WANT_ECC_BRAINPOOL_P_R1_256 1 |
| 69 | //#define PSA_WANT_ECC_BRAINPOOL_P_R1_384 1 |
| 70 | //#define PSA_WANT_ECC_BRAINPOOL_P_R1_512 1 |
| 71 | //#define PSA_WANT_ECC_MONTGOMERY_255 1 |
| 72 | //#define PSA_WANT_ECC_MONTGOMERY_448 1 |
| 73 | //#define PSA_WANT_ECC_SECP_K1_256 1 |
| 74 | /* For secp256r1, consider enabling #MBEDTLS_PSA_P256M_DRIVER_ENABLED |
| 75 | * (see the description in psa/cypto_config.h for details). */ |
| 76 | #define PSA_WANT_ECC_SECP_R1_256 1 |
| 77 | //#define PSA_WANT_ECC_SECP_R1_384 1 |
| 78 | //#define PSA_WANT_ECC_SECP_R1_521 1 |
| 79 | |
| 80 | //#define PSA_WANT_DH_RFC7919_2048 1 |
| 81 | //#define PSA_WANT_DH_RFC7919_3072 1 |
| 82 | //#define PSA_WANT_DH_RFC7919_4096 1 |
| 83 | //#define PSA_WANT_DH_RFC7919_6144 1 |
| 84 | //#define PSA_WANT_DH_RFC7919_8192 1 |
| 85 | |
| 86 | #define PSA_WANT_KEY_TYPE_DERIVE 1 |
| 87 | //#define PSA_WANT_KEY_TYPE_PASSWORD 1 |
| 88 | //#define PSA_WANT_KEY_TYPE_PASSWORD_HASH 1 |
| 89 | #define PSA_WANT_KEY_TYPE_HMAC 1 |
| 90 | #define PSA_WANT_KEY_TYPE_AES 1 |
| 91 | //#define PSA_WANT_KEY_TYPE_ARIA 1 |
| 92 | //#define PSA_WANT_KEY_TYPE_CAMELLIA 1 |
| 93 | //#define PSA_WANT_KEY_TYPE_CHACHA20 1 |
| 94 | #define PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1 |
| 95 | //#define PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY 1 |
| 96 | #define PSA_WANT_KEY_TYPE_RAW_DATA 1 |
| 97 | //#define PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1 |
| 98 | |
| 99 | /* |
| 100 | * The following symbols extend and deprecate the legacy |
| 101 | * PSA_WANT_KEY_TYPE_xxx_KEY_PAIR ones. They include the usage of that key in |
| 102 | * the name's suffix. "_USE" is the most generic and it can be used to describe |
| 103 | * a generic suport, whereas other ones add more features on top of that and |
| 104 | * they are more specific. |
| 105 | */ |
| 106 | #define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC 1 |
| 107 | #define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT 1 |
| 108 | #define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT 1 |
| 109 | #define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE 1 |
| 110 | //#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE 1 |
| 111 | |
| 112 | //#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1 |
| 113 | //#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1 |
| 114 | //#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1 |
| 115 | //#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1 |
| 116 | //#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_DERIVE 1 /* Not supported */ |
| 117 | |
| 118 | //#define PSA_WANT_KEY_TYPE_DH_KEY_PAIR_BASIC 1 |
| 119 | //#define PSA_WANT_KEY_TYPE_DH_KEY_PAIR_IMPORT 1 |
| 120 | //#define PSA_WANT_KEY_TYPE_DH_KEY_PAIR_EXPORT 1 |
| 121 | //#define PSA_WANT_KEY_TYPE_DH_KEY_PAIR_GENERATE 1 |
| 122 | //#define PSA_WANT_KEY_TYPE_DH_KEY_PAIR_DERIVE 1 /* Not supported */ |
| 123 | /** \} name SECTION Cryptographic mechanism selection (PSA API) */ |
| 124 | |
| 125 | /** |
| 126 | * \name SECTION: Platform abstraction layer |
| 127 | * |
| 128 | * This section sets platform specific settings. |
| 129 | * \{ |
| 130 | */ |
| 131 | |
| 132 | /** |
| 133 | * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 134 | * |
| 135 | * Enable the buffer allocator implementation that makes use of a (stack) |
| 136 | * based buffer to 'allocate' dynamic memory. (replaces calloc() and free() |
| 137 | * calls) |
| 138 | * |
| 139 | * Module: platform/memory_buffer_alloc.c |
| 140 | * |
| 141 | * Requires: MBEDTLS_PLATFORM_C |
| 142 | * MBEDTLS_PLATFORM_MEMORY (to use it within Mbed TLS) |
| 143 | * |
| 144 | * Enable this module to enable the buffer memory allocator. |
| 145 | */ |
| 146 | #define MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 147 | |
| 148 | /** |
| 149 | * \def MBEDTLS_PLATFORM_C |
| 150 | * |
| 151 | * Enable the platform abstraction layer that allows you to re-assign |
| 152 | * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit(). |
| 153 | * |
| 154 | * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT |
| 155 | * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned |
| 156 | * above to be specified at runtime or compile time respectively. |
| 157 | * |
| 158 | * \note This abstraction layer must be enabled on Windows (including MSYS2) |
| 159 | * as other modules rely on it for a fixed snprintf implementation. |
| 160 | * |
| 161 | * Module: platform/platform.c |
| 162 | * Caller: Most other .c files |
| 163 | * |
| 164 | * This module enables abstraction of common (libc) functions. |
| 165 | */ |
| 166 | #define MBEDTLS_PLATFORM_C |
| 167 | |
| 168 | /** |
| 169 | * \def MBEDTLS_PLATFORM_MEMORY |
| 170 | * |
| 171 | * Enable the memory allocation layer. |
| 172 | * |
| 173 | * By default Mbed TLS uses the system-provided calloc() and free(). |
| 174 | * This allows different allocators (self-implemented or provided) to be |
| 175 | * provided to the platform abstraction layer. |
| 176 | * |
| 177 | * Enabling #MBEDTLS_PLATFORM_MEMORY without the |
| 178 | * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide |
| 179 | * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and |
| 180 | * free() function pointer at runtime. |
| 181 | * |
| 182 | * Enabling #MBEDTLS_PLATFORM_MEMORY and specifying |
| 183 | * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the |
| 184 | * alternate function at compile time. |
| 185 | * |
| 186 | * An overview of how the value of mbedtls_calloc is determined: |
| 187 | * |
| 188 | * - if !MBEDTLS_PLATFORM_MEMORY |
| 189 | * - mbedtls_calloc = calloc |
| 190 | * - if MBEDTLS_PLATFORM_MEMORY |
| 191 | * - if (MBEDTLS_PLATFORM_CALLOC_MACRO && MBEDTLS_PLATFORM_FREE_MACRO): |
| 192 | * - mbedtls_calloc = MBEDTLS_PLATFORM_CALLOC_MACRO |
| 193 | * - if !(MBEDTLS_PLATFORM_CALLOC_MACRO && MBEDTLS_PLATFORM_FREE_MACRO): |
| 194 | * - Dynamic setup via mbedtls_platform_set_calloc_free is now possible with a default value MBEDTLS_PLATFORM_STD_CALLOC. |
| 195 | * - How is MBEDTLS_PLATFORM_STD_CALLOC handled? |
| 196 | * - if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS: |
| 197 | * - MBEDTLS_PLATFORM_STD_CALLOC is not set to anything; |
| 198 | * - MBEDTLS_PLATFORM_STD_MEM_HDR can be included if present; |
| 199 | * - if !MBEDTLS_PLATFORM_NO_STD_FUNCTIONS: |
| 200 | * - if MBEDTLS_PLATFORM_STD_CALLOC is present: |
| 201 | * - User-defined MBEDTLS_PLATFORM_STD_CALLOC is respected; |
| 202 | * - if !MBEDTLS_PLATFORM_STD_CALLOC: |
| 203 | * - MBEDTLS_PLATFORM_STD_CALLOC = calloc |
| 204 | * |
| 205 | * - At this point the presence of MBEDTLS_PLATFORM_STD_CALLOC is checked. |
| 206 | * - if !MBEDTLS_PLATFORM_STD_CALLOC |
| 207 | * - MBEDTLS_PLATFORM_STD_CALLOC = uninitialized_calloc |
| 208 | * |
| 209 | * - mbedtls_calloc = MBEDTLS_PLATFORM_STD_CALLOC. |
| 210 | * |
| 211 | * Defining MBEDTLS_PLATFORM_CALLOC_MACRO and #MBEDTLS_PLATFORM_STD_CALLOC at the same time is not possible. |
| 212 | * MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_FREE_MACRO must both be defined or undefined at the same time. |
| 213 | * #MBEDTLS_PLATFORM_STD_CALLOC and #MBEDTLS_PLATFORM_STD_FREE do not have to be defined at the same time, as, if they are used, |
| 214 | * dynamic setup of these functions is possible. See the tree above to see how are they handled in all cases. |
| 215 | * An uninitialized #MBEDTLS_PLATFORM_STD_CALLOC always fails, returning a null pointer. |
| 216 | * An uninitialized #MBEDTLS_PLATFORM_STD_FREE does not do anything. |
| 217 | * |
| 218 | * Requires: MBEDTLS_PLATFORM_C |
| 219 | * |
| 220 | * Enable this layer to allow use of alternative memory allocators. |
| 221 | */ |
| 222 | #define MBEDTLS_PLATFORM_MEMORY |
| 223 | |
| 224 | /** |
| 225 | * \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS |
| 226 | * |
| 227 | * Do not assign standard functions in the platform layer (e.g. calloc() to |
| 228 | * MBEDTLS_PLATFORM_STD_CALLOC and printf() to MBEDTLS_PLATFORM_STD_PRINTF) |
| 229 | * |
| 230 | * This makes sure there are no linking errors on platforms that do not support |
| 231 | * these functions. You will HAVE to provide alternatives, either at runtime |
| 232 | * via the platform_set_xxx() functions or at compile time by setting |
| 233 | * the MBEDTLS_PLATFORM_STD_XXX defines, or enabling a |
| 234 | * MBEDTLS_PLATFORM_XXX_MACRO. |
| 235 | * |
| 236 | * Requires: MBEDTLS_PLATFORM_C |
| 237 | * |
| 238 | * Uncomment to prevent default assignment of standard functions in the |
| 239 | * platform layer. |
| 240 | */ |
| 241 | #define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS |
| 242 | |
| 243 | #define MBEDTLS_PLATFORM_PRINTF_ALT |
| 244 | |
| 245 | /* To use the following function macros, MBEDTLS_PLATFORM_C must be enabled. */ |
| 246 | /* MBEDTLS_PLATFORM_XXX_MACRO and MBEDTLS_PLATFORM_XXX_ALT cannot both be defined */ |
| 247 | |
| 248 | #include <stdio.h> |
| 249 | |
| 250 | #define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf |
| 251 | #define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE |
| 252 | #define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS |
| 253 | |
| 254 | #define MBEDTLS_PLATFORM_STD_MEM_HDR <stdlib.h> |
| 255 | |
| 256 | /** \} name SECTION: Platform abstraction layer */ |
| 257 | |
| 258 | /** |
| 259 | * \name SECTION: PSA core |
| 260 | * |
| 261 | * This section sets PSA specific settings. |
| 262 | * \{ |
| 263 | */ |
| 264 | /** |
| 265 | * \def MBEDTLS_CTR_DRBG_C |
| 266 | * |
| 267 | * Enable the CTR_DRBG AES-based random generator. |
| 268 | * The CTR_DRBG generator uses AES-256 by default. |
| 269 | * To use AES-128 instead, set #MBEDTLS_PSA_CRYPTO_RNG_STRENGTH to 128. |
| 270 | * |
| 271 | * AES support can either be achieved through built-in AES or PSA. Built-in is |
| 272 | * the default option when present otherwise PSA is used. |
| 273 | * |
| 274 | * Module: drivers/builtin/src/ctr_drbg.c |
| 275 | * |
| 276 | * Requires: MBEDTLS_PSA_CRYPTO_C, PSA_WANT_KEY_TYPE_AES and |
| 277 | * PSA_WANT_ALG_ECB_NO_PADDING |
| 278 | * |
| 279 | * This module provides the CTR_DRBG AES random number generator. |
| 280 | */ |
| 281 | #define MBEDTLS_CTR_DRBG_C |
| 282 | |
| 283 | /** |
| 284 | * \def MBEDTLS_ENTROPY_NV_SEED |
| 285 | * |
| 286 | * Enable the non-volatile (NV) seed file-based entropy source. |
| 287 | * (Also enables the NV seed read/write functions in the platform layer) |
| 288 | * |
| 289 | * This is crucial (if not required) on systems that do not have a |
| 290 | * cryptographic entropy source (in hardware or kernel) available. |
| 291 | * |
| 292 | * Requires: MBEDTLS_PSA_CRYPTO_C, |
| 293 | * !MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG |
| 294 | * MBEDTLS_PLATFORM_C |
| 295 | * |
| 296 | * \note The read/write functions that are used by the entropy source are |
| 297 | * determined in the platform layer, and can be modified at runtime and/or |
| 298 | * compile-time depending on the flags (MBEDTLS_PLATFORM_NV_SEED_*) used. |
| 299 | * |
| 300 | * \note If you use the default implementation functions that read a seedfile |
| 301 | * with regular fopen(), please make sure you make a seedfile with the |
| 302 | * proper name (defined in MBEDTLS_PLATFORM_STD_NV_SEED_FILE) and at |
| 303 | * least MBEDTLS_ENTROPY_BLOCK_SIZE bytes in size that can be read from |
| 304 | * and written to or you will get an entropy source error! The default |
| 305 | * implementation will only use the first MBEDTLS_ENTROPY_BLOCK_SIZE |
| 306 | * bytes from the file. |
| 307 | * |
| 308 | * \note The entropy collector will write to the seed file before entropy is |
| 309 | * given to an external source, to update it. |
| 310 | */ |
| 311 | #define MBEDTLS_ENTROPY_NV_SEED |
| 312 | |
| 313 | /** |
| 314 | * \def MBEDTLS_PSA_CRYPTO_C |
| 315 | * |
| 316 | * Enable the Platform Security Architecture cryptography API. |
| 317 | * |
| 318 | * Module: core/psa_crypto.c |
| 319 | * |
| 320 | * Requires: one of the following: |
| 321 | * - MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG |
| 322 | * - MBEDTLS_CTR_DRBG_C |
| 323 | * - MBEDTLS_HMAC_DRBG_C |
| 324 | * |
| 325 | * If MBEDTLS_CTR_DRBG_C or MBEDTLS_HMAC_DRBG_C is used as the PSA |
| 326 | * random generator, then either PSA_WANT_ALG_SHA_256 or |
| 327 | * PSA_WANT_ALG_SHA_512 must be enabled for the entropy module. |
| 328 | * |
| 329 | * \note The PSA crypto subsystem prioritizes DRBG mechanisms as follows: |
| 330 | * - #MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG, if enabled |
| 331 | * - CTR_DRBG (AES), seeded by the entropy module, if |
| 332 | * #MBEDTLS_CTR_DRBG_C is enabled |
| 333 | * - HMAC_DRBG, seeded by the entropy module, if |
| 334 | * #MBEDTLS_HMAC_DRBG_C is enabled |
| 335 | * |
| 336 | * A future version may reevaluate the prioritization of DRBG mechanisms. |
| 337 | */ |
| 338 | #define MBEDTLS_PSA_CRYPTO_C |
| 339 | |
| 340 | /** |
| 341 | * \def MBEDTLS_PSA_CRYPTO_SPM |
| 342 | * |
| 343 | * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is built for SPM (Secure |
| 344 | * Partition Manager) integration which separates the code into two parts: a |
| 345 | * NSPE (Non-Secure Process Environment) and an SPE (Secure Process |
| 346 | * Environment). |
| 347 | * |
| 348 | * If you enable this option, your build environment must include a header |
| 349 | * file `"crypto_spe.h"` (either in the `psa` subdirectory of the Mbed TLS |
| 350 | * header files, or in another directory on the compiler's include search |
| 351 | * path). Alternatively, your platform may customize the header |
| 352 | * `psa/crypto_platform.h`, in which case it can skip or replace the |
| 353 | * inclusion of `"crypto_spe.h"`. |
| 354 | * |
| 355 | * Module: core/psa_crypto.c |
| 356 | * Requires: MBEDTLS_PSA_CRYPTO_C |
| 357 | * |
| 358 | */ |
| 359 | #define MBEDTLS_PSA_CRYPTO_SPM |
| 360 | |
| 361 | /** |
| 362 | * \def MBEDTLS_PSA_CRYPTO_STORAGE_C |
| 363 | * |
| 364 | * Enable the Platform Security Architecture persistent key storage. |
| 365 | * |
| 366 | * Module: core/psa_crypto_storage.c |
| 367 | * |
| 368 | * Requires: MBEDTLS_PSA_CRYPTO_C, |
| 369 | * either MBEDTLS_PSA_ITS_FILE_C or a native implementation of |
| 370 | * the PSA ITS interface |
| 371 | */ |
| 372 | #define MBEDTLS_PSA_CRYPTO_STORAGE_C |
| 373 | |
| 374 | /** |
| 375 | * \def MBEDTLS_PSA_DRIVER_GET_ENTROPY |
| 376 | * |
| 377 | * Requires: MBEDTLS_PSA_CRYPTO_C, !MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG |
| 378 | * |
| 379 | * Enable the custom entropy callback mbedtls_platform_get_entropy() |
| 380 | * (declared in mbedtls/platform.h). You need to provide this callback |
| 381 | * if you need an entropy source and the built-in entropy callback |
| 382 | * provided by #MBEDTLS_PSA_BUILTIN_GET_ENTROPY does not work on your platform. |
| 383 | * |
| 384 | * Enabling both #MBEDTLS_PSA_BUILTIN_GET_ENTROPY and |
| 385 | * #MBEDTLS_PSA_DRIVER_GET_ENTROPY is currently not supported. |
| 386 | * |
| 387 | * You do not need any entropy source in the following circumstances: |
| 388 | * |
| 389 | * - If your platform has a fast cryptographic-quality random generator, and |
| 390 | * you enable #MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG and provide a random generator |
| 391 | * callback instead. |
| 392 | * - If your platform has no source of entropy at all, and you enable |
| 393 | * #MBEDTLS_ENTROPY_NV_SEED and provide a seed in nonvolatile memory |
| 394 | * during the provisioning of the device. |
| 395 | * - If you build the library with no random generator. |
| 396 | * Builds with no random generator are not officially supported yet, except |
| 397 | * client-only builds (#MBEDTLS_PSA_CRYPTO_CLIENT enabled and |
| 398 | * #MBEDTLS_PSA_CRYPTO_C disabled). |
| 399 | */ |
| 400 | //#define MBEDTLS_PSA_DRIVER_GET_ENTROPY |
| 401 | |
| 402 | /** |
| 403 | * \def MBEDTLS_PSA_CRYPTO_RNG_STRENGTH |
| 404 | * |
| 405 | * Minimum security strength (in bits) of the PSA RNG. |
| 406 | * |
| 407 | * \note Valid values: 128 or default of 256. |
| 408 | */ |
| 409 | #define MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 |
| 410 | |
| 411 | /** \} name SECTION: PSA core */ |
| 412 | |
| 413 | /** |
| 414 | * \name SECTION: Builtin drivers |
| 415 | * |
| 416 | * This section sets driver specific settings. |
| 417 | * \{ |
| 418 | */ |
| 419 | |
| 420 | /** |
| 421 | * \def MBEDTLS_AES_ROM_TABLES |
| 422 | * |
| 423 | * Use precomputed AES tables stored in ROM. |
| 424 | * |
| 425 | * Uncomment this macro to use precomputed AES tables stored in ROM. |
| 426 | * Comment this macro to generate AES tables in RAM at runtime. |
| 427 | * |
| 428 | * Tradeoff: Using precomputed ROM tables reduces RAM usage by ~8kb |
| 429 | * (or ~2kb if \c MBEDTLS_AES_FEWER_TABLES is used) and reduces the |
| 430 | * initialization time before the first AES operation can be performed. |
| 431 | * It comes at the cost of additional ~8kb ROM use (resp. ~2kb if \c |
| 432 | * MBEDTLS_AES_FEWER_TABLES below is used), and potentially degraded |
| 433 | * performance if ROM access is slower than RAM access. |
| 434 | * |
| 435 | * This option is independent of \c MBEDTLS_AES_FEWER_TABLES. |
| 436 | */ |
| 437 | #define MBEDTLS_AES_ROM_TABLES |
| 438 | |
| 439 | /** |
| 440 | * \def MBEDTLS_AES_FEWER_TABLES |
| 441 | * |
| 442 | * Use less ROM/RAM for AES tables. |
| 443 | * |
| 444 | * Uncommenting this macro omits 75% of the AES tables from |
| 445 | * ROM / RAM (depending on the value of \c MBEDTLS_AES_ROM_TABLES) |
| 446 | * by computing their values on the fly during operations |
| 447 | * (the tables are entry-wise rotations of one another). |
| 448 | * |
| 449 | * Tradeoff: Uncommenting this reduces the RAM / ROM footprint |
| 450 | * by ~6kb but at the cost of more arithmetic operations during |
| 451 | * runtime. Specifically, one has to compare 4 accesses within |
| 452 | * different tables to 4 accesses with additional arithmetic |
| 453 | * operations within the same table. The performance gain/loss |
| 454 | * depends on the system and memory details. |
| 455 | * |
| 456 | * This option is independent of \c MBEDTLS_AES_ROM_TABLES. |
| 457 | */ |
| 458 | #define MBEDTLS_AES_FEWER_TABLES |
| 459 | |
| 460 | /** |
| 461 | * \def MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH |
| 462 | * |
| 463 | * Use only 128-bit keys in AES operations to save ROM. |
| 464 | * |
| 465 | * Uncomment this macro to remove support for AES operations that use 192- |
| 466 | * or 256-bit keys. |
| 467 | * |
| 468 | * Uncommenting this macro reduces the size of AES code by ~300 bytes |
| 469 | * on v8-M/Thumb2. |
| 470 | * |
| 471 | * Module: drivers/builtin/src/aes.c |
| 472 | * |
| 473 | * Requires: The AES built-in implementation |
| 474 | */ |
| 475 | #define MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH |
| 476 | |
| 477 | /** |
| 478 | * \def MBEDTLS_ECP_NIST_OPTIM |
| 479 | * |
| 480 | * Enable specific 'modulo p' routines for each NIST prime. |
| 481 | * Depending on the prime and architecture, makes operations 4 to 8 times |
| 482 | * faster on the corresponding curve. |
| 483 | * |
| 484 | * Comment this macro to disable NIST curves optimisation. |
| 485 | */ |
| 486 | #define MBEDTLS_ECP_NIST_OPTIM |
| 487 | |
| 488 | /** |
| 489 | * \def MBEDTLS_HAVE_ASM |
| 490 | * |
| 491 | * The compiler has support for asm(). |
| 492 | * |
| 493 | * Requires support for asm() in compiler. |
| 494 | * |
| 495 | * Used in: |
| 496 | * drivers/builtin/src/aesni.h |
| 497 | * drivers/builtin/src/aria.c |
| 498 | * drivers/builtin/src/bn_mul.h |
| 499 | * utilities/constant_time.c |
| 500 | * |
| 501 | * Required by: |
| 502 | * MBEDTLS_AESCE_C |
| 503 | * MBEDTLS_AESNI_C (on some platforms) |
| 504 | * |
| 505 | * Comment to disable the use of assembly code. |
| 506 | */ |
| 507 | #define MBEDTLS_HAVE_ASM |
| 508 | |
| 509 | /** |
| 510 | * Uncomment to enable p256-m. This is an alternative implementation of |
| 511 | * key generation, ECDH and (randomized) ECDSA on the curve SECP256R1. |
| 512 | * Compared to the default implementation: |
| 513 | * |
| 514 | * - p256-m has a much smaller code size and RAM footprint. |
| 515 | * - p256-m is only available via the PSA API. This includes the pk module. |
| 516 | * - p256-m does not support deterministic ECDSA, EC-JPAKE, custom protocols |
| 517 | * over the core arithmetic, or deterministic derivation of keys. |
| 518 | * |
| 519 | * We recommend enabling this option if your application uses the PSA API |
| 520 | * and the only elliptic curve support it needs is ECDH and ECDSA over |
| 521 | * SECP256R1. |
| 522 | * |
| 523 | * If you enable this option, you do not need to enable any ECC-related |
| 524 | * MBEDTLS_xxx option. You do need to separately request support for the |
| 525 | * cryptographic mechanisms through the PSA API: |
| 526 | * - #MBEDTLS_PSA_CRYPTO_C for PSA-based configuration; |
| 527 | * - #PSA_WANT_ECC_SECP_R1_256; |
| 528 | * - #PSA_WANT_ALG_ECDH and/or #PSA_WANT_ALG_ECDSA as needed; |
| 529 | * - #PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY, #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC, |
| 530 | * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT, |
| 531 | * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT and/or |
| 532 | * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE as needed. |
| 533 | * |
| 534 | * \note To benefit from the smaller code size of p256-m, make sure that you |
| 535 | * do not enable any ECC-related option not supported by p256-m: this |
| 536 | * would cause the built-in ECC implementation to be built as well, in |
| 537 | * order to provide the required option. |
| 538 | * Make sure #PSA_WANT_ALG_DETERMINISTIC_ECDSA, #PSA_WANT_ALG_JPAKE and |
| 539 | * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE, and curves other than |
| 540 | * SECP256R1 are disabled as they are not supported by this driver. |
| 541 | * Also, avoid defining #MBEDTLS_PK_PARSE_EC_COMPRESSED or |
| 542 | * #MBEDTLS_PK_PARSE_EC_EXTENDED as those currently require a subset of |
| 543 | * the built-in ECC implementation, see docs/driver-only-builds.md. |
| 544 | */ |
| 545 | #define MBEDTLS_PSA_P256M_DRIVER_ENABLED |
| 546 | |
| 547 | /** |
| 548 | * \def MBEDTLS_SHA256_SMALLER |
| 549 | * |
| 550 | * Enable an implementation of SHA-256 that has lower ROM footprint but also |
| 551 | * lower performance. |
| 552 | * |
| 553 | * The default implementation is meant to be a reasonable compromise between |
| 554 | * performance and size. This version optimizes more aggressively for size at |
| 555 | * the expense of performance. Eg on Cortex-M4 it reduces the size of |
| 556 | * mbedtls_sha256_process() from ~2KB to ~0.5KB for a performance hit of about |
| 557 | * 30%. |
| 558 | * |
| 559 | * Uncomment to enable the smaller implementation of SHA256. |
| 560 | */ |
| 561 | #define MBEDTLS_SHA256_SMALLER |
| 562 | |
| 563 | /* ECP options */ |
| 564 | #define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Disable fixed-point speed-up */ |
| 565 | |
| 566 | /** \} name SECTION: Builtin drivers */ |
| 567 | |
| 568 | /***********************************************************/ |
| 569 | /* Tweak the configuration to remove dependencies on TF-M. */ |
| 570 | /***********************************************************/ |
| 571 | |
| 572 | /* MBEDTLS_PSA_CRYPTO_SPM needs third-party files, so disable it. */ |
| 573 | #undef MBEDTLS_PSA_CRYPTO_SPM |
| 574 | |
| 575 | /* Disable buffer-based memory allocator. This isn't strictly required, |
| 576 | * but using the native allocator is faster and works better with |
| 577 | * memory management analysis frameworks such as ASan. */ |
| 578 | #undef MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 579 | |
| 580 | // This macro is enabled in TFM Medium but is disabled here because it is |
| 581 | // incompatible with baremetal builds in Mbed TLS. |
| 582 | #undef MBEDTLS_PSA_CRYPTO_STORAGE_C |
| 583 | |
| 584 | // This macro is enabled in TFM Medium but is disabled here because it is |
| 585 | // incompatible with baremetal builds in Mbed TLS. |
| 586 | #undef MBEDTLS_ENTROPY_NV_SEED |
| 587 | |
| 588 | // This macro is disabled in TFM Medium but enabled in integrations with |
| 589 | // supported hardware. Enable it because we need an entropy source in our |
| 590 | // test builds. |
| 591 | #define MBEDTLS_PSA_DRIVER_GET_ENTROPY |
| 592 | |
| 593 | // These platform-related TF-M settings are not useful here. |
| 594 | #undef MBEDTLS_PLATFORM_NO_STD_FUNCTIONS |
| 595 | #undef MBEDTLS_PLATFORM_STD_MEM_HDR |
| 596 | #undef MBEDTLS_PLATFORM_SNPRINTF_MACRO |
| 597 | #undef MBEDTLS_PLATFORM_PRINTF_ALT |
| 598 | #undef MBEDTLS_PLATFORM_STD_EXIT_SUCCESS |
| 599 | #undef MBEDTLS_PLATFORM_STD_EXIT_FAILURE |
| 600 | |
| 601 | /*********************************************************************** |
| 602 | * Local changes to crypto config below this delimiter |
| 603 | **********************************************************************/ |
| 604 | |
| 605 | // We expect TF-M to pick this up soon |
| 606 | #define MBEDTLS_BLOCK_CIPHER_NO_DECRYPT |
| 607 | |
| 608 | #if CRYPTO_NV_SEED |
| 609 | #include "tfm_mbedcrypto_config_extra_nv_seed.h" |
| 610 | #endif /* CRYPTO_NV_SEED */ |
| 611 | |
| 612 | #if !defined(CRYPTO_HW_ACCELERATOR) && defined(MBEDTLS_ENTROPY_NV_SEED) |
| 613 | #include "mbedtls_entropy_nv_seed_config.h" |
| 614 | #endif |
| 615 | |
| 616 | #ifdef CRYPTO_HW_ACCELERATOR |
| 617 | #include "crypto_accelerator_config.h" |
| 618 | #endif |
| 619 | |
| 620 | #endif /* PROFILE_M_PSA_CRYPTO_CONFIG_H */ |