blob: 67de4c0fd992e56d4e3c90ae2a314e722c12c5c5 [file] [log] [blame]
Dave Rodgman27a37852023-12-08 15:27:49 +00001/*
2 * Copyright (c) 2018-2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
Aditya Deshpande16a62e32023-04-11 16:25:02 +01007/**
8 * \file psa/crypto_config.h
9 * \brief PSA crypto configuration options (set of defines)
10 *
11 */
Aditya Deshpande16a62e32023-04-11 16:25:02 +010012
13#ifndef PROFILE_M_PSA_CRYPTO_CONFIG_H
14#define PROFILE_M_PSA_CRYPTO_CONFIG_H
15
Ronald Cron26540812024-12-05 16:52:17 +010016/**
17 * \name SECTION: Platform abstraction layer
18 *
19 * This section sets platform specific settings.
20 * \{
21 */
22
23/**
24 * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C
25 *
26 * Enable the buffer allocator implementation that makes use of a (stack)
27 * based buffer to 'allocate' dynamic memory. (replaces calloc() and free()
28 * calls)
29 *
30 * Module: library/memory_buffer_alloc.c
31 *
32 * Requires: MBEDTLS_PLATFORM_C
33 * MBEDTLS_PLATFORM_MEMORY (to use it within Mbed TLS)
34 *
35 * Enable this module to enable the buffer memory allocator.
36 */
37#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
38
39/**
40 * \def MBEDTLS_PLATFORM_C
41 *
42 * Enable the platform abstraction layer that allows you to re-assign
43 * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit().
44 *
45 * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT
46 * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned
47 * above to be specified at runtime or compile time respectively.
48 *
49 * \note This abstraction layer must be enabled on Windows (including MSYS2)
50 * as other modules rely on it for a fixed snprintf implementation.
51 *
52 * Module: library/platform.c
53 * Caller: Most other .c files
54 *
55 * This module enables abstraction of common (libc) functions.
56 */
57#define MBEDTLS_PLATFORM_C
58
59/**
60 * \def MBEDTLS_PLATFORM_MEMORY
61 *
62 * Enable the memory allocation layer.
63 *
64 * By default Mbed TLS uses the system-provided calloc() and free().
65 * This allows different allocators (self-implemented or provided) to be
66 * provided to the platform abstraction layer.
67 *
68 * Enabling #MBEDTLS_PLATFORM_MEMORY without the
69 * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide
70 * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and
71 * free() function pointer at runtime.
72 *
73 * Enabling #MBEDTLS_PLATFORM_MEMORY and specifying
74 * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the
75 * alternate function at compile time.
76 *
77 * An overview of how the value of mbedtls_calloc is determined:
78 *
79 * - if !MBEDTLS_PLATFORM_MEMORY
80 * - mbedtls_calloc = calloc
81 * - if MBEDTLS_PLATFORM_MEMORY
82 * - if (MBEDTLS_PLATFORM_CALLOC_MACRO && MBEDTLS_PLATFORM_FREE_MACRO):
83 * - mbedtls_calloc = MBEDTLS_PLATFORM_CALLOC_MACRO
84 * - if !(MBEDTLS_PLATFORM_CALLOC_MACRO && MBEDTLS_PLATFORM_FREE_MACRO):
85 * - Dynamic setup via mbedtls_platform_set_calloc_free is now possible with a default value MBEDTLS_PLATFORM_STD_CALLOC.
86 * - How is MBEDTLS_PLATFORM_STD_CALLOC handled?
87 * - if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS:
88 * - MBEDTLS_PLATFORM_STD_CALLOC is not set to anything;
89 * - MBEDTLS_PLATFORM_STD_MEM_HDR can be included if present;
90 * - if !MBEDTLS_PLATFORM_NO_STD_FUNCTIONS:
91 * - if MBEDTLS_PLATFORM_STD_CALLOC is present:
92 * - User-defined MBEDTLS_PLATFORM_STD_CALLOC is respected;
93 * - if !MBEDTLS_PLATFORM_STD_CALLOC:
94 * - MBEDTLS_PLATFORM_STD_CALLOC = calloc
95 *
96 * - At this point the presence of MBEDTLS_PLATFORM_STD_CALLOC is checked.
97 * - if !MBEDTLS_PLATFORM_STD_CALLOC
98 * - MBEDTLS_PLATFORM_STD_CALLOC = uninitialized_calloc
99 *
100 * - mbedtls_calloc = MBEDTLS_PLATFORM_STD_CALLOC.
101 *
102 * Defining MBEDTLS_PLATFORM_CALLOC_MACRO and #MBEDTLS_PLATFORM_STD_CALLOC at the same time is not possible.
103 * MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_FREE_MACRO must both be defined or undefined at the same time.
104 * #MBEDTLS_PLATFORM_STD_CALLOC and #MBEDTLS_PLATFORM_STD_FREE do not have to be defined at the same time, as, if they are used,
105 * dynamic setup of these functions is possible. See the tree above to see how are they handled in all cases.
106 * An uninitialized #MBEDTLS_PLATFORM_STD_CALLOC always fails, returning a null pointer.
107 * An uninitialized #MBEDTLS_PLATFORM_STD_FREE does not do anything.
108 *
109 * Requires: MBEDTLS_PLATFORM_C
110 *
111 * Enable this layer to allow use of alternative memory allocators.
112 */
113#define MBEDTLS_PLATFORM_MEMORY
114
115/**
116 * \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
117 *
118 * Do not assign standard functions in the platform layer (e.g. calloc() to
119 * MBEDTLS_PLATFORM_STD_CALLOC and printf() to MBEDTLS_PLATFORM_STD_PRINTF)
120 *
121 * This makes sure there are no linking errors on platforms that do not support
122 * these functions. You will HAVE to provide alternatives, either at runtime
123 * via the platform_set_xxx() functions or at compile time by setting
124 * the MBEDTLS_PLATFORM_STD_XXX defines, or enabling a
125 * MBEDTLS_PLATFORM_XXX_MACRO.
126 *
127 * Requires: MBEDTLS_PLATFORM_C
128 *
129 * Uncomment to prevent default assignment of standard functions in the
130 * platform layer.
131 */
132#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
133
134#define MBEDTLS_PLATFORM_PRINTF_ALT
135
136/* To use the following function macros, MBEDTLS_PLATFORM_C must be enabled. */
137/* MBEDTLS_PLATFORM_XXX_MACRO and MBEDTLS_PLATFORM_XXX_ALT cannot both be defined */
138
139#include <stdio.h>
140
141#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf
142#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE
143#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS
144
145#define MBEDTLS_PLATFORM_STD_MEM_HDR <stdlib.h>
146
147/** \} name SECTION: Platform abstraction layer */
148
149/**
150 * \name SECTION: SECTION Cryptographic mechanism selection (PSA API)
151 *
152 * This section sets PSA API settings.
153 * \{
154 */
Aditya Deshpande16a62e32023-04-11 16:25:02 +0100155/*
156 * CBC-MAC is not yet supported via the PSA API in Mbed TLS.
157 */
158//#define PSA_WANT_ALG_CBC_MAC 1
159//#define PSA_WANT_ALG_CBC_NO_PADDING 1
160//#define PSA_WANT_ALG_CBC_PKCS7 1
161#define PSA_WANT_ALG_CCM 1
162//#define PSA_WANT_ALG_CMAC 1
163//#define PSA_WANT_ALG_CFB 1
164//#define PSA_WANT_ALG_CHACHA20_POLY1305 1
165//#define PSA_WANT_ALG_CTR 1
Dave Rodgman4edcf692023-11-15 12:23:29 +0000166//#define PSA_WANT_ALG_DETERMINISTIC_ECDSA 1
Aditya Deshpande16a62e32023-04-11 16:25:02 +0100167//#define PSA_WANT_ALG_ECB_NO_PADDING 1
168#define PSA_WANT_ALG_ECDH 1
169#define PSA_WANT_ALG_ECDSA 1
170//#define PSA_WANT_ALG_GCM 1
171#define PSA_WANT_ALG_HKDF 1
172#define PSA_WANT_ALG_HMAC 1
173//#define PSA_WANT_ALG_MD5 1
174//#define PSA_WANT_ALG_OFB 1
175/* PBKDF2-HMAC is not yet supported via the PSA API in Mbed TLS.
176 * Note: when adding support, also adjust include/mbedtls/config_psa.h */
177//#define PSA_WANT_ALG_PBKDF2_HMAC 1
178//#define PSA_WANT_ALG_RIPEMD160 1
179//#define PSA_WANT_ALG_RSA_OAEP 1
180//#define PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
181//#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
182//#define PSA_WANT_ALG_RSA_PSS 1
183//#define PSA_WANT_ALG_SHA_1 1
184#define PSA_WANT_ALG_SHA_224 1
185#define PSA_WANT_ALG_SHA_256 1
186//#define PSA_WANT_ALG_SHA_384 1
187//#define PSA_WANT_ALG_SHA_512 1
188//#define PSA_WANT_ALG_STREAM_CIPHER 1
189#define PSA_WANT_ALG_TLS12_PRF 1
190#define PSA_WANT_ALG_TLS12_PSK_TO_MS 1
191/* PBKDF2-HMAC is not yet supported via the PSA API in Mbed TLS.
192 * Note: when adding support, also adjust include/mbedtls/config_psa.h */
193//#define PSA_WANT_ALG_XTS 1
194
195//#define PSA_WANT_ECC_BRAINPOOL_P_R1_256 1
196//#define PSA_WANT_ECC_BRAINPOOL_P_R1_384 1
197//#define PSA_WANT_ECC_BRAINPOOL_P_R1_512 1
198//#define PSA_WANT_ECC_MONTGOMERY_255 1
199//#define PSA_WANT_ECC_MONTGOMERY_448 1
200//#define PSA_WANT_ECC_SECP_K1_192 1
201/*
202 * SECP224K1 is buggy via the PSA API in Mbed TLS
203 * (https://github.com/Mbed-TLS/mbedtls/issues/3541). Thus, do not enable it by
204 * default.
205 */
206//#define PSA_WANT_ECC_SECP_K1_224 1
207//#define PSA_WANT_ECC_SECP_K1_256 1
208//#define PSA_WANT_ECC_SECP_R1_192 1
209//#define PSA_WANT_ECC_SECP_R1_224 1
210#define PSA_WANT_ECC_SECP_R1_256 1
211//#define PSA_WANT_ECC_SECP_R1_384 1
212//#define PSA_WANT_ECC_SECP_R1_521 1
213
214#define PSA_WANT_KEY_TYPE_DERIVE 1
215#define PSA_WANT_KEY_TYPE_HMAC 1
216#define PSA_WANT_KEY_TYPE_AES 1
217//#define PSA_WANT_KEY_TYPE_ARIA 1
218//#define PSA_WANT_KEY_TYPE_CAMELLIA 1
219//#define PSA_WANT_KEY_TYPE_CHACHA20 1
220//#define PSA_WANT_KEY_TYPE_DES 1
Dave Rodgman4edcf692023-11-15 12:23:29 +0000221//#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR 1 /* Deprecated */
222#define PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
223#define PSA_WANT_KEY_TYPE_RAW_DATA 1
224//#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1 /* Deprecated */
225//#define PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
226
227/*
228 * The following symbols extend and deprecate the legacy
229 * PSA_WANT_KEY_TYPE_xxx_KEY_PAIR ones. They include the usage of that key in
230 * the name's suffix. "_USE" is the most generic and it can be used to describe
231 * a generic suport, whereas other ones add more features on top of that and
232 * they are more specific.
233 */
234#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC 1
Valerio Settiae064432023-06-26 12:13:38 +0200235#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT 1
236#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT 1
237#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE 1
Dave Rodgman4edcf692023-11-15 12:23:29 +0000238//#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE 1
Aditya Deshpande16a62e32023-04-11 16:25:02 +0100239
Ronald Cron26540812024-12-05 16:52:17 +0100240/** \} name SECTION Cryptographic mechanism selection (PSA API) */
241
242/**
243 * \name SECTION: PSA core
244 *
245 * This section sets PSA specific settings.
246 * \{
247 */
248
249/**
250 * \def MBEDTLS_ENTROPY_C
251 *
252 * Enable the platform-specific entropy code.
253 *
254 * Module: library/entropy.c
255 * Caller:
256 *
257 * Requires: MBEDTLS_SHA512_C or MBEDTLS_SHA256_C
258 *
259 * This module provides a generic entropy pool
260 */
261#define MBEDTLS_ENTROPY_C
262
263/**
264 * \def MBEDTLS_ENTROPY_NV_SEED
265 *
266 * Enable the non-volatile (NV) seed file-based entropy source.
267 * (Also enables the NV seed read/write functions in the platform layer)
268 *
269 * This is crucial (if not required) on systems that do not have a
270 * cryptographic entropy source (in hardware or kernel) available.
271 *
272 * Requires: MBEDTLS_ENTROPY_C, MBEDTLS_PLATFORM_C
273 *
274 * \note The read/write functions that are used by the entropy source are
275 * determined in the platform layer, and can be modified at runtime and/or
276 * compile-time depending on the flags (MBEDTLS_PLATFORM_NV_SEED_*) used.
277 *
278 * \note If you use the default implementation functions that read a seedfile
279 * with regular fopen(), please make sure you make a seedfile with the
280 * proper name (defined in MBEDTLS_PLATFORM_STD_NV_SEED_FILE) and at
281 * least MBEDTLS_ENTROPY_BLOCK_SIZE bytes in size that can be read from
282 * and written to or you will get an entropy source error! The default
283 * implementation will only use the first MBEDTLS_ENTROPY_BLOCK_SIZE
284 * bytes from the file.
285 *
286 * \note The entropy collector will write to the seed file before entropy is
287 * given to an external source, to update it.
288 */
289#define MBEDTLS_ENTROPY_NV_SEED
290
291/**
292 * \def MBEDTLS_NO_PLATFORM_ENTROPY
293 *
294 * Do not use built-in platform entropy functions.
295 * This is useful if your platform does not support
296 * standards like the /dev/urandom or Windows CryptoAPI.
297 *
298 * Uncomment this macro to disable the built-in platform entropy functions.
299 */
300#define MBEDTLS_NO_PLATFORM_ENTROPY
301
302/**
303 * \def MBEDTLS_PSA_CRYPTO_C
304 *
305 * Enable the Platform Security Architecture cryptography API.
306 *
307 * Module: library/psa_crypto.c
308 *
309 * Requires: either MBEDTLS_CTR_DRBG_C and MBEDTLS_ENTROPY_C,
310 * or MBEDTLS_HMAC_DRBG_C and MBEDTLS_ENTROPY_C,
311 * or MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG.
312 * Auto-enables: MBEDTLS_CIPHER_C if any unauthenticated (ie, non-AEAD) cipher
313 * is enabled in PSA (unless it's fully accelerated, see
314 * docs/driver-only-builds.md about that).
315 */
316#define MBEDTLS_PSA_CRYPTO_C
317
318/**
319 * \def MBEDTLS_PSA_CRYPTO_SPM
320 *
321 * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is built for SPM (Secure
322 * Partition Manager) integration which separates the code into two parts: a
323 * NSPE (Non-Secure Process Environment) and an SPE (Secure Process
324 * Environment).
325 *
326 * If you enable this option, your build environment must include a header
327 * file `"crypto_spe.h"` (either in the `psa` subdirectory of the Mbed TLS
328 * header files, or in another directory on the compiler's include search
329 * path). Alternatively, your platform may customize the header
330 * `psa/crypto_platform.h`, in which case it can skip or replace the
331 * inclusion of `"crypto_spe.h"`.
332 *
333 * Module: library/psa_crypto.c
334 * Requires: MBEDTLS_PSA_CRYPTO_C
335 *
336 */
337#define MBEDTLS_PSA_CRYPTO_SPM
338
339/**
340 * \def MBEDTLS_PSA_CRYPTO_STORAGE_C
341 *
342 * Enable the Platform Security Architecture persistent key storage.
343 *
344 * Module: library/psa_crypto_storage.c
345 *
346 * Requires: MBEDTLS_PSA_CRYPTO_C,
347 * either MBEDTLS_PSA_ITS_FILE_C or a native implementation of
348 * the PSA ITS interface
349 */
350#define MBEDTLS_PSA_CRYPTO_STORAGE_C
351
352/** \} name SECTION: PSA core */
353
354/**
355 * \name SECTION: Builtin drivers
356 *
357 * This section sets driver specific settings.
358 * \{
359 */
360
361/**
362 * \def MBEDTLS_AES_ROM_TABLES
363 *
364 * Use precomputed AES tables stored in ROM.
365 *
366 * Uncomment this macro to use precomputed AES tables stored in ROM.
367 * Comment this macro to generate AES tables in RAM at runtime.
368 *
369 * Tradeoff: Using precomputed ROM tables reduces RAM usage by ~8kb
370 * (or ~2kb if \c MBEDTLS_AES_FEWER_TABLES is used) and reduces the
371 * initialization time before the first AES operation can be performed.
372 * It comes at the cost of additional ~8kb ROM use (resp. ~2kb if \c
373 * MBEDTLS_AES_FEWER_TABLES below is used), and potentially degraded
374 * performance if ROM access is slower than RAM access.
375 *
376 * This option is independent of \c MBEDTLS_AES_FEWER_TABLES.
377 */
378#define MBEDTLS_AES_ROM_TABLES
379
380/**
381 * \def MBEDTLS_AES_FEWER_TABLES
382 *
383 * Use less ROM/RAM for AES tables.
384 *
385 * Uncommenting this macro omits 75% of the AES tables from
386 * ROM / RAM (depending on the value of \c MBEDTLS_AES_ROM_TABLES)
387 * by computing their values on the fly during operations
388 * (the tables are entry-wise rotations of one another).
389 *
390 * Tradeoff: Uncommenting this reduces the RAM / ROM footprint
391 * by ~6kb but at the cost of more arithmetic operations during
392 * runtime. Specifically, one has to compare 4 accesses within
393 * different tables to 4 accesses with additional arithmetic
394 * operations within the same table. The performance gain/loss
395 * depends on the system and memory details.
396 *
397 * This option is independent of \c MBEDTLS_AES_ROM_TABLES.
398 */
399#define MBEDTLS_AES_FEWER_TABLES
400
401/**
402 * \def MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
403 *
404 * Use only 128-bit keys in AES operations to save ROM.
405 *
406 * Uncomment this macro to remove support for AES operations that use 192-
407 * or 256-bit keys.
408 *
409 * Uncommenting this macro reduces the size of AES code by ~300 bytes
410 * on v8-M/Thumb2.
411 *
412 * Module: library/aes.c
413 *
414 * Requires: MBEDTLS_AES_C
415 */
416#define MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
417
418/**
419 * \def MBEDTLS_ECP_NIST_OPTIM
420 *
421 * Enable specific 'modulo p' routines for each NIST prime.
422 * Depending on the prime and architecture, makes operations 4 to 8 times
423 * faster on the corresponding curve.
424 *
425 * Comment this macro to disable NIST curves optimisation.
426 */
427#define MBEDTLS_ECP_NIST_OPTIM
428
429/**
430 * \def MBEDTLS_HAVE_ASM
431 *
432 * The compiler has support for asm().
433 *
434 * Requires support for asm() in compiler.
435 *
436 * Used in:
437 * library/aesni.h
438 * library/aria.c
439 * library/bn_mul.h
440 * library/constant_time.c
441 *
442 * Required by:
443 * MBEDTLS_AESCE_C
444 * MBEDTLS_AESNI_C (on some platforms)
445 *
446 * Comment to disable the use of assembly code.
447 */
448#define MBEDTLS_HAVE_ASM
449
450/**
451 * Uncomment to enable p256-m. This is an alternative implementation of
452 * key generation, ECDH and (randomized) ECDSA on the curve SECP256R1.
453 * Compared to the default implementation:
454 *
455 * - p256-m has a much smaller code size and RAM footprint.
456 * - p256-m is only available via the PSA API. This includes the pk module.
457 * - p256-m does not support deterministic ECDSA, EC-JPAKE, custom protocols
458 * over the core arithmetic, or deterministic derivation of keys.
459 *
460 * We recommend enabling this option if your application uses the PSA API
461 * and the only elliptic curve support it needs is ECDH and ECDSA over
462 * SECP256R1.
463 *
464 * If you enable this option, you do not need to enable any ECC-related
465 * MBEDTLS_xxx option. You do need to separately request support for the
466 * cryptographic mechanisms through the PSA API:
467 * - #MBEDTLS_PSA_CRYPTO_C for PSA-based configuration;
468 * - #PSA_WANT_ECC_SECP_R1_256;
469 * - #PSA_WANT_ALG_ECDH and/or #PSA_WANT_ALG_ECDSA as needed;
470 * - #PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY, #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC,
471 * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT,
472 * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT and/or
473 * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE as needed.
474 *
475 * \note To benefit from the smaller code size of p256-m, make sure that you
476 * do not enable any ECC-related option not supported by p256-m: this
477 * would cause the built-in ECC implementation to be built as well, in
478 * order to provide the required option.
479 * Make sure #PSA_WANT_ALG_DETERMINISTIC_ECDSA, #PSA_WANT_ALG_JPAKE and
480 * #PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE, and curves other than
481 * SECP256R1 are disabled as they are not supported by this driver.
482 * Also, avoid defining #MBEDTLS_PK_PARSE_EC_COMPRESSED or
483 * #MBEDTLS_PK_PARSE_EC_EXTENDED as those currently require a subset of
484 * the built-in ECC implementation, see docs/driver-only-builds.md.
485 */
486#define MBEDTLS_PSA_P256M_DRIVER_ENABLED
487
488/**
489 * \def MBEDTLS_SHA256_SMALLER
490 *
491 * Enable an implementation of SHA-256 that has lower ROM footprint but also
492 * lower performance.
493 *
494 * The default implementation is meant to be a reasonable compromise between
495 * performance and size. This version optimizes more aggressively for size at
496 * the expense of performance. Eg on Cortex-M4 it reduces the size of
497 * mbedtls_sha256_process() from ~2KB to ~0.5KB for a performance hit of about
498 * 30%.
499 *
500 * Uncomment to enable the smaller implementation of SHA256.
501 */
502#define MBEDTLS_SHA256_SMALLER
503
504/* ECP options */
505#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Disable fixed-point speed-up */
506
507/** \} name SECTION: Builtin drivers */
508
509/**
510 * \name SECTION: Legacy cryptography
511 *
512 * This section sets legacy settings.
513 * \{
514 */
515
516/**
517 * \def MBEDTLS_AES_C
518 *
519 * Enable the AES block cipher.
520 *
521 * Module: library/aes.c
522 * Caller: library/cipher.c
523 * library/pem.c
524 * library/ctr_drbg.c
525 *
526 * This module enables the following ciphersuites (if other requisites are
527 * enabled as well):
528 * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
529 * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
530 * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
531 * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
532 * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
533 * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
534 * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
535 * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
536 * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
537 * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
538 * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
539 * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
540 * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
541 * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
542 * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
543 * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
544 * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
545 * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
546 * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
547 * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
548 * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
549 * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
550 * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
551 * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
552 * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
553 * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
554 * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
555 * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
556 * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
557 * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
558 * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
559 * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384
560 * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
561 * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
562 * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA
563 * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
564 * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
565 * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
566 * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
567 * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA
568 * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384
569 * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256
570 * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA
571 * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256
572 * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256
573 * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA
574 * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384
575 * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384
576 * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA
577 * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256
578 * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256
579 * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA
580 *
581 * PEM_PARSE uses AES for decrypting encrypted keys.
582 */
583#define MBEDTLS_AES_C
584
585/**
586 * \def MBEDTLS_CIPHER_C
587 *
588 * Enable the generic cipher layer.
589 *
590 * Module: library/cipher.c
591 * Caller: library/ccm.c
592 * library/cmac.c
593 * library/gcm.c
594 * library/nist_kw.c
595 * library/pkcs12.c
596 * library/pkcs5.c
597 * library/psa_crypto_aead.c
598 * library/psa_crypto_mac.c
599 * library/ssl_ciphersuites.c
600 * library/ssl_msg.c
601 * Auto-enabled by: MBEDTLS_PSA_CRYPTO_C depending on which ciphers are enabled
602 * (see the documentation of that option for details).
603 *
604 * Uncomment to enable generic cipher wrappers.
605 */
606#define MBEDTLS_CIPHER_C
607
608/**
609 * \def MBEDTLS_CTR_DRBG_C
610 *
611 * Enable the CTR_DRBG AES-based random generator.
612 * The CTR_DRBG generator uses AES-256 by default.
613 * To use AES-128 instead, enable \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY above.
614 *
615 * AES support can either be achieved through builtin (MBEDTLS_AES_C) or PSA.
616 * Builtin is the default option when MBEDTLS_AES_C is defined otherwise PSA
617 * is used.
618 *
619 * \warning When using PSA, the user should call `psa_crypto_init()` before
620 * using any CTR_DRBG operation (except `mbedtls_ctr_drbg_init()`).
621 *
622 * \note AES-128 will be used if \c MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH is set.
623 *
624 * \note To achieve a 256-bit security strength with CTR_DRBG,
625 * you must use AES-256 *and* use sufficient entropy.
626 * See ctr_drbg.h for more details.
627 *
628 * Module: library/ctr_drbg.c
629 * Caller:
630 *
631 * Requires: MBEDTLS_AES_C or
632 * (PSA_WANT_KEY_TYPE_AES and PSA_WANT_ALG_ECB_NO_PADDING and
633 * MBEDTLS_PSA_CRYPTO_C)
634 *
635 * This module provides the CTR_DRBG AES random number generator.
636 */
637#define MBEDTLS_CTR_DRBG_C
638/** \} name SECTION: Legacy cryptography */
639
Minos Galanakisbca85e62024-11-01 17:32:54 +0000640/***********************************************************/
641/* Tweak the configuration to remove dependencies on TF-M. */
642/***********************************************************/
643
644/* MBEDTLS_PSA_CRYPTO_SPM needs third-party files, so disable it. */
645#undef MBEDTLS_PSA_CRYPTO_SPM
646
647/* Disable buffer-based memory allocator. This isn't strictly required,
648 * but using the native allocator is faster and works better with
649 * memory management analysis frameworks such as ASan. */
650#undef MBEDTLS_MEMORY_BUFFER_ALLOC_C
651
652// This macro is enabled in TFM Medium but is disabled here because it is
653// incompatible with baremetal builds in Mbed TLS.
654#undef MBEDTLS_PSA_CRYPTO_STORAGE_C
655
656// This macro is enabled in TFM Medium but is disabled here because it is
657// incompatible with baremetal builds in Mbed TLS.
658#undef MBEDTLS_ENTROPY_NV_SEED
659
660// These platform-related TF-M settings are not useful here.
661#undef MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
662#undef MBEDTLS_PLATFORM_STD_MEM_HDR
663#undef MBEDTLS_PLATFORM_SNPRINTF_MACRO
664#undef MBEDTLS_PLATFORM_PRINTF_ALT
665#undef MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
666#undef MBEDTLS_PLATFORM_STD_EXIT_FAILURE
667
668/*
669 * In order to get an example config that works cleanly out-of-the-box
670 * for both baremetal and non-baremetal builds, we detect baremetal builds
671 * (either IAR, Arm compiler or __ARM_EABI__ defined), and adjust some
672 * variables accordingly.
673 */
674#if defined(__IAR_SYSTEMS_ICC__) || defined(__ARMCC_VERSION) || defined(__ARM_EABI__)
675#define MBEDTLS_NO_PLATFORM_ENTROPY
676#else
677/* Use built-in platform entropy functions (TF-M provides its own). */
678#undef MBEDTLS_NO_PLATFORM_ENTROPY
679#endif
680
681/***********************************************************************
682 * Local changes to crypto config below this delimiter
683 **********************************************************************/
684
685// We expect TF-M to pick this up soon
686#define MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
687
688/* CCM is the only cipher/AEAD enabled in TF-M configuration files, but it
689 * does not need CIPHER_C to be enabled, so we can disable it in order
690 * to reduce code size further. */
691#undef MBEDTLS_CIPHER_C
692
Ronald Cron26540812024-12-05 16:52:17 +0100693#if CRYPTO_NV_SEED
694#include "tfm_mbedcrypto_config_extra_nv_seed.h"
695#endif /* CRYPTO_NV_SEED */
696
697#if !defined(CRYPTO_HW_ACCELERATOR) && defined(MBEDTLS_ENTROPY_NV_SEED)
698#include "mbedtls_entropy_nv_seed_config.h"
699#endif
700
Dave Rodgman4edcf692023-11-15 12:23:29 +0000701#ifdef CRYPTO_HW_ACCELERATOR
702#include "crypto_accelerator_config.h"
703#endif
Valerio Setti52e0fb42023-08-02 09:55:21 +0200704
Aditya Deshpande16a62e32023-04-11 16:25:02 +0100705#endif /* PROFILE_M_PSA_CRYPTO_CONFIG_H */