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