blob: 01e261a96f7a5210fcc13425c6cda944669ded82 [file] [log] [blame]
Juan Castillo7d37aa12015-04-02 15:44:20 +01001/*
laurenw-arm78da42a2022-05-31 16:39:09 -05002 * Copyright (c) 2015-2022, Arm Limited. All rights reserved.
Juan Castillo7d37aa12015-04-02 15:44:20 +01003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo7d37aa12015-04-02 15:44:20 +01005 */
Antonio Nino Diazc3cf06f2018-11-08 10:20:19 +00006#ifndef MBEDTLS_CONFIG_H
7#define MBEDTLS_CONFIG_H
Juan Castillo7d37aa12015-04-02 15:44:20 +01008
9/*
Juan Castillo649dbf62015-11-05 09:24:53 +000010 * Key algorithms currently supported on mbed TLS libraries
Juan Castillo7d37aa12015-04-02 15:44:20 +010011 */
Qixiang Xu9db9c652017-08-24 15:12:20 +080012#define TF_MBEDTLS_RSA 1
13#define TF_MBEDTLS_ECDSA 2
Qixiang Xudcbf3932017-08-24 15:26:39 +080014#define TF_MBEDTLS_RSA_AND_ECDSA 3
Juan Castillo7d37aa12015-04-02 15:44:20 +010015
Justin Chadwellaacff742019-07-29 17:13:10 +010016#define TF_MBEDTLS_USE_RSA (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA \
17 || TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA)
18#define TF_MBEDTLS_USE_ECDSA (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA \
19 || TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA)
20
Juan Castillo7d37aa12015-04-02 15:44:20 +010021/*
Qixiang Xu9a3088a2017-11-09 13:56:29 +080022 * Hash algorithms currently supported on mbed TLS libraries
23 */
24#define TF_MBEDTLS_SHA256 1
25#define TF_MBEDTLS_SHA384 2
26#define TF_MBEDTLS_SHA512 3
27
28/*
Juan Castillo649dbf62015-11-05 09:24:53 +000029 * Configuration file to build mbed TLS with the required features for
Juan Castillo7d37aa12015-04-02 15:44:20 +010030 * Trusted Boot
31 */
32
Juan Castillo649dbf62015-11-05 09:24:53 +000033#define MBEDTLS_PLATFORM_MEMORY
34#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Antonio Nino Diazab1794f2017-05-19 11:37:22 +010035/* Prevent mbed TLS from using snprintf so that it can use tf_snprintf. */
36#define MBEDTLS_PLATFORM_SNPRINTF_ALT
Juan Castillo7d37aa12015-04-02 15:44:20 +010037
Juan Castillo649dbf62015-11-05 09:24:53 +000038#define MBEDTLS_PKCS1_V21
Juan Castillo7d37aa12015-04-02 15:44:20 +010039
Juan Castillo649dbf62015-11-05 09:24:53 +000040#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
41#define MBEDTLS_X509_CHECK_KEY_USAGE
42#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
Juan Castillo7d37aa12015-04-02 15:44:20 +010043
Juan Castillo649dbf62015-11-05 09:24:53 +000044#define MBEDTLS_ASN1_PARSE_C
45#define MBEDTLS_ASN1_WRITE_C
Juan Castillo7d37aa12015-04-02 15:44:20 +010046
Juan Castillo649dbf62015-11-05 09:24:53 +000047#define MBEDTLS_BASE64_C
48#define MBEDTLS_BIGNUM_C
Juan Castillo7d37aa12015-04-02 15:44:20 +010049
Juan Castillo649dbf62015-11-05 09:24:53 +000050#define MBEDTLS_ERROR_C
51#define MBEDTLS_MD_C
Juan Castillo7d37aa12015-04-02 15:44:20 +010052
Juan Castillo649dbf62015-11-05 09:24:53 +000053#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
54#define MBEDTLS_OID_C
Juan Castillo7d37aa12015-04-02 15:44:20 +010055
Juan Castillo649dbf62015-11-05 09:24:53 +000056#define MBEDTLS_PK_C
57#define MBEDTLS_PK_PARSE_C
58#define MBEDTLS_PK_WRITE_C
Juan Castillo7d37aa12015-04-02 15:44:20 +010059
Juan Castillo649dbf62015-11-05 09:24:53 +000060#define MBEDTLS_PLATFORM_C
Juan Castillo7d37aa12015-04-02 15:44:20 +010061
Justin Chadwellaacff742019-07-29 17:13:10 +010062#if TF_MBEDTLS_USE_ECDSA
Juan Castillo649dbf62015-11-05 09:24:53 +000063#define MBEDTLS_ECDSA_C
64#define MBEDTLS_ECP_C
65#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
Alexei Fedorovea14b512020-09-21 12:23:54 +010066#define MBEDTLS_ECP_NO_INTERNAL_RNG
Justin Chadwellaacff742019-07-29 17:13:10 +010067#endif
68#if TF_MBEDTLS_USE_RSA
Juan Castillo649dbf62015-11-05 09:24:53 +000069#define MBEDTLS_RSA_C
Qixiang Xu9db9c652017-08-24 15:12:20 +080070#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
Juan Castillo7d37aa12015-04-02 15:44:20 +010071#endif
72
Juan Castillo649dbf62015-11-05 09:24:53 +000073#define MBEDTLS_SHA256_C
Manish V Badarkhe14db9632021-10-06 23:41:50 +010074
75/*
76 * If either Trusted Boot or Measured Boot require a stronger algorithm than
77 * SHA-256, pull in SHA-512 support.
78 */
79#if (TF_MBEDTLS_HASH_ALG_ID != TF_MBEDTLS_SHA256) /* TBB hash algo */
80#define MBEDTLS_SHA512_C
81#else
82 /* TBB uses SHA-256, what about measured boot? */
laurenw-arm78da42a2022-05-31 16:39:09 -050083#if defined(TF_MBEDTLS_MBOOT_USE_SHA512)
Qixiang Xu9a3088a2017-11-09 13:56:29 +080084#define MBEDTLS_SHA512_C
85#endif
Manish V Badarkhe14db9632021-10-06 23:41:50 +010086#endif
Juan Castillo7d37aa12015-04-02 15:44:20 +010087
Juan Castillo649dbf62015-11-05 09:24:53 +000088#define MBEDTLS_VERSION_C
Juan Castillo7d37aa12015-04-02 15:44:20 +010089
Juan Castillo649dbf62015-11-05 09:24:53 +000090#define MBEDTLS_X509_USE_C
91#define MBEDTLS_X509_CRT_PARSE_C
Juan Castillo7d37aa12015-04-02 15:44:20 +010092
Sumit Garg7cda17b2019-11-15 10:43:00 +053093#if TF_MBEDTLS_USE_AES_GCM
94#define MBEDTLS_AES_C
95#define MBEDTLS_CIPHER_C
96#define MBEDTLS_GCM_C
97#endif
98
Juan Castillo7d37aa12015-04-02 15:44:20 +010099/* MPI / BIGNUM options */
Justin Chadwellaacff742019-07-29 17:13:10 +0100100#define MBEDTLS_MPI_WINDOW_SIZE 2
101
102#if TF_MBEDTLS_USE_RSA
103#if TF_MBEDTLS_KEY_SIZE <= 2048
104#define MBEDTLS_MPI_MAX_SIZE 256
105#else
106#define MBEDTLS_MPI_MAX_SIZE 512
107#endif
108#else
109#define MBEDTLS_MPI_MAX_SIZE 256
110#endif
Juan Castillo7d37aa12015-04-02 15:44:20 +0100111
112/* Memory buffer allocator options */
Justin Chadwellaacff742019-07-29 17:13:10 +0100113#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 8
Juan Castillo7d37aa12015-04-02 15:44:20 +0100114
Alexei Fedorovea14b512020-09-21 12:23:54 +0100115/*
116 * Prevent the use of 128-bit division which
117 * creates dependency on external libraries.
118 */
119#define MBEDTLS_NO_UDBL_DIVISION
120
Julius Wernerd5dfdeb2019-07-09 13:49:11 -0700121#ifndef __ASSEMBLER__
Qixiang Xu9b1eae92017-10-13 09:23:42 +0800122/* System headers required to build mbed TLS with the current configuration */
123#include <stdlib.h>
Masahiro Yamada948a0c02019-09-04 14:09:07 +0900124#include <mbedtls/check_config.h>
Qixiang Xu9b1eae92017-10-13 09:23:42 +0800125#endif
Juan Castillo7d37aa12015-04-02 15:44:20 +0100126
John Tsichritzis6d01a462018-06-07 16:31:34 +0100127/*
128 * Determine Mbed TLS heap size
129 * 13312 = 13*1024
Justin Chadwellaacff742019-07-29 17:13:10 +0100130 * 11264 = 11*1024
131 * 7168 = 7*1024
John Tsichritzis6d01a462018-06-07 16:31:34 +0100132 */
Justin Chadwellaacff742019-07-29 17:13:10 +0100133#if TF_MBEDTLS_USE_ECDSA
John Tsichritzis6d01a462018-06-07 16:31:34 +0100134#define TF_MBEDTLS_HEAP_SIZE U(13312)
Justin Chadwellaacff742019-07-29 17:13:10 +0100135#elif TF_MBEDTLS_USE_RSA
136#if TF_MBEDTLS_KEY_SIZE <= 2048
John Tsichritzis6d01a462018-06-07 16:31:34 +0100137#define TF_MBEDTLS_HEAP_SIZE U(7168)
Justin Chadwellaacff742019-07-29 17:13:10 +0100138#else
139#define TF_MBEDTLS_HEAP_SIZE U(11264)
140#endif
John Tsichritzis6d01a462018-06-07 16:31:34 +0100141#endif
142
Sandrine Bailleuxa4e485d2022-06-15 15:31:52 +0200143/*
144 * Warn if errors from certain functions are ignored.
145 *
146 * The warnings are always enabled (where supported) for critical functions
147 * where ignoring the return value is almost always a bug. This macro extends
148 * the warnings to more functions.
149 */
150#define MBEDTLS_CHECK_RETURN_WARNING
151
Antonio Nino Diazc3cf06f2018-11-08 10:20:19 +0000152#endif /* MBEDTLS_CONFIG_H */