1 /*
2  * Copyright The TrustedFirmware-M Contributors
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 /**
8  * \file config.h
9  *
10  * \brief Configuration options (set of defines)
11  *
12  *  This set of compile-time options may be used to enable
13  *  or disable features selectively, and reduce the global
14  *  memory footprint.
15  */
16 
17 #ifndef PROFILE_L_MBEDTLS_CONFIG_H
18 #define PROFILE_L_MBEDTLS_CONFIG_H
19 
20 #include "config_tfm.h"
21 
22 #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
23 #define _CRT_SECURE_NO_DEPRECATE 1
24 #endif
25 
26 /**
27  * \name SECTION: System support
28  *
29  * This section sets system specific settings.
30  * \{
31  */
32 
33 /**
34  * \def MBEDTLS_HAVE_ASM
35  *
36  * The compiler has support for asm().
37  *
38  * Requires support for asm() in compiler.
39  *
40  * Used in:
41  *      library/aria.c
42  *      library/timing.c
43  *      include/mbedtls/bn_mul.h
44  *
45  * Required by:
46  *      MBEDTLS_AESNI_C
47  *      MBEDTLS_PADLOCK_C
48  *
49  * Comment to disable the use of assembly code.
50  */
51 #define MBEDTLS_HAVE_ASM
52 
53 /**
54  * \def MBEDTLS_PLATFORM_MEMORY
55  *
56  * Enable the memory allocation layer.
57  *
58  * By default mbed TLS uses the system-provided calloc() and free().
59  * This allows different allocators (self-implemented or provided) to be
60  * provided to the platform abstraction layer.
61  *
62  * Enabling MBEDTLS_PLATFORM_MEMORY without the
63  * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide
64  * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and
65  * free() function pointer at runtime.
66  *
67  * Enabling MBEDTLS_PLATFORM_MEMORY and specifying
68  * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the
69  * alternate function at compile time.
70  *
71  * Requires: MBEDTLS_PLATFORM_C
72  *
73  * Enable this layer to allow use of alternative memory allocators.
74  */
75 #define MBEDTLS_PLATFORM_MEMORY
76 
77 /* \} name SECTION: System support */
78 
79 /**
80  * \name SECTION: mbed TLS feature support
81  *
82  * This section sets support for features that are or are not needed
83  * within the modules that are enabled.
84  * \{
85  */
86 
87 /**
88  * \def MBEDTLS_AES_ROM_TABLES
89  *
90  * Use precomputed AES tables stored in ROM.
91  *
92  * Uncomment this macro to use precomputed AES tables stored in ROM.
93  * Comment this macro to generate AES tables in RAM at runtime.
94  *
95  * Tradeoff: Using precomputed ROM tables reduces RAM usage by ~8kb
96  * (or ~2kb if \c MBEDTLS_AES_FEWER_TABLES is used) and reduces the
97  * initialization time before the first AES operation can be performed.
98  * It comes at the cost of additional ~8kb ROM use (resp. ~2kb if \c
99  * MBEDTLS_AES_FEWER_TABLES below is used), and potentially degraded
100  * performance if ROM access is slower than RAM access.
101  *
102  * This option is independent of \c MBEDTLS_AES_FEWER_TABLES.
103  *
104  */
105 #define MBEDTLS_AES_ROM_TABLES
106 
107 /**
108  * \def MBEDTLS_AES_FEWER_TABLES
109  *
110  * Use less ROM/RAM for AES tables.
111  *
112  * Uncommenting this macro omits 75% of the AES tables from
113  * ROM / RAM (depending on the value of \c MBEDTLS_AES_ROM_TABLES)
114  * by computing their values on the fly during operations
115  * (the tables are entry-wise rotations of one another).
116  *
117  * Tradeoff: Uncommenting this reduces the RAM / ROM footprint
118  * by ~6kb but at the cost of more arithmetic operations during
119  * runtime. Specifically, one has to compare 4 accesses within
120  * different tables to 4 accesses with additional arithmetic
121  * operations within the same table. The performance gain/loss
122  * depends on the system and memory details.
123  *
124  * This option is independent of \c MBEDTLS_AES_ROM_TABLES.
125  *
126  */
127 #define MBEDTLS_AES_FEWER_TABLES
128 
129 /**
130  * \def MBEDTLS_ECP_NIST_OPTIM
131  *
132  * Enable specific 'modulo p' routines for each NIST prime.
133  * Depending on the prime and architecture, makes operations 4 to 8 times
134  * faster on the corresponding curve.
135  *
136  * Comment this macro to disable NIST curves optimisation.
137  */
138 #define MBEDTLS_ECP_NIST_OPTIM
139 
140 /**
141  * \def MBEDTLS_PK_PARSE_EC_EXTENDED
142  *
143  * Enhance support for reading EC keys using variants of SEC1 not allowed by
144  * RFC 5915 and RFC 5480.
145  *
146  * Currently this means parsing the SpecifiedECDomain choice of EC
147  * parameters (only known groups are supported, not arbitrary domains, to
148  * avoid validation issues).
149  *
150  * Disable if you only need to support RFC 5915 + 5480 key formats.
151  */
152 #define MBEDTLS_PK_PARSE_EC_EXTENDED
153 
154 /**
155  * \def MBEDTLS_NO_PLATFORM_ENTROPY
156  *
157  * Do not use built-in platform entropy functions.
158  * This is useful if your platform does not support
159  * standards like the /dev/urandom or Windows CryptoAPI.
160  *
161  * Uncomment this macro to disable the built-in platform entropy functions.
162  */
163 #define MBEDTLS_NO_PLATFORM_ENTROPY
164 
165 /**
166  * \def MBEDTLS_ENTROPY_NV_SEED
167  *
168  * Enable the non-volatile (NV) seed file-based entropy source.
169  * (Also enables the NV seed read/write functions in the platform layer)
170  *
171  * This is crucial (if not required) on systems that do not have a
172  * cryptographic entropy source (in hardware or kernel) available.
173  *
174  * Requires: MBEDTLS_ENTROPY_C, MBEDTLS_PLATFORM_C
175  *
176  * \note The read/write functions that are used by the entropy source are
177  *       determined in the platform layer, and can be modified at runtime and/or
178  *       compile-time depending on the flags (MBEDTLS_PLATFORM_NV_SEED_*) used.
179  *
180  * \note If you use the default implementation functions that read a seedfile
181  *       with regular fopen(), please make sure you make a seedfile with the
182  *       proper name (defined in MBEDTLS_PLATFORM_STD_NV_SEED_FILE) and at
183  *       least MBEDTLS_ENTROPY_BLOCK_SIZE bytes in size that can be read from
184  *       and written to or you will get an entropy source error! The default
185  *       implementation will only use the first MBEDTLS_ENTROPY_BLOCK_SIZE
186  *       bytes from the file.
187  *
188  * \note The entropy collector will write to the seed file before entropy is
189  *       given to an external source, to update it.
190  */
191 #define MBEDTLS_ENTROPY_NV_SEED
192 
193 /**
194  * \def MBEDTLS_PK_RSA_ALT_SUPPORT
195  *
196  * Support external private RSA keys (eg from a HSM) in the PK layer.
197  *
198  * Comment this macro to disable support for external private RSA keys.
199  */
200 #define MBEDTLS_PK_RSA_ALT_SUPPORT
201 
202 /**
203  * \def MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
204  *
205  * Assume all buffers passed to PSA functions are owned exclusively by the
206  * PSA function and are not stored in shared memory.
207  *
208  * This option may be enabled if all buffers passed to any PSA function reside
209  * in memory that is accessible only to the PSA function during its execution.
210  *
211  * This option MUST be disabled whenever buffer arguments are in memory shared
212  * with an untrusted party, for example where arguments to PSA calls are passed
213  * across a trust boundary.
214  *
215  * \note Enabling this option reduces memory usage and code size.
216  *
217  * \note Enabling this option causes overlap of input and output buffers
218  *       not to be supported by PSA functions.
219  */
220 #define MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
221 
222 /**
223  * \def MBEDTLS_PSA_CRYPTO_CONFIG
224  *
225  * This setting allows support for cryptographic mechanisms through the PSA
226  * API to be configured separately from support through the mbedtls API.
227  *
228  * When this option is disabled, the PSA API exposes the cryptographic
229  * mechanisms that can be implemented on top of the `mbedtls_xxx` API
230  * configured with `MBEDTLS_XXX` symbols.
231  *
232  * When this option is enabled, the PSA API exposes the cryptographic
233  * mechanisms requested by the `PSA_WANT_XXX` symbols defined in
234  * include/psa/crypto_config.h. The corresponding `MBEDTLS_XXX` settings are
235  * automatically enabled if required (i.e. if no PSA driver provides the
236  * mechanism). You may still freely enable additional `MBEDTLS_XXX` symbols
237  * in mbedtls_config.h.
238  *
239  * If the symbol #MBEDTLS_PSA_CRYPTO_CONFIG_FILE is defined, it specifies
240  * an alternative header to include instead of include/psa/crypto_config.h.
241  *
242  * This feature is still experimental and is not ready for production since
243  * it is not completed.
244  */
245 #define MBEDTLS_PSA_CRYPTO_CONFIG
246 
247 /* \} name SECTION: mbed TLS feature support */
248 
249 /**
250  * \name SECTION: mbed TLS modules
251  *
252  * This section enables or disables entire modules in mbed TLS
253  * \{
254  */
255 
256 /**
257  * \def MBEDTLS_AES_C
258  *
259  * Enable the AES block cipher.
260  *
261  * Module:  library/aes.c
262  * Caller:  library/cipher.c
263  *          library/pem.c
264  *          library/ctr_drbg.c
265  *
266  * This module is required to support the TLS ciphersuites that use the AES
267  * cipher.
268  *
269  * PEM_PARSE uses AES for decrypting encrypted keys.
270  */
271 #define MBEDTLS_AES_C
272 
273 /**
274  * \def MBEDTLS_CIPHER_C
275  *
276  * Enable the generic cipher layer.
277  *
278  * Module:  library/cipher.c
279  *
280  * Uncomment to enable generic cipher wrappers.
281  */
282 #define MBEDTLS_CIPHER_C
283 
284 /**
285  * \def MBEDTLS_CTR_DRBG_C
286  *
287  * Enable the CTR_DRBG AES-based random generator.
288  * The CTR_DRBG generator uses AES-256 by default.
289  * To use AES-128 instead, enable MBEDTLS_CTR_DRBG_USE_128_BIT_KEY below.
290  *
291  * Module:  library/ctr_drbg.c
292  * Caller:
293  *
294  * Requires: MBEDTLS_AES_C
295  *
296  * This module provides the CTR_DRBG AES random number generator.
297  */
298 //#define MBEDTLS_CTR_DRBG_C
299 
300 /**
301  * \def MBEDTLS_ENTROPY_C
302  *
303  * Enable the platform-specific entropy code.
304  *
305  * Module:  library/entropy.c
306  * Caller:
307  *
308  * Requires: MBEDTLS_SHA512_C or MBEDTLS_SHA256_C
309  *
310  * This module provides a generic entropy pool
311  */
312 #define MBEDTLS_ENTROPY_C
313 
314 /**
315  * \def MBEDTLS_HKDF_C
316  *
317  * Enable the HKDF algorithm (RFC 5869).
318  *
319  * Module:  library/hkdf.c
320  * Caller:
321  *
322  * Requires: MBEDTLS_MD_C
323  *
324  * This module adds support for the Hashed Message Authentication Code
325  * (HMAC)-based key derivation function (HKDF).
326  */
327 //#define MBEDTLS_HKDF_C /* Used for HUK deriviation */
328 
329 /**
330  * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C
331  *
332  * Enable the buffer allocator implementation that makes use of a (stack)
333  * based buffer to 'allocate' dynamic memory. (replaces calloc() and free()
334  * calls)
335  *
336  * Module:  library/memory_buffer_alloc.c
337  *
338  * Requires: MBEDTLS_PLATFORM_C
339  *           MBEDTLS_PLATFORM_MEMORY (to use it within mbed TLS)
340  *
341  * Enable this module to enable the buffer memory allocator.
342  */
343 #define MBEDTLS_MEMORY_BUFFER_ALLOC_C
344 
345 /**
346  * \def MBEDTLS_PLATFORM_C
347  *
348  * Enable the platform abstraction layer that allows you to re-assign
349  * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit().
350  *
351  * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT
352  * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned
353  * above to be specified at runtime or compile time respectively.
354  *
355  * \note This abstraction layer must be enabled on Windows (including MSYS2)
356  * as other module rely on it for a fixed snprintf implementation.
357  *
358  * Module:  library/platform.c
359  * Caller:  Most other .c files
360  *
361  * This module enables abstraction of common (libc) functions.
362  */
363 #define MBEDTLS_PLATFORM_C
364 
365 #define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
366 #define MBEDTLS_PLATFORM_STD_MEM_HDR   <stdlib.h>
367 
368 #include <stdio.h>
369 
370 #define MBEDTLS_PLATFORM_SNPRINTF_MACRO      snprintf
371 #define MBEDTLS_PLATFORM_PRINTF_ALT
372 #define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS  EXIT_SUCCESS
373 #define MBEDTLS_PLATFORM_STD_EXIT_FAILURE  EXIT_FAILURE
374 
375 /**
376  * \def MBEDTLS_PSA_CRYPTO_C
377  *
378  * Enable the Platform Security Architecture cryptography API.
379  *
380  * Module:  library/psa_crypto.c
381  *
382  * Requires: MBEDTLS_CTR_DRBG_C, MBEDTLS_ENTROPY_C
383  *
384  */
385 #define MBEDTLS_PSA_CRYPTO_C
386 
387 /**
388  * \def MBEDTLS_PSA_CRYPTO_STORAGE_C
389  *
390  * Enable the Platform Security Architecture persistent key storage.
391  *
392  * Module:  library/psa_crypto_storage.c
393  *
394  * Requires: MBEDTLS_PSA_CRYPTO_C,
395  *           either MBEDTLS_PSA_ITS_FILE_C or a native implementation of
396  *           the PSA ITS interface
397  */
398 #define MBEDTLS_PSA_CRYPTO_STORAGE_C
399 
400 /**
401  * \def MBEDTLS_PSA_CRYPTO_SPM
402  *
403  * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is built for SPM (Secure
404  * Partition Manager) integration which separates the code into two parts: a
405  * NSPE (Non-Secure Process Environment) and an SPE (Secure Process
406  * Environment).
407  *
408  * If you enable this option, your build environment must include a header
409  * file `"crypto_spe.h"` (either in the `psa` subdirectory of the Mbed TLS
410  * header files, or in another directory on the compiler's include search
411  * path). Alternatively, your platform may customize the header
412  * `psa/crypto_platform.h`, in which case it can skip or replace the
413  * inclusion of `"crypto_spe.h"`.
414  *
415  * Module:  library/psa_crypto.c
416  * Requires: MBEDTLS_PSA_CRYPTO_C
417  *
418  */
419 #define MBEDTLS_PSA_CRYPTO_SPM
420 
421 /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
422  *
423  * Enable key identifiers that encode a key owner identifier.
424  *
425  * The owner of a key is identified by a value of type ::mbedtls_key_owner_id_t
426  * which is currently hard-coded to be int32_t.
427  *
428  * Note that this option is meant for internal use only and may be removed
429  * without notice.
430  */
431 #define MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
432 
433 /** \def MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
434  *
435  * Enable support for platform built-in keys. If you enable this feature,
436  * you must implement the function mbedtls_psa_platform_get_builtin_key().
437  * See the documentation of that function for more information.
438  *
439  * Built-in keys are typically derived from a hardware unique key or
440  * stored in a secure element.
441  *
442  * Requires: MBEDTLS_PSA_CRYPTO_C.
443  *
444  * \warning This interface is experimental and may change or be removed
445  * without notice.
446  */
447 #define MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
448 
449 /* \} name SECTION: mbed TLS modules */
450 
451 /**
452  * \name SECTION: General configuration options
453  *
454  * This section contains Mbed TLS build settings that are not associated
455  * with a particular module.
456  *
457  * \{
458  */
459 
460 /**
461  * \def MBEDTLS_CONFIG_FILE
462  *
463  * If defined, this is a header which will be included instead of
464  * `"mbedtls/mbedtls_config.h"`.
465  * This header file specifies the compile-time configuration of Mbed TLS.
466  * Unlike other configuration options, this one must be defined on the
467  * compiler command line: a definition in `mbedtls_config.h` would have
468  * no effect.
469  *
470  * This macro is expanded after an <tt>\#include</tt> directive. This is a popular but
471  * non-standard feature of the C language, so this feature is only available
472  * with compilers that perform macro expansion on an <tt>\#include</tt> line.
473  *
474  * The value of this symbol is typically a path in double quotes, either
475  * absolute or relative to a directory on the include search path.
476  */
477 //#define MBEDTLS_CONFIG_FILE "mbedtls/mbedtls_config.h"
478 
479 /**
480  * \def MBEDTLS_USER_CONFIG_FILE
481  *
482  * If defined, this is a header which will be included after
483  * `"mbedtls/mbedtls_config.h"` or #MBEDTLS_CONFIG_FILE.
484  * This allows you to modify the default configuration, including the ability
485  * to undefine options that are enabled by default.
486  *
487  * This macro is expanded after an <tt>\#include</tt> directive. This is a popular but
488  * non-standard feature of the C language, so this feature is only available
489  * with compilers that perform macro expansion on an <tt>\#include</tt> line.
490  *
491  * The value of this symbol is typically a path in double quotes, either
492  * absolute or relative to a directory on the include search path.
493  */
494 //#define MBEDTLS_USER_CONFIG_FILE "/dev/null"
495 
496 /**
497  * \def MBEDTLS_PSA_CRYPTO_CONFIG_FILE
498  *
499  * If defined, this is a header which will be included instead of
500  * `"psa/crypto_config.h"`.
501  * This header file specifies which cryptographic mechanisms are available
502  * through the PSA API when #MBEDTLS_PSA_CRYPTO_CONFIG is enabled, and
503  * is not used when #MBEDTLS_PSA_CRYPTO_CONFIG is disabled.
504  *
505  * This macro is expanded after an <tt>\#include</tt> directive. This is a popular but
506  * non-standard feature of the C language, so this feature is only available
507  * with compilers that perform macro expansion on an <tt>\#include</tt> line.
508  *
509  * The value of this symbol is typically a path in double quotes, either
510  * absolute or relative to a directory on the include search path.
511  */
512 //#define MBEDTLS_PSA_CRYPTO_CONFIG_FILE "psa/crypto_config.h"
513 
514 /**
515  * \def MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE
516  *
517  * If defined, this is a header which will be included after
518  * `"psa/crypto_config.h"` or #MBEDTLS_PSA_CRYPTO_CONFIG_FILE.
519  * This allows you to modify the default configuration, including the ability
520  * to undefine options that are enabled by default.
521  *
522  * This macro is expanded after an <tt>\#include</tt> directive. This is a popular but
523  * non-standard feature of the C language, so this feature is only available
524  * with compilers that perform macro expansion on an <tt>\#include</tt> line.
525  *
526  * The value of this symbol is typically a path in double quotes, either
527  * absolute or relative to a directory on the include search path.
528  */
529 //#define MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE "/dev/null"
530 
531 /** \} name SECTION: General configuration options */
532 
533 /**
534  * \name SECTION: Module configuration options
535  *
536  * This section allows for the setting of module specific sizes and
537  * configuration options. The default values are already present in the
538  * relevant header files and should suffice for the regular use cases.
539  *
540  * Our advice is to enable options and change their values here
541  * only if you have a good reason and know the consequences.
542  *
543  * Please check the respective header file for documentation on these
544  * parameters (to prevent duplicate documentation).
545  * \{
546  */
547 
548 /* ECP options */
549 #define MBEDTLS_ECP_FIXED_POINT_OPTIM        0 /**< Disable fixed-point speed-up */
550 
551 /* \} name SECTION: Customisation configuration options */
552 
553 #if CRYPTO_NV_SEED
554 #include "tfm_mbedcrypto_config_extra_nv_seed.h"
555 #endif /* CRYPTO_NV_SEED */
556 
557 #if !defined(CRYPTO_HW_ACCELERATOR) && defined(MBEDTLS_ENTROPY_NV_SEED)
558 #include "mbedtls_entropy_nv_seed_config.h"
559 #endif
560 
561 #ifdef CRYPTO_HW_ACCELERATOR
562 #include "mbedtls_accelerator_config.h"
563 #endif
564 
565 #endif /* PROFILE_L_MBEDTLS_CONFIG_H */
566