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