blob: 3234cd67210176f83a3e8fd36c72747a611102df [file] [log] [blame]
Aditya Deshpande16a62e32023-04-11 16:25:02 +01001/**
2 * \file config.h
3 *
4 * \brief Configuration options (set of defines)
5 *
6 * This set of compile-time options may be used to enable
7 * or disable features selectively, and reduce the global
8 * memory footprint.
9 */
10/*
11 * Copyright (C) 2006-2022, ARM Limited, All Rights Reserved
Dave Rodgmane3c05852023-11-03 12:21:36 +000012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Aditya Deshpande16a62e32023-04-11 16:25:02 +010013 *
14 * This file is part of mbed TLS (https://tls.mbed.org)
15 */
16
17#ifndef PROFILE_M_MBEDTLS_CONFIG_H
18#define PROFILE_M_MBEDTLS_CONFIG_H
19
Aditya Deshpande16a62e32023-04-11 16:25:02 +010020#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
21#define _CRT_SECURE_NO_DEPRECATE 1
22#endif
23
24/**
25 * \name SECTION: System support
26 *
27 * This section sets system specific settings.
28 * \{
29 */
30
31/**
32 * \def MBEDTLS_HAVE_ASM
33 *
34 * The compiler has support for asm().
35 *
36 * Requires support for asm() in compiler.
37 *
38 * Used in:
39 * library/aria.c
40 * library/timing.c
41 * include/mbedtls/bn_mul.h
42 *
43 * Required by:
44 * MBEDTLS_AESNI_C
45 * MBEDTLS_PADLOCK_C
46 *
47 * Comment to disable the use of assembly code.
48 */
49#define MBEDTLS_HAVE_ASM
50
51/**
52 * \def MBEDTLS_PLATFORM_MEMORY
53 *
54 * Enable the memory allocation layer.
55 *
56 * By default mbed TLS uses the system-provided calloc() and free().
57 * This allows different allocators (self-implemented or provided) to be
58 * provided to the platform abstraction layer.
59 *
60 * Enabling MBEDTLS_PLATFORM_MEMORY without the
61 * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide
62 * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and
63 * free() function pointer at runtime.
64 *
65 * Enabling MBEDTLS_PLATFORM_MEMORY and specifying
66 * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the
67 * alternate function at compile time.
68 *
69 * Requires: MBEDTLS_PLATFORM_C
70 *
71 * Enable this layer to allow use of alternative memory allocators.
72 */
73#define MBEDTLS_PLATFORM_MEMORY
74
75/* \} name SECTION: System support */
76
77/**
78 * \name SECTION: mbed TLS feature support
79 *
80 * This section sets support for features that are or are not needed
81 * within the modules that are enabled.
82 * \{
83 */
84
85/**
86 * \def MBEDTLS_MD2_PROCESS_ALT
87 *
88 * MBEDTLS__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use you
89 * alternate core implementation of symmetric crypto or hash function. Keep in
90 * mind that function prototypes should remain the same.
91 *
92 * This replaces only one function. The header file from mbed TLS is still
93 * used, in contrast to the MBEDTLS__MODULE_NAME__ALT flags.
94 *
95 * Example: In case you uncomment MBEDTLS_SHA256_PROCESS_ALT, mbed TLS will
96 * no longer provide the mbedtls_sha1_process() function, but it will still provide
97 * the other function (using your mbedtls_sha1_process() function) and the definition
98 * of mbedtls_sha1_context, so your implementation of mbedtls_sha1_process must be compatible
99 * with this definition.
100 *
101 * \note Because of a signature change, the core AES encryption and decryption routines are
102 * currently named mbedtls_aes_internal_encrypt and mbedtls_aes_internal_decrypt,
103 * respectively. When setting up alternative implementations, these functions should
104 * be overridden, but the wrapper functions mbedtls_aes_decrypt and mbedtls_aes_encrypt
105 * must stay untouched.
106 *
107 * \note If you use the AES_xxx_ALT macros, then is is recommended to also set
108 * MBEDTLS_AES_ROM_TABLES in order to help the linker garbage-collect the AES
109 * tables.
110 *
111 * Uncomment a macro to enable alternate implementation of the corresponding
112 * function.
113 *
114 * \warning MD2, MD4, MD5, DES and SHA-1 are considered weak and their use
115 * constitutes a security risk. If possible, we recommend avoiding
116 * dependencies on them, and considering stronger message digests
117 * and ciphers instead.
118 *
119 */
120#define MBEDTLS_AES_SETKEY_DEC_ALT
121#define MBEDTLS_AES_DECRYPT_ALT
122
123/**
124 * \def MBEDTLS_AES_ROM_TABLES
125 *
126 * Use precomputed AES tables stored in ROM.
127 *
128 * Uncomment this macro to use precomputed AES tables stored in ROM.
129 * Comment this macro to generate AES tables in RAM at runtime.
130 *
131 * Tradeoff: Using precomputed ROM tables reduces RAM usage by ~8kb
132 * (or ~2kb if \c MBEDTLS_AES_FEWER_TABLES is used) and reduces the
133 * initialization time before the first AES operation can be performed.
134 * It comes at the cost of additional ~8kb ROM use (resp. ~2kb if \c
135 * MBEDTLS_AES_FEWER_TABLES below is used), and potentially degraded
136 * performance if ROM access is slower than RAM access.
137 *
138 * This option is independent of \c MBEDTLS_AES_FEWER_TABLES.
139 *
140 */
141#define MBEDTLS_AES_ROM_TABLES
142
143/**
144 * \def MBEDTLS_AES_FEWER_TABLES
145 *
146 * Use less ROM/RAM for AES tables.
147 *
148 * Uncommenting this macro omits 75% of the AES tables from
149 * ROM / RAM (depending on the value of \c MBEDTLS_AES_ROM_TABLES)
150 * by computing their values on the fly during operations
151 * (the tables are entry-wise rotations of one another).
152 *
153 * Tradeoff: Uncommenting this reduces the RAM / ROM footprint
154 * by ~6kb but at the cost of more arithmetic operations during
155 * runtime. Specifically, one has to compare 4 accesses within
156 * different tables to 4 accesses with additional arithmetic
157 * operations within the same table. The performance gain/loss
158 * depends on the system and memory details.
159 *
160 * This option is independent of \c MBEDTLS_AES_ROM_TABLES.
161 *
162 */
163#define MBEDTLS_AES_FEWER_TABLES
164
165/**
166 * \def MBEDTLS_ECP_NIST_OPTIM
167 *
168 * Enable specific 'modulo p' routines for each NIST prime.
169 * Depending on the prime and architecture, makes operations 4 to 8 times
170 * faster on the corresponding curve.
171 *
172 * Comment this macro to disable NIST curves optimisation.
173 */
174#define MBEDTLS_ECP_NIST_OPTIM
175
176/**
177 * \def MBEDTLS_ERROR_STRERROR_DUMMY
178 *
179 * Enable a dummy error function to make use of mbedtls_strerror() in
180 * third party libraries easier when MBEDTLS_ERROR_C is disabled
181 * (no effect when MBEDTLS_ERROR_C is enabled).
182 *
183 * You can safely disable this if MBEDTLS_ERROR_C is enabled, or if you're
184 * not using mbedtls_strerror() or error_strerror() in your application.
185 *
186 * Disable if you run into name conflicts and want to really remove the
187 * mbedtls_strerror()
188 */
189#define MBEDTLS_ERROR_STRERROR_DUMMY
190
191/**
192 * \def MBEDTLS_NO_PLATFORM_ENTROPY
193 *
194 * Do not use built-in platform entropy functions.
195 * This is useful if your platform does not support
196 * standards like the /dev/urandom or Windows CryptoAPI.
197 *
198 * Uncomment this macro to disable the built-in platform entropy functions.
199 */
200#define MBEDTLS_NO_PLATFORM_ENTROPY
201
202/**
203 * \def MBEDTLS_ENTROPY_NV_SEED
204 *
205 * Enable the non-volatile (NV) seed file-based entropy source.
206 * (Also enables the NV seed read/write functions in the platform layer)
207 *
208 * This is crucial (if not required) on systems that do not have a
209 * cryptographic entropy source (in hardware or kernel) available.
210 *
211 * Requires: MBEDTLS_ENTROPY_C, MBEDTLS_PLATFORM_C
212 *
213 * \note The read/write functions that are used by the entropy source are
214 * determined in the platform layer, and can be modified at runtime and/or
215 * compile-time depending on the flags (MBEDTLS_PLATFORM_NV_SEED_*) used.
216 *
217 * \note If you use the default implementation functions that read a seedfile
218 * with regular fopen(), please make sure you make a seedfile with the
219 * proper name (defined in MBEDTLS_PLATFORM_STD_NV_SEED_FILE) and at
220 * least MBEDTLS_ENTROPY_BLOCK_SIZE bytes in size that can be read from
221 * and written to or you will get an entropy source error! The default
222 * implementation will only use the first MBEDTLS_ENTROPY_BLOCK_SIZE
223 * bytes from the file.
224 *
225 * \note The entropy collector will write to the seed file before entropy is
226 * given to an external source, to update it.
227 */
Aditya Deshpande2f1ae5a2023-04-11 16:43:08 +0100228// This macro is enabled in TFM Medium but is disabled here because it is
229// incompatible with baremetal builds in Mbed TLS.
230//#define MBEDTLS_ENTROPY_NV_SEED
Aditya Deshpande16a62e32023-04-11 16:25:02 +0100231
232/* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
233 *
234 * Enable key identifiers that encode a key owner identifier.
235 *
236 * This is only meaningful when building the library as part of a
237 * multi-client service. When you activate this option, you must provide an
238 * implementation of the type mbedtls_key_owner_id_t and a translation from
239 * mbedtls_svc_key_id_t to file name in all the storage backends that you
240 * you wish to support.
241 *
Aditya Deshpande2f1ae5a2023-04-11 16:43:08 +0100242 * Note that while this define has been removed from TF-M's copy of this config
243 * file, TF-M still passes this option to Mbed TLS during the build via CMake.
244 * Therefore we keep it in our copy. See discussion on PR #7426 for more info.
245 *
Aditya Deshpande16a62e32023-04-11 16:25:02 +0100246 */
247#define MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
248
249/**
250 * \def MBEDTLS_PSA_CRYPTO_SPM
251 *
252 * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is built for SPM (Secure
253 * Partition Manager) integration which separates the code into two parts: a
254 * NSPE (Non-Secure Process Environment) and an SPE (Secure Process
255 * Environment).
256 *
257 * Module: library/psa_crypto.c
258 * Requires: MBEDTLS_PSA_CRYPTO_C
259 *
260 */
261#define MBEDTLS_PSA_CRYPTO_SPM
262
263/**
264 * \def MBEDTLS_SHA256_SMALLER
265 *
266 * Enable an implementation of SHA-256 that has lower ROM footprint but also
267 * lower performance.
268 *
269 * The default implementation is meant to be a reasonnable compromise between
270 * performance and size. This version optimizes more aggressively for size at
271 * the expense of performance. Eg on Cortex-M4 it reduces the size of
272 * mbedtls_sha256_process() from ~2KB to ~0.5KB for a performance hit of about
273 * 30%.
274 *
275 * Uncomment to enable the smaller implementation of SHA256.
276 */
277#define MBEDTLS_SHA256_SMALLER
278
279/**
280 * \def MBEDTLS_PSA_CRYPTO_CONFIG
281 *
282 * This setting allows support for cryptographic mechanisms through the PSA
283 * API to be configured separately from support through the mbedtls API.
284 *
285 * When this option is disabled, the PSA API exposes the cryptographic
286 * mechanisms that can be implemented on top of the `mbedtls_xxx` API
287 * configured with `MBEDTLS_XXX` symbols.
288 *
289 * When this option is enabled, the PSA API exposes the cryptographic
290 * mechanisms requested by the `PSA_WANT_XXX` symbols defined in
291 * include/psa/crypto_config.h. The corresponding `MBEDTLS_XXX` settings are
292 * automatically enabled if required (i.e. if no PSA driver provides the
293 * mechanism). You may still freely enable additional `MBEDTLS_XXX` symbols
294 * in mbedtls_config.h.
295 *
296 * If the symbol #MBEDTLS_PSA_CRYPTO_CONFIG_FILE is defined, it specifies
297 * an alternative header to include instead of include/psa/crypto_config.h.
298 *
299 * This feature is still experimental and is not ready for production since
300 * it is not completed.
301 */
302#define MBEDTLS_PSA_CRYPTO_CONFIG
303
304/* \} name SECTION: mbed TLS feature support */
305
306/**
307 * \name SECTION: mbed TLS modules
308 *
309 * This section enables or disables entire modules in mbed TLS
310 * \{
311 */
312
313/**
314 * \def MBEDTLS_AES_C
315 *
316 * Enable the AES block cipher.
317 *
318 * Module: library/aes.c
319 * Caller: library/cipher.c
320 * library/pem.c
321 * library/ctr_drbg.c
322 *
323 * This module is required to support the TLS ciphersuites that use the AES
324 * cipher.
325 *
326 * PEM_PARSE uses AES for decrypting encrypted keys.
327 */
328#define MBEDTLS_AES_C
329
330/**
331 * \def MBEDTLS_CIPHER_C
332 *
333 * Enable the generic cipher layer.
334 *
335 * Module: library/cipher.c
336 *
337 * Uncomment to enable generic cipher wrappers.
338 */
339#define MBEDTLS_CIPHER_C
340
341/**
342 * \def MBEDTLS_CTR_DRBG_C
343 *
344 * Enable the CTR_DRBG AES-based random generator.
345 * The CTR_DRBG generator uses AES-256 by default.
346 * To use AES-128 instead, enable MBEDTLS_CTR_DRBG_USE_128_BIT_KEY below.
347 *
348 * Module: library/ctr_drbg.c
349 * Caller:
350 *
351 * Requires: MBEDTLS_AES_C
352 *
353 * This module provides the CTR_DRBG AES random number generator.
354 */
355#define MBEDTLS_CTR_DRBG_C
356
357/**
358 * \def MBEDTLS_ENTROPY_C
359 *
360 * Enable the platform-specific entropy code.
361 *
362 * Module: library/entropy.c
363 * Caller:
364 *
365 * Requires: MBEDTLS_SHA512_C or MBEDTLS_SHA256_C
366 *
367 * This module provides a generic entropy pool
368 */
369#define MBEDTLS_ENTROPY_C
370
371/**
372 * \def MBEDTLS_ERROR_C
373 *
374 * Enable error code to error string conversion.
375 *
376 * Module: library/error.c
377 * Caller:
378 *
379 * This module enables mbedtls_strerror().
380 */
381#define MBEDTLS_ERROR_C
382
383/**
384 * \def MBEDTLS_HKDF_C
385 *
386 * Enable the HKDF algorithm (RFC 5869).
387 *
388 * Module: library/hkdf.c
389 * Caller:
390 *
391 * Requires: MBEDTLS_MD_C
392 *
393 * This module adds support for the Hashed Message Authentication Code
394 * (HMAC)-based key derivation function (HKDF).
395 */
396#define MBEDTLS_HKDF_C /* Used for HUK deriviation */
397
398/**
Dave Rodgman84e8f1d2023-09-22 17:40:18 +0100399 * \def MBEDTLS_MD_C
400 *
401 * Enable the generic layer for message digest (hashing) and HMAC.
402 *
403 * Requires: one of: MBEDTLS_MD5_C, MBEDTLS_RIPEMD160_C, MBEDTLS_SHA1_C,
404 * MBEDTLS_SHA224_C, MBEDTLS_SHA256_C, MBEDTLS_SHA384_C,
405 * MBEDTLS_SHA512_C, or MBEDTLS_PSA_CRYPTO_C with at least
406 * one hash.
407 * Module: library/md.c
408 * Caller: library/constant_time.c
409 * library/ecdsa.c
410 * library/ecjpake.c
411 * library/hkdf.c
412 * library/hmac_drbg.c
413 * library/pk.c
414 * library/pkcs5.c
415 * library/pkcs12.c
416 * library/psa_crypto_ecp.c
417 * library/psa_crypto_rsa.c
418 * library/rsa.c
419 * library/ssl_cookie.c
420 * library/ssl_msg.c
421 * library/ssl_tls.c
422 * library/x509.c
423 * library/x509_crt.c
424 * library/x509write_crt.c
425 * library/x509write_csr.c
426 *
427 * Uncomment to enable generic message digest wrappers.
428 */
429#define MBEDTLS_MD_C
430
431/**
Aditya Deshpande16a62e32023-04-11 16:25:02 +0100432 * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C
433 *
434 * Enable the buffer allocator implementation that makes use of a (stack)
435 * based buffer to 'allocate' dynamic memory. (replaces calloc() and free()
436 * calls)
437 *
438 * Module: library/memory_buffer_alloc.c
439 *
440 * Requires: MBEDTLS_PLATFORM_C
441 * MBEDTLS_PLATFORM_MEMORY (to use it within mbed TLS)
442 *
443 * Enable this module to enable the buffer memory allocator.
444 */
445#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
446
447/**
Aditya Deshpande16a62e32023-04-11 16:25:02 +0100448 * \def MBEDTLS_PLATFORM_C
449 *
450 * Enable the platform abstraction layer that allows you to re-assign
451 * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit().
452 *
453 * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT
454 * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned
455 * above to be specified at runtime or compile time respectively.
456 *
457 * \note This abstraction layer must be enabled on Windows (including MSYS2)
458 * as other module rely on it for a fixed snprintf implementation.
459 *
460 * Module: library/platform.c
461 * Caller: Most other .c files
462 *
463 * This module enables abstraction of common (libc) functions.
464 */
465#define MBEDTLS_PLATFORM_C
466
Aditya Deshpande16a62e32023-04-11 16:25:02 +0100467
468/**
469 * \def MBEDTLS_PSA_CRYPTO_C
470 *
471 * Enable the Platform Security Architecture cryptography API.
472 *
473 * Module: library/psa_crypto.c
474 *
475 * Requires: MBEDTLS_CTR_DRBG_C, MBEDTLS_ENTROPY_C
476 *
477 */
478#define MBEDTLS_PSA_CRYPTO_C
479
480/**
481 * \def MBEDTLS_PSA_CRYPTO_STORAGE_C
482 *
483 * Enable the Platform Security Architecture persistent key storage.
484 *
485 * Module: library/psa_crypto_storage.c
486 *
487 * Requires: MBEDTLS_PSA_CRYPTO_C,
488 * either MBEDTLS_PSA_ITS_FILE_C or a native implementation of
489 * the PSA ITS interface
490 */
Aditya Deshpande2f1ae5a2023-04-11 16:43:08 +0100491// This macro is enabled in TFM Medium but is disabled here because it is
492// incompatible with baremetal builds in Mbed TLS.
493//#define MBEDTLS_PSA_CRYPTO_STORAGE_C
Aditya Deshpande16a62e32023-04-11 16:25:02 +0100494
495/* \} name SECTION: mbed TLS modules */
496
497/**
498 * \name SECTION: General configuration options
499 *
500 * This section contains Mbed TLS build settings that are not associated
501 * with a particular module.
502 *
503 * \{
504 */
505
506/**
507 * \def MBEDTLS_CONFIG_FILE
508 *
509 * If defined, this is a header which will be included instead of
510 * `"mbedtls/mbedtls_config.h"`.
511 * This header file specifies the compile-time configuration of Mbed TLS.
512 * Unlike other configuration options, this one must be defined on the
513 * compiler command line: a definition in `mbedtls_config.h` would have
514 * no effect.
515 *
516 * This macro is expanded after an <tt>\#include</tt> directive. This is a popular but
517 * non-standard feature of the C language, so this feature is only available
518 * with compilers that perform macro expansion on an <tt>\#include</tt> line.
519 *
520 * The value of this symbol is typically a path in double quotes, either
521 * absolute or relative to a directory on the include search path.
522 */
523//#define MBEDTLS_CONFIG_FILE "mbedtls/mbedtls_config.h"
524
525/**
526 * \def MBEDTLS_USER_CONFIG_FILE
527 *
528 * If defined, this is a header which will be included after
529 * `"mbedtls/mbedtls_config.h"` or #MBEDTLS_CONFIG_FILE.
530 * This allows you to modify the default configuration, including the ability
531 * to undefine options that are enabled by default.
532 *
533 * This macro is expanded after an <tt>\#include</tt> directive. This is a popular but
534 * non-standard feature of the C language, so this feature is only available
535 * with compilers that perform macro expansion on an <tt>\#include</tt> line.
536 *
537 * The value of this symbol is typically a path in double quotes, either
538 * absolute or relative to a directory on the include search path.
539 */
540//#define MBEDTLS_USER_CONFIG_FILE "/dev/null"
541
542/**
543 * \def MBEDTLS_PSA_CRYPTO_CONFIG_FILE
544 *
545 * If defined, this is a header which will be included instead of
546 * `"psa/crypto_config.h"`.
547 * This header file specifies which cryptographic mechanisms are available
548 * through the PSA API when #MBEDTLS_PSA_CRYPTO_CONFIG is enabled, and
549 * is not used when #MBEDTLS_PSA_CRYPTO_CONFIG is disabled.
550 *
551 * This macro is expanded after an <tt>\#include</tt> directive. This is a popular but
552 * non-standard feature of the C language, so this feature is only available
553 * with compilers that perform macro expansion on an <tt>\#include</tt> line.
554 *
555 * The value of this symbol is typically a path in double quotes, either
556 * absolute or relative to a directory on the include search path.
557 */
558//#define MBEDTLS_PSA_CRYPTO_CONFIG_FILE "psa/crypto_config.h"
559
560/**
561 * \def MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE
562 *
563 * If defined, this is a header which will be included after
564 * `"psa/crypto_config.h"` or #MBEDTLS_PSA_CRYPTO_CONFIG_FILE.
565 * This allows you to modify the default configuration, including the ability
566 * to undefine options that are enabled by default.
567 *
568 * This macro is expanded after an <tt>\#include</tt> directive. This is a popular but
569 * non-standard feature of the C language, so this feature is only available
570 * with compilers that perform macro expansion on an <tt>\#include</tt> line.
571 *
572 * The value of this symbol is typically a path in double quotes, either
573 * absolute or relative to a directory on the include search path.
574 */
575//#define MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE "/dev/null"
576
577/** \} name SECTION: General configuration options */
578
579/**
580 * \name SECTION: Module configuration options
581 *
582 * This section allows for the setting of module specific sizes and
583 * configuration options. The default values are already present in the
584 * relevant header files and should suffice for the regular use cases.
585 *
586 * Our advice is to enable options and change their values here
587 * only if you have a good reason and know the consequences.
588 *
589 * Please check the respective header file for documentation on these
590 * parameters (to prevent duplicate documentation).
591 * \{
592 */
593
594/* ECP options */
595#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Disable fixed-point speed-up */
596
597/* \} name SECTION: Customisation configuration options */
598
599#if CRYPTO_NV_SEED
600#include "tfm_mbedcrypto_config_extra_nv_seed.h"
601#endif /* CRYPTO_NV_SEED */
602
603#if !defined(CRYPTO_HW_ACCELERATOR) && defined(MBEDTLS_ENTROPY_NV_SEED)
604#include "mbedtls_entropy_nv_seed_config.h"
605#endif
606
607#ifdef CRYPTO_HW_ACCELERATOR
608#include "mbedtls_accelerator_config.h"
609#endif
610
611#endif /* PROFILE_M_MBEDTLS_CONFIG_H */