blob: ba936a3c814160f9f93dc8ce41957e7f8bc9b29f [file] [log] [blame]
Juan Castilloa57a4d52015-04-02 15:44:20 +01001/*
Govindraj Rajadee8b6f2023-01-12 15:34:12 +00002 * Copyright (c) 2023, Arm Limited. All rights reserved.
Juan Castilloa57a4d52015-04-02 15:44:20 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castilloa57a4d52015-04-02 15:44:20 +01005 */
Govindraj Rajadee8b6f2023-01-12 15:34:12 +00006
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 Castilloa57a4d52015-04-02 15:44:20 +010012
13/*
Juan Castillobae6b2a2015-11-05 09:24:53 +000014 * Key algorithms currently supported on mbed TLS libraries
Juan Castilloa57a4d52015-04-02 15:44:20 +010015 */
Qixiang Xu1c2aef12017-08-24 15:12:20 +080016#define TF_MBEDTLS_RSA 1
17#define TF_MBEDTLS_ECDSA 2
Qixiang Xuaa05eea2017-08-24 15:26:39 +080018#define TF_MBEDTLS_RSA_AND_ECDSA 3
Juan Castilloa57a4d52015-04-02 15:44:20 +010019
Justin Chadwellf9b32c12019-07-29 17:13:10 +010020#define TF_MBEDTLS_USE_RSA (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA \
21 || TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA)
22#define TF_MBEDTLS_USE_ECDSA (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA \
23 || TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA)
24
Juan Castilloa57a4d52015-04-02 15:44:20 +010025/*
Qixiang Xu1a1f2912017-11-09 13:56:29 +080026 * Hash algorithms currently supported on mbed TLS libraries
27 */
28#define TF_MBEDTLS_SHA256 1
29#define TF_MBEDTLS_SHA384 2
30#define TF_MBEDTLS_SHA512 3
31
32/*
Juan Castillobae6b2a2015-11-05 09:24:53 +000033 * Configuration file to build mbed TLS with the required features for
Juan Castilloa57a4d52015-04-02 15:44:20 +010034 * Trusted Boot
35 */
36
Juan Castillobae6b2a2015-11-05 09:24:53 +000037#define MBEDTLS_PLATFORM_MEMORY
38#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Antonio Nino Diaz6b90f5e2017-05-19 11:37:22 +010039/* Prevent mbed TLS from using snprintf so that it can use tf_snprintf. */
40#define MBEDTLS_PLATFORM_SNPRINTF_ALT
Juan Castilloa57a4d52015-04-02 15:44:20 +010041
Juan Castillobae6b2a2015-11-05 09:24:53 +000042#define MBEDTLS_PKCS1_V21
Juan Castilloa57a4d52015-04-02 15:44:20 +010043
Juan Castillobae6b2a2015-11-05 09:24:53 +000044#define MBEDTLS_ASN1_PARSE_C
45#define MBEDTLS_ASN1_WRITE_C
Juan Castilloa57a4d52015-04-02 15:44:20 +010046
Juan Castillobae6b2a2015-11-05 09:24:53 +000047#define MBEDTLS_BASE64_C
48#define MBEDTLS_BIGNUM_C
Juan Castilloa57a4d52015-04-02 15:44:20 +010049
Juan Castillobae6b2a2015-11-05 09:24:53 +000050#define MBEDTLS_ERROR_C
51#define MBEDTLS_MD_C
Juan Castilloa57a4d52015-04-02 15:44:20 +010052
Juan Castillobae6b2a2015-11-05 09:24:53 +000053#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
54#define MBEDTLS_OID_C
Juan Castilloa57a4d52015-04-02 15:44:20 +010055
Juan Castillobae6b2a2015-11-05 09:24:53 +000056#define MBEDTLS_PK_C
57#define MBEDTLS_PK_PARSE_C
58#define MBEDTLS_PK_WRITE_C
Juan Castilloa57a4d52015-04-02 15:44:20 +010059
Juan Castillobae6b2a2015-11-05 09:24:53 +000060#define MBEDTLS_PLATFORM_C
Juan Castilloa57a4d52015-04-02 15:44:20 +010061
Justin Chadwellf9b32c12019-07-29 17:13:10 +010062#if TF_MBEDTLS_USE_ECDSA
Juan Castillobae6b2a2015-11-05 09:24:53 +000063#define MBEDTLS_ECDSA_C
64#define MBEDTLS_ECP_C
65#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
Justin Chadwellf9b32c12019-07-29 17:13:10 +010066#endif
67#if TF_MBEDTLS_USE_RSA
Qixiang Xuaa05eea2017-08-24 15:26:39 +080068#define MBEDTLS_RSA_C
69#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
Juan Castilloa57a4d52015-04-02 15:44:20 +010070#endif
71
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000072/* The library does not currently support enabling SHA-256 without SHA-224. */
73#define MBEDTLS_SHA224_C
Juan Castillobae6b2a2015-11-05 09:24:53 +000074#define MBEDTLS_SHA256_C
Manish V Badarkhee112a5a2021-10-06 23:41:50 +010075/*
76 * If either Trusted Boot or Measured Boot require a stronger algorithm than
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000077 * SHA-256, pull in SHA-512 support. Library currently needs to have SHA_384
78 * support when enabling SHA-512.
Manish V Badarkhee112a5a2021-10-06 23:41:50 +010079 */
80#if (TF_MBEDTLS_HASH_ALG_ID != TF_MBEDTLS_SHA256) /* TBB hash algo */
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000081#define MBEDTLS_SHA384_C
Manish V Badarkhee112a5a2021-10-06 23:41:50 +010082#define MBEDTLS_SHA512_C
83#else
84 /* TBB uses SHA-256, what about measured boot? */
laurenw-arm7834aa02022-05-31 16:39:09 -050085#if defined(TF_MBEDTLS_MBOOT_USE_SHA512)
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000086#define MBEDTLS_SHA384_C
Qixiang Xu1a1f2912017-11-09 13:56:29 +080087#define MBEDTLS_SHA512_C
88#endif
Manish V Badarkhee112a5a2021-10-06 23:41:50 +010089#endif
Juan Castilloa57a4d52015-04-02 15:44:20 +010090
Juan Castillobae6b2a2015-11-05 09:24:53 +000091#define MBEDTLS_VERSION_C
Juan Castilloa57a4d52015-04-02 15:44:20 +010092
Juan Castillobae6b2a2015-11-05 09:24:53 +000093#define MBEDTLS_X509_USE_C
94#define MBEDTLS_X509_CRT_PARSE_C
Juan Castilloa57a4d52015-04-02 15:44:20 +010095
Sumit Garg392e4df2019-11-15 10:43:00 +053096#if TF_MBEDTLS_USE_AES_GCM
97#define MBEDTLS_AES_C
98#define MBEDTLS_CIPHER_C
99#define MBEDTLS_GCM_C
100#endif
101
Juan Castilloa57a4d52015-04-02 15:44:20 +0100102/* MPI / BIGNUM options */
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100103#define MBEDTLS_MPI_WINDOW_SIZE 2
104
105#if TF_MBEDTLS_USE_RSA
106#if TF_MBEDTLS_KEY_SIZE <= 2048
107#define MBEDTLS_MPI_MAX_SIZE 256
108#else
109#define MBEDTLS_MPI_MAX_SIZE 512
110#endif
111#else
112#define MBEDTLS_MPI_MAX_SIZE 256
113#endif
Juan Castilloa57a4d52015-04-02 15:44:20 +0100114
115/* Memory buffer allocator options */
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100116#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 8
Juan Castilloa57a4d52015-04-02 15:44:20 +0100117
Alexei Fedorov42cb1aa2020-09-21 12:23:54 +0100118/*
119 * Prevent the use of 128-bit division which
120 * creates dependency on external libraries.
121 */
122#define MBEDTLS_NO_UDBL_DIVISION
123
Julius Werner53456fc2019-07-09 13:49:11 -0700124#ifndef __ASSEMBLER__
Qixiang Xude431b12017-10-13 09:23:42 +0800125/* System headers required to build mbed TLS with the current configuration */
126#include <stdlib.h>
Masahiro Yamada64b0c9a2019-09-04 14:09:07 +0900127#include <mbedtls/check_config.h>
Qixiang Xude431b12017-10-13 09:23:42 +0800128#endif
Juan Castilloa57a4d52015-04-02 15:44:20 +0100129
John Tsichritzis30f89642018-06-07 16:31:34 +0100130/*
131 * Determine Mbed TLS heap size
132 * 13312 = 13*1024
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100133 * 11264 = 11*1024
134 * 7168 = 7*1024
John Tsichritzis30f89642018-06-07 16:31:34 +0100135 */
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100136#if TF_MBEDTLS_USE_ECDSA
John Tsichritzis30f89642018-06-07 16:31:34 +0100137#define TF_MBEDTLS_HEAP_SIZE U(13312)
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100138#elif TF_MBEDTLS_USE_RSA
139#if TF_MBEDTLS_KEY_SIZE <= 2048
John Tsichritzis30f89642018-06-07 16:31:34 +0100140#define TF_MBEDTLS_HEAP_SIZE U(7168)
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100141#else
142#define TF_MBEDTLS_HEAP_SIZE U(11264)
143#endif
John Tsichritzis30f89642018-06-07 16:31:34 +0100144#endif
145
Sandrine Bailleuxa8143572022-06-15 15:31:52 +0200146/*
147 * Warn if errors from certain functions are ignored.
148 *
149 * The warnings are always enabled (where supported) for critical functions
150 * where ignoring the return value is almost always a bug. This macro extends
151 * the warnings to more functions.
152 */
153#define MBEDTLS_CHECK_RETURN_WARNING