blob: 55ab9358e48dd0446193f1fbf67b7805310cb0be [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 \
44 memory_buffer_alloc.c \
45 oid.c \
46 platform.c \
47 platform_util.c \
48 bignum.c \
laurenw-armb3b6de72024-03-05 14:55:18 -060049 bignum_core.c \
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000050 gcm.c \
51 md.c \
52 pk.c \
Jimmy Brisson640d9912024-04-10 10:20:13 -050053 pk_ecc.c \
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000054 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
Manish V Badarkhe78e14f82023-09-06 09:08:28 +010068ifeq (${PSA_CRYPTO},1)
Jimmy Brisson640d9912024-04-10 10:20:13 -050069LIBMBEDTLS_CFLAGS += -Wno-error=unused-but-set-variable
Manish V Badarkhe78e14f82023-09-06 09:08:28 +010070LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \
71 psa_crypto.c \
72 psa_crypto_client.c \
Manish V Badarkhe78e14f82023-09-06 09:08:28 +010073 psa_crypto_hash.c \
74 psa_crypto_rsa.c \
75 psa_crypto_ecp.c \
76 psa_crypto_slot_management.c \
Jimmy Brisson640d9912024-04-10 10:20:13 -050077 psa_util.c \
Manish V Badarkhe78e14f82023-09-06 09:08:28 +010078 )
79endif
80
Roberto Vargas502290b2018-05-08 10:27:10 +010081# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
Justin Chadwell3168a202019-09-09 15:24:31 +010082# algorithm to use. If the variable is not defined, select it based on
83# algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined,
84# then it is set to `rsa`.
Roberto Vargas502290b2018-05-08 10:27:10 +010085ifeq (${TF_MBEDTLS_KEY_ALG},)
86 ifeq (${KEY_ALG}, ecdsa)
87 TF_MBEDTLS_KEY_ALG := ecdsa
88 else
89 TF_MBEDTLS_KEY_ALG := rsa
90 endif
91endif
92
Justin Chadwellf9b32c12019-07-29 17:13:10 +010093ifeq (${TF_MBEDTLS_KEY_SIZE},)
94 ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),)
laurenw-armf709c272023-08-15 14:56:46 -050095 ifeq (${KEY_SIZE},)
Justin Chadwellf9b32c12019-07-29 17:13:10 +010096 TF_MBEDTLS_KEY_SIZE := 2048
laurenw-armf709c272023-08-15 14:56:46 -050097 else ifneq ($(filter $(KEY_SIZE), 1024 2048 3072 4096),)
98 TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
99 else
100 $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}")
101 endif
102 else ifneq ($(findstring ecdsa,${TF_MBEDTLS_KEY_ALG}),)
103 ifeq (${KEY_SIZE},)
104 TF_MBEDTLS_KEY_SIZE := 256
105 else ifneq ($(filter $(KEY_SIZE), 256 384),)
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100106 TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
laurenw-armf709c272023-08-15 14:56:46 -0500107 else
108 $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}")
109 endif
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100110 endif
111endif
112
Roberto Vargas502290b2018-05-08 10:27:10 +0100113ifeq (${HASH_ALG}, sha384)
114 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384
115else ifeq (${HASH_ALG}, sha512)
Alexei Fedorov25d7c882020-03-20 18:38:55 +0000116 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512
Roberto Vargas502290b2018-05-08 10:27:10 +0100117else
118 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256
119endif
120
121ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
122 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA
123else ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
124 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA
125else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
126 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA
127else
128 $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
129endif
130
Sumit Garg392e4df2019-11-15 10:43:00 +0530131ifeq (${DECRYPTION_SUPPORT}, aes_gcm)
132 TF_MBEDTLS_USE_AES_GCM := 1
133else
134 TF_MBEDTLS_USE_AES_GCM := 0
135endif
136
Roberto Vargas502290b2018-05-08 10:27:10 +0100137# Needs to be set to drive mbed TLS configuration correctly
Leonardo Sandoval65fca7c2020-09-10 12:18:27 -0500138$(eval $(call add_defines,\
139 $(sort \
140 TF_MBEDTLS_KEY_ALG_ID \
141 TF_MBEDTLS_KEY_SIZE \
142 TF_MBEDTLS_HASH_ALG_ID \
143 TF_MBEDTLS_USE_AES_GCM \
144)))
Roberto Vargas502290b2018-05-08 10:27:10 +0100145
146$(eval $(call MAKE_LIB,mbedtls))
Juan Castilloa57a4d52015-04-02 15:44:20 +0100147
Juan Castilloa57a4d52015-04-02 15:44:20 +0100148endif