blob: 8ad6d7a42414e8d3ad41819a93864a08c1428245 [file] [log] [blame]
Juan Castilloa57a4d52015-04-02 15:44:20 +01001/*
Manish V Badarkhee112a5a2021-10-06 23:41:50 +01002 * Copyright (c) 2015-2021, 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 */
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00006#ifndef MBEDTLS_CONFIG_H
7#define MBEDTLS_CONFIG_H
Juan Castilloa57a4d52015-04-02 15:44:20 +01008
9/*
Juan Castillobae6b2a2015-11-05 09:24:53 +000010 * Key algorithms currently supported on mbed TLS libraries
Juan Castilloa57a4d52015-04-02 15:44:20 +010011 */
Qixiang Xu1c2aef12017-08-24 15:12:20 +080012#define TF_MBEDTLS_RSA 1
13#define TF_MBEDTLS_ECDSA 2
Qixiang Xuaa05eea2017-08-24 15:26:39 +080014#define TF_MBEDTLS_RSA_AND_ECDSA 3
Juan Castilloa57a4d52015-04-02 15:44:20 +010015
Justin Chadwellf9b32c12019-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 Castilloa57a4d52015-04-02 15:44:20 +010021/*
Qixiang Xu1a1f2912017-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 Castillobae6b2a2015-11-05 09:24:53 +000029 * Configuration file to build mbed TLS with the required features for
Juan Castilloa57a4d52015-04-02 15:44:20 +010030 * Trusted Boot
31 */
32
Juan Castillobae6b2a2015-11-05 09:24:53 +000033#define MBEDTLS_PLATFORM_MEMORY
34#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Antonio Nino Diaz6b90f5e2017-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 Castilloa57a4d52015-04-02 15:44:20 +010037
Juan Castillobae6b2a2015-11-05 09:24:53 +000038#define MBEDTLS_PKCS1_V21
Juan Castilloa57a4d52015-04-02 15:44:20 +010039
Juan Castillobae6b2a2015-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 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
Alexei Fedorov42cb1aa2020-09-21 12:23:54 +010066#define MBEDTLS_ECP_NO_INTERNAL_RNG
Justin Chadwellf9b32c12019-07-29 17:13:10 +010067#endif
68#if TF_MBEDTLS_USE_RSA
Qixiang Xuaa05eea2017-08-24 15:26:39 +080069#define MBEDTLS_RSA_C
70#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
Juan Castilloa57a4d52015-04-02 15:44:20 +010071#endif
72
Juan Castillobae6b2a2015-11-05 09:24:53 +000073#define MBEDTLS_SHA256_C
Manish V Badarkhee112a5a2021-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? */
83#if defined(TF_MBEDTLS_TPM_HASH_ALG_ID) && \
84 (TF_MBEDTLS_TPM_HASH_ALG_ID != TF_MBEDTLS_SHA256)
Qixiang Xu1a1f2912017-11-09 13:56:29 +080085#define MBEDTLS_SHA512_C
86#endif
Manish V Badarkhee112a5a2021-10-06 23:41:50 +010087#endif
Juan Castilloa57a4d52015-04-02 15:44:20 +010088
Juan Castillobae6b2a2015-11-05 09:24:53 +000089#define MBEDTLS_VERSION_C
Juan Castilloa57a4d52015-04-02 15:44:20 +010090
Juan Castillobae6b2a2015-11-05 09:24:53 +000091#define MBEDTLS_X509_USE_C
92#define MBEDTLS_X509_CRT_PARSE_C
Juan Castilloa57a4d52015-04-02 15:44:20 +010093
Sumit Garg392e4df2019-11-15 10:43:00 +053094#if TF_MBEDTLS_USE_AES_GCM
95#define MBEDTLS_AES_C
96#define MBEDTLS_CIPHER_C
97#define MBEDTLS_GCM_C
98#endif
99
Juan Castilloa57a4d52015-04-02 15:44:20 +0100100/* MPI / BIGNUM options */
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100101#define MBEDTLS_MPI_WINDOW_SIZE 2
102
103#if TF_MBEDTLS_USE_RSA
104#if TF_MBEDTLS_KEY_SIZE <= 2048
105#define MBEDTLS_MPI_MAX_SIZE 256
106#else
107#define MBEDTLS_MPI_MAX_SIZE 512
108#endif
109#else
110#define MBEDTLS_MPI_MAX_SIZE 256
111#endif
Juan Castilloa57a4d52015-04-02 15:44:20 +0100112
113/* Memory buffer allocator options */
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100114#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 8
Juan Castilloa57a4d52015-04-02 15:44:20 +0100115
Alexei Fedorov42cb1aa2020-09-21 12:23:54 +0100116/*
117 * Prevent the use of 128-bit division which
118 * creates dependency on external libraries.
119 */
120#define MBEDTLS_NO_UDBL_DIVISION
121
Julius Werner53456fc2019-07-09 13:49:11 -0700122#ifndef __ASSEMBLER__
Qixiang Xude431b12017-10-13 09:23:42 +0800123/* System headers required to build mbed TLS with the current configuration */
124#include <stdlib.h>
Masahiro Yamada64b0c9a2019-09-04 14:09:07 +0900125#include <mbedtls/check_config.h>
Qixiang Xude431b12017-10-13 09:23:42 +0800126#endif
Juan Castilloa57a4d52015-04-02 15:44:20 +0100127
John Tsichritzis30f89642018-06-07 16:31:34 +0100128/*
129 * Determine Mbed TLS heap size
130 * 13312 = 13*1024
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100131 * 11264 = 11*1024
132 * 7168 = 7*1024
John Tsichritzis30f89642018-06-07 16:31:34 +0100133 */
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100134#if TF_MBEDTLS_USE_ECDSA
John Tsichritzis30f89642018-06-07 16:31:34 +0100135#define TF_MBEDTLS_HEAP_SIZE U(13312)
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100136#elif TF_MBEDTLS_USE_RSA
137#if TF_MBEDTLS_KEY_SIZE <= 2048
John Tsichritzis30f89642018-06-07 16:31:34 +0100138#define TF_MBEDTLS_HEAP_SIZE U(7168)
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100139#else
140#define TF_MBEDTLS_HEAP_SIZE U(11264)
141#endif
John Tsichritzis30f89642018-06-07 16:31:34 +0100142#endif
143
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000144#endif /* MBEDTLS_CONFIG_H */