blob: 2bb23f961e5d9e08ed86a7077ca01ea389440eb5 [file] [log] [blame]
Juan Castilloa57a4d52015-04-02 15:44:20 +01001#
laurenw-armb3b6de72024-03-05 14:55:18 -06002# Copyright (c) 2015-2024, 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#
6
7ifneq (${MBEDTLS_COMMON_MK},1)
8MBEDTLS_COMMON_MK := 1
9
Juan Castillobae6b2a2015-11-05 09:24:53 +000010# MBEDTLS_DIR must be set to the mbed TLS main directory (it must contain
Juan Castilloa57a4d52015-04-02 15:44:20 +010011# the 'include' and 'library' subdirectories).
12ifeq (${MBEDTLS_DIR},)
13 $(error Error: MBEDTLS_DIR not set)
14endif
15
Roberto Vargasd51207e2018-06-04 15:15:04 +010016MBEDTLS_INC = -I${MBEDTLS_DIR}/include
Juan Castilloa57a4d52015-04-02 15:44:20 +010017
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000018MBEDTLS_MAJOR=$(shell grep -hP "define MBEDTLS_VERSION_MAJOR" ${MBEDTLS_DIR}/include/mbedtls/*.h | grep -oe '\([0-9.]*\)')
19MBEDTLS_MINOR=$(shell grep -hP "define MBEDTLS_VERSION_MINOR" ${MBEDTLS_DIR}/include/mbedtls/*.h | grep -oe '\([0-9.]*\)')
20$(info MBEDTLS_VERSION_MAJOR is [${MBEDTLS_MAJOR}] MBEDTLS_VERSION_MINOR is [${MBEDTLS_MINOR}])
21
laurenw-armb3b6de72024-03-05 14:55:18 -060022ifneq (${MBEDTLS_MAJOR}, 3)
23 $(error Error: TF-A only supports MbedTLS versions > 3.x)
24endif
25
Juan Castillobae6b2a2015-11-05 09:24:53 +000026# Specify mbed TLS configuration file
laurenw-armb3b6de72024-03-05 14:55:18 -060027ifeq (${PSA_CRYPTO},1)
28 MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/psa_mbedtls_config.h>"
29else
30 MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/mbedtls_config-3.h>"
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000031endif
32
Juan Castillobae6b2a2015-11-05 09:24:53 +000033$(eval $(call add_define,MBEDTLS_CONFIG_FILE))
Juan Castilloa57a4d52015-04-02 15:44:20 +010034
Roberto Vargas502290b2018-05-08 10:27:10 +010035MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c
36
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000037LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \
38 aes.c \
39 asn1parse.c \
40 asn1write.c \
41 cipher.c \
42 cipher_wrap.c \
43 constant_time.c \
laurenw-armb3b6de72024-03-05 14:55:18 -060044 hash_info.c \
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000045 memory_buffer_alloc.c \
46 oid.c \
47 platform.c \
48 platform_util.c \
49 bignum.c \
laurenw-armb3b6de72024-03-05 14:55:18 -060050 bignum_core.c \
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000051 gcm.c \
52 md.c \
53 pk.c \
54 pk_wrap.c \
55 pkparse.c \
56 pkwrite.c \
57 sha256.c \
58 sha512.c \
59 ecdsa.c \
60 ecp_curves.c \
61 ecp.c \
62 rsa.c \
laurenw-armb3b6de72024-03-05 14:55:18 -060063 rsa_alt_helpers.c \
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000064 x509.c \
65 x509_crt.c \
Roberto Vargas502290b2018-05-08 10:27:10 +010066 )
67
laurenw-armb3b6de72024-03-05 14:55:18 -060068# Currently on Mbedtls-3 there is outstanding bug due to usage
69# of redundant declaration[1], So disable redundant-decls
70# compilation flag to avoid compilation error when compiling with
71# Mbedtls-3.
72# [1]: https://github.com/Mbed-TLS/mbedtls/issues/6910
73LIBMBEDTLS_CFLAGS += -Wno-error=redundant-decls
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000074
Manish V Badarkhe78e14f82023-09-06 09:08:28 +010075ifeq (${PSA_CRYPTO},1)
76LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \
77 psa_crypto.c \
78 psa_crypto_client.c \
79 psa_crypto_driver_wrappers.c \
80 psa_crypto_hash.c \
81 psa_crypto_rsa.c \
82 psa_crypto_ecp.c \
83 psa_crypto_slot_management.c \
84 )
85endif
86
Roberto Vargas502290b2018-05-08 10:27:10 +010087# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
Justin Chadwell3168a202019-09-09 15:24:31 +010088# algorithm to use. If the variable is not defined, select it based on
89# algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined,
90# then it is set to `rsa`.
Roberto Vargas502290b2018-05-08 10:27:10 +010091ifeq (${TF_MBEDTLS_KEY_ALG},)
92 ifeq (${KEY_ALG}, ecdsa)
93 TF_MBEDTLS_KEY_ALG := ecdsa
94 else
95 TF_MBEDTLS_KEY_ALG := rsa
96 endif
97endif
98
Justin Chadwellf9b32c12019-07-29 17:13:10 +010099ifeq (${TF_MBEDTLS_KEY_SIZE},)
100 ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),)
laurenw-armf709c272023-08-15 14:56:46 -0500101 ifeq (${KEY_SIZE},)
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100102 TF_MBEDTLS_KEY_SIZE := 2048
laurenw-armf709c272023-08-15 14:56:46 -0500103 else ifneq ($(filter $(KEY_SIZE), 1024 2048 3072 4096),)
104 TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
105 else
106 $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}")
107 endif
108 else ifneq ($(findstring ecdsa,${TF_MBEDTLS_KEY_ALG}),)
109 ifeq (${KEY_SIZE},)
110 TF_MBEDTLS_KEY_SIZE := 256
111 else ifneq ($(filter $(KEY_SIZE), 256 384),)
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100112 TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
laurenw-armf709c272023-08-15 14:56:46 -0500113 else
114 $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}")
115 endif
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100116 endif
117endif
118
Roberto Vargas502290b2018-05-08 10:27:10 +0100119ifeq (${HASH_ALG}, sha384)
120 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384
121else ifeq (${HASH_ALG}, sha512)
Alexei Fedorov25d7c882020-03-20 18:38:55 +0000122 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512
Roberto Vargas502290b2018-05-08 10:27:10 +0100123else
124 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256
125endif
126
127ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
128 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA
129else ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
130 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA
131else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
132 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA
133else
134 $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
135endif
136
Sumit Garg392e4df2019-11-15 10:43:00 +0530137ifeq (${DECRYPTION_SUPPORT}, aes_gcm)
138 TF_MBEDTLS_USE_AES_GCM := 1
139else
140 TF_MBEDTLS_USE_AES_GCM := 0
141endif
142
Roberto Vargas502290b2018-05-08 10:27:10 +0100143# Needs to be set to drive mbed TLS configuration correctly
Leonardo Sandoval65fca7c2020-09-10 12:18:27 -0500144$(eval $(call add_defines,\
145 $(sort \
146 TF_MBEDTLS_KEY_ALG_ID \
147 TF_MBEDTLS_KEY_SIZE \
148 TF_MBEDTLS_HASH_ALG_ID \
149 TF_MBEDTLS_USE_AES_GCM \
150)))
Roberto Vargas502290b2018-05-08 10:27:10 +0100151
152$(eval $(call MAKE_LIB,mbedtls))
Juan Castilloa57a4d52015-04-02 15:44:20 +0100153
Juan Castilloa57a4d52015-04-02 15:44:20 +0100154endif