blob: a2c6430390e0b594301a05804373e2a78aae73f0 [file] [log] [blame]
Juan Castilloa57a4d52015-04-02 15:44:20 +01001#
Govindraj Rajadee8b6f2023-01-12 15:34:12 +00002# Copyright (c) 2015-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#
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
Juan Castillobae6b2a2015-11-05 09:24:53 +000022# Specify mbed TLS configuration file
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000023ifeq (${MBEDTLS_MAJOR}, 2)
Govindraj Raja8d683952023-11-10 09:00:09 -060024 $(info Deprecation Notice: Please migrate to Mbedtls version 3.x (refer to TF-A documentation for the exact version number))
25 MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/mbedtls_config-2.h>"
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000026else ifeq (${MBEDTLS_MAJOR}, 3)
Manish V Badarkhe78e14f82023-09-06 09:08:28 +010027 ifeq (${PSA_CRYPTO},1)
28 MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/psa_mbedtls_config.h>"
29 else
30 MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/mbedtls_config-3.h>"
31 endif
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000032endif
33
Juan Castillobae6b2a2015-11-05 09:24:53 +000034$(eval $(call add_define,MBEDTLS_CONFIG_FILE))
Juan Castilloa57a4d52015-04-02 15:44:20 +010035
Roberto Vargas502290b2018-05-08 10:27:10 +010036MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c
37
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000038LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \
39 aes.c \
40 asn1parse.c \
41 asn1write.c \
42 cipher.c \
43 cipher_wrap.c \
44 constant_time.c \
45 memory_buffer_alloc.c \
46 oid.c \
47 platform.c \
48 platform_util.c \
49 bignum.c \
50 gcm.c \
51 md.c \
52 pk.c \
53 pk_wrap.c \
54 pkparse.c \
55 pkwrite.c \
56 sha256.c \
57 sha512.c \
58 ecdsa.c \
59 ecp_curves.c \
60 ecp.c \
61 rsa.c \
62 x509.c \
63 x509_crt.c \
Roberto Vargas502290b2018-05-08 10:27:10 +010064 )
65
Govindraj Rajadee8b6f2023-01-12 15:34:12 +000066ifeq (${MBEDTLS_MAJOR}, 2)
67 LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \
68 rsa_internal.c \
69 )
70else ifeq (${MBEDTLS_MAJOR}, 3)
71 LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \
72 bignum_core.c \
73 rsa_alt_helpers.c \
74 hash_info.c \
75 )
76
77 # Currently on Mbedtls-3 there is outstanding bug due to usage
78 # of redundant declaration[1], So disable redundant-decls
79 # compilation flag to avoid compilation error when compiling with
80 # Mbedtls-3.
81 # [1]: https://github.com/Mbed-TLS/mbedtls/issues/6910
82 LIBMBEDTLS_CFLAGS += -Wno-error=redundant-decls
83endif
84
Manish V Badarkhe78e14f82023-09-06 09:08:28 +010085ifeq (${PSA_CRYPTO},1)
86LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \
87 psa_crypto.c \
88 psa_crypto_client.c \
89 psa_crypto_driver_wrappers.c \
90 psa_crypto_hash.c \
91 psa_crypto_rsa.c \
92 psa_crypto_ecp.c \
93 psa_crypto_slot_management.c \
94 )
95endif
96
Roberto Vargas502290b2018-05-08 10:27:10 +010097# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
Justin Chadwell3168a202019-09-09 15:24:31 +010098# algorithm to use. If the variable is not defined, select it based on
99# algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined,
100# then it is set to `rsa`.
Roberto Vargas502290b2018-05-08 10:27:10 +0100101ifeq (${TF_MBEDTLS_KEY_ALG},)
102 ifeq (${KEY_ALG}, ecdsa)
103 TF_MBEDTLS_KEY_ALG := ecdsa
104 else
105 TF_MBEDTLS_KEY_ALG := rsa
106 endif
107endif
108
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100109ifeq (${TF_MBEDTLS_KEY_SIZE},)
110 ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),)
laurenw-armf709c272023-08-15 14:56:46 -0500111 ifeq (${KEY_SIZE},)
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100112 TF_MBEDTLS_KEY_SIZE := 2048
laurenw-armf709c272023-08-15 14:56:46 -0500113 else ifneq ($(filter $(KEY_SIZE), 1024 2048 3072 4096),)
114 TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
115 else
116 $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}")
117 endif
118 else ifneq ($(findstring ecdsa,${TF_MBEDTLS_KEY_ALG}),)
119 ifeq (${KEY_SIZE},)
120 TF_MBEDTLS_KEY_SIZE := 256
121 else ifneq ($(filter $(KEY_SIZE), 256 384),)
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100122 TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
laurenw-armf709c272023-08-15 14:56:46 -0500123 else
124 $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}")
125 endif
Justin Chadwellf9b32c12019-07-29 17:13:10 +0100126 endif
127endif
128
Roberto Vargas502290b2018-05-08 10:27:10 +0100129ifeq (${HASH_ALG}, sha384)
130 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384
131else ifeq (${HASH_ALG}, sha512)
Alexei Fedorov25d7c882020-03-20 18:38:55 +0000132 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512
Roberto Vargas502290b2018-05-08 10:27:10 +0100133else
134 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256
135endif
136
137ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
138 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA
139else ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
140 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA
141else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
142 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA
143else
144 $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
145endif
146
Sumit Garg392e4df2019-11-15 10:43:00 +0530147ifeq (${DECRYPTION_SUPPORT}, aes_gcm)
148 TF_MBEDTLS_USE_AES_GCM := 1
149else
150 TF_MBEDTLS_USE_AES_GCM := 0
151endif
152
Roberto Vargas502290b2018-05-08 10:27:10 +0100153# Needs to be set to drive mbed TLS configuration correctly
Leonardo Sandoval65fca7c2020-09-10 12:18:27 -0500154$(eval $(call add_defines,\
155 $(sort \
156 TF_MBEDTLS_KEY_ALG_ID \
157 TF_MBEDTLS_KEY_SIZE \
158 TF_MBEDTLS_HASH_ALG_ID \
159 TF_MBEDTLS_USE_AES_GCM \
160)))
Roberto Vargas502290b2018-05-08 10:27:10 +0100161
162$(eval $(call MAKE_LIB,mbedtls))
Juan Castilloa57a4d52015-04-02 15:44:20 +0100163
Juan Castilloa57a4d52015-04-02 15:44:20 +0100164endif