Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 1 | /* |
Jimmy Brisson | 640d991 | 2024-04-10 10:20:13 -0500 | [diff] [blame] | 2 | * Copyright (c) 2023-2024, Arm Limited. All rights reserved. |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 5 | */ |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 6 | |
| 7 | /** |
| 8 | * This set of compile-time options may be used to enable |
| 9 | * or disable features selectively, and reduce the global |
| 10 | * memory footprint. |
| 11 | */ |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 12 | |
| 13 | /* |
Ryan Everett | 118fd33 | 2024-12-09 16:00:38 +0000 | [diff] [blame] | 14 | * This file is compatible with versions >= 3.6.2 |
| 15 | */ |
| 16 | #define MBEDTLS_CONFIG_VERSION 0x03060200 |
| 17 | |
| 18 | /* |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 19 | * Key algorithms currently supported on mbed TLS libraries |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 20 | */ |
Qixiang Xu | 1c2aef1 | 2017-08-24 15:12:20 +0800 | [diff] [blame] | 21 | #define TF_MBEDTLS_RSA 1 |
| 22 | #define TF_MBEDTLS_ECDSA 2 |
Qixiang Xu | aa05eea | 2017-08-24 15:26:39 +0800 | [diff] [blame] | 23 | #define TF_MBEDTLS_RSA_AND_ECDSA 3 |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 24 | |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 25 | #define TF_MBEDTLS_USE_RSA (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA \ |
| 26 | || TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA) |
| 27 | #define TF_MBEDTLS_USE_ECDSA (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA \ |
| 28 | || TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA) |
| 29 | |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 30 | /* |
Qixiang Xu | 1a1f291 | 2017-11-09 13:56:29 +0800 | [diff] [blame] | 31 | * Hash algorithms currently supported on mbed TLS libraries |
| 32 | */ |
| 33 | #define TF_MBEDTLS_SHA256 1 |
| 34 | #define TF_MBEDTLS_SHA384 2 |
| 35 | #define TF_MBEDTLS_SHA512 3 |
| 36 | |
| 37 | /* |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 38 | * Configuration file to build mbed TLS with the required features for |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 39 | * Trusted Boot |
| 40 | */ |
| 41 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 42 | #define MBEDTLS_PLATFORM_MEMORY |
| 43 | #define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS |
Antonio Nino Diaz | 6b90f5e | 2017-05-19 11:37:22 +0100 | [diff] [blame] | 44 | /* Prevent mbed TLS from using snprintf so that it can use tf_snprintf. */ |
| 45 | #define MBEDTLS_PLATFORM_SNPRINTF_ALT |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 46 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 47 | #define MBEDTLS_PKCS1_V21 |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 48 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 49 | #define MBEDTLS_ASN1_PARSE_C |
| 50 | #define MBEDTLS_ASN1_WRITE_C |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 51 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 52 | #define MBEDTLS_BASE64_C |
| 53 | #define MBEDTLS_BIGNUM_C |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 54 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 55 | #define MBEDTLS_ERROR_C |
| 56 | #define MBEDTLS_MD_C |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 57 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 58 | #define MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 59 | #define MBEDTLS_OID_C |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 60 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 61 | #define MBEDTLS_PK_C |
| 62 | #define MBEDTLS_PK_PARSE_C |
| 63 | #define MBEDTLS_PK_WRITE_C |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 64 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 65 | #define MBEDTLS_PLATFORM_C |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 66 | |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 67 | #if TF_MBEDTLS_USE_ECDSA |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 68 | #define MBEDTLS_ECDSA_C |
| 69 | #define MBEDTLS_ECP_C |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 70 | #if TF_MBEDTLS_KEY_SIZE == 384 |
| 71 | #define MBEDTLS_ECP_DP_SECP384R1_ENABLED |
| 72 | #else |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 73 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 74 | #endif |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 75 | #endif |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 76 | #if TF_MBEDTLS_USE_RSA |
Qixiang Xu | aa05eea | 2017-08-24 15:26:39 +0800 | [diff] [blame] | 77 | #define MBEDTLS_RSA_C |
| 78 | #define MBEDTLS_X509_RSASSA_PSS_SUPPORT |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 79 | #endif |
| 80 | |
Jimmy Brisson | 9ce5eb4 | 2024-07-11 10:10:55 -0500 | [diff] [blame] | 81 | /* Enable hash algorithms based on TBB or Measured Boot */ |
| 82 | #if (TF_MBEDTLS_HASH_ALG_ID == TF_MBEDTLS_SHA256) || defined(TF_MBEDTLS_MBOOT_USE_SHA256) |
| 83 | #define MBEDTLS_SHA256_C |
Qixiang Xu | 1a1f291 | 2017-11-09 13:56:29 +0800 | [diff] [blame] | 84 | #endif |
Jimmy Brisson | 9ce5eb4 | 2024-07-11 10:10:55 -0500 | [diff] [blame] | 85 | |
| 86 | #if (TF_MBEDTLS_HASH_ALG_ID == TF_MBEDTLS_SHA384) || defined(TF_MBEDTLS_MBOOT_USE_SHA384) |
| 87 | #define MBEDTLS_SHA384_C |
| 88 | #endif |
| 89 | |
| 90 | #if (TF_MBEDTLS_HASH_ALG_ID == TF_MBEDTLS_SHA512) || defined(TF_MBEDTLS_MBOOT_USE_SHA512) |
| 91 | #define MBEDTLS_SHA512_C |
Manish V Badarkhe | e112a5a | 2021-10-06 23:41:50 +0100 | [diff] [blame] | 92 | #endif |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 93 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 94 | #define MBEDTLS_VERSION_C |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 95 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 96 | #define MBEDTLS_X509_USE_C |
| 97 | #define MBEDTLS_X509_CRT_PARSE_C |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 98 | |
Sumit Garg | 392e4df | 2019-11-15 10:43:00 +0530 | [diff] [blame] | 99 | #if TF_MBEDTLS_USE_AES_GCM |
| 100 | #define MBEDTLS_AES_C |
| 101 | #define MBEDTLS_CIPHER_C |
| 102 | #define MBEDTLS_GCM_C |
| 103 | #endif |
| 104 | |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 105 | /* MPI / BIGNUM options */ |
Jimmy Brisson | 9ce5eb4 | 2024-07-11 10:10:55 -0500 | [diff] [blame] | 106 | |
| 107 | /* Note: Lower numbers trade longer execution time for less RAM allocation */ |
| 108 | #define MBEDTLS_MPI_WINDOW_SIZE 1 |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 109 | |
| 110 | #if TF_MBEDTLS_USE_RSA |
| 111 | #if TF_MBEDTLS_KEY_SIZE <= 2048 |
| 112 | #define MBEDTLS_MPI_MAX_SIZE 256 |
| 113 | #else |
| 114 | #define MBEDTLS_MPI_MAX_SIZE 512 |
| 115 | #endif |
| 116 | #else |
| 117 | #define MBEDTLS_MPI_MAX_SIZE 256 |
| 118 | #endif |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 119 | |
| 120 | /* Memory buffer allocator options */ |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 121 | #define MBEDTLS_MEMORY_ALIGN_MULTIPLE 8 |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 122 | |
Alexei Fedorov | 42cb1aa | 2020-09-21 12:23:54 +0100 | [diff] [blame] | 123 | /* |
| 124 | * Prevent the use of 128-bit division which |
| 125 | * creates dependency on external libraries. |
| 126 | */ |
| 127 | #define MBEDTLS_NO_UDBL_DIVISION |
| 128 | |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 129 | #ifndef __ASSEMBLER__ |
Qixiang Xu | de431b1 | 2017-10-13 09:23:42 +0800 | [diff] [blame] | 130 | /* System headers required to build mbed TLS with the current configuration */ |
| 131 | #include <stdlib.h> |
Qixiang Xu | de431b1 | 2017-10-13 09:23:42 +0800 | [diff] [blame] | 132 | #endif |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 133 | |
John Tsichritzis | 30f8964 | 2018-06-07 16:31:34 +0100 | [diff] [blame] | 134 | /* |
| 135 | * Determine Mbed TLS heap size |
| 136 | * 13312 = 13*1024 |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 137 | * 11264 = 11*1024 |
| 138 | * 7168 = 7*1024 |
John Tsichritzis | 30f8964 | 2018-06-07 16:31:34 +0100 | [diff] [blame] | 139 | */ |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 140 | #if TF_MBEDTLS_USE_ECDSA |
John Tsichritzis | 30f8964 | 2018-06-07 16:31:34 +0100 | [diff] [blame] | 141 | #define TF_MBEDTLS_HEAP_SIZE U(13312) |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 142 | #elif TF_MBEDTLS_USE_RSA |
| 143 | #if TF_MBEDTLS_KEY_SIZE <= 2048 |
John Tsichritzis | 30f8964 | 2018-06-07 16:31:34 +0100 | [diff] [blame] | 144 | #define TF_MBEDTLS_HEAP_SIZE U(7168) |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 145 | #else |
| 146 | #define TF_MBEDTLS_HEAP_SIZE U(11264) |
| 147 | #endif |
John Tsichritzis | 30f8964 | 2018-06-07 16:31:34 +0100 | [diff] [blame] | 148 | #endif |
| 149 | |
Sandrine Bailleux | a814357 | 2022-06-15 15:31:52 +0200 | [diff] [blame] | 150 | /* |
| 151 | * Warn if errors from certain functions are ignored. |
| 152 | * |
| 153 | * The warnings are always enabled (where supported) for critical functions |
| 154 | * where ignoring the return value is almost always a bug. This macro extends |
| 155 | * the warnings to more functions. |
| 156 | */ |
| 157 | #define MBEDTLS_CHECK_RETURN_WARNING |