blob: f157acb4eea06d7c87224c814dc6d68a43d31089 [file] [log] [blame]
Juan Castillo7d37aa12015-04-02 15:44:20 +01001#
Yann Gautierfd566c32024-01-19 17:44:41 +01002# Copyright (c) 2015-2023, Arm Limited. All rights reserved.
Juan Castillo7d37aa12015-04-02 15:44:20 +01003#
dp-arm82cb2c12017-05-03 09:38:09 +01004# SPDX-License-Identifier: BSD-3-Clause
Juan Castillo7d37aa12015-04-02 15:44:20 +01005#
6
7ifneq (${MBEDTLS_COMMON_MK},1)
8MBEDTLS_COMMON_MK := 1
9
Juan Castillo649dbf62015-11-05 09:24:53 +000010# MBEDTLS_DIR must be set to the mbed TLS main directory (it must contain
Juan Castillo7d37aa12015-04-02 15:44:20 +010011# the 'include' and 'library' subdirectories).
12ifeq (${MBEDTLS_DIR},)
13 $(error Error: MBEDTLS_DIR not set)
14endif
15
Roberto Vargasea7a57a2018-06-04 15:15:04 +010016MBEDTLS_INC = -I${MBEDTLS_DIR}/include
Juan Castillo7d37aa12015-04-02 15:44:20 +010017
Yann Gautierfd566c32024-01-19 17:44:41 +010018MBEDTLS_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 Castillo649dbf62015-11-05 09:24:53 +000022# Specify mbed TLS configuration file
Yann Gautierfd566c32024-01-19 17:44:41 +010023ifeq (${MBEDTLS_MAJOR}, 2)
Yann Gautier07126ff2023-11-15 18:35:26 +010024 $(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>"
Yann Gautierfd566c32024-01-19 17:44:41 +010026else ifeq (${MBEDTLS_MAJOR}, 3)
27 MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/mbedtls_config-3.h>"
28endif
29
Juan Castillo649dbf62015-11-05 09:24:53 +000030$(eval $(call add_define,MBEDTLS_CONFIG_FILE))
Juan Castillo7d37aa12015-04-02 15:44:20 +010031
Roberto Vargas180c4bc2018-05-08 10:27:10 +010032MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c
33
34
35LIBMBEDTLS_SRCS := $(addprefix ${MBEDTLS_DIR}/library/, \
Sumit Garg7cda17b2019-11-15 10:43:00 +053036 aes.c \
Roberto Vargas180c4bc2018-05-08 10:27:10 +010037 asn1parse.c \
38 asn1write.c \
Sumit Garg7cda17b2019-11-15 10:43:00 +053039 cipher.c \
40 cipher_wrap.c \
Yann Gautierfd566c32024-01-19 17:44:41 +010041 constant_time.c \
Roberto Vargas180c4bc2018-05-08 10:27:10 +010042 memory_buffer_alloc.c \
43 oid.c \
44 platform.c \
45 platform_util.c \
46 bignum.c \
Sumit Garg7cda17b2019-11-15 10:43:00 +053047 gcm.c \
Roberto Vargas180c4bc2018-05-08 10:27:10 +010048 md.c \
Roberto Vargas180c4bc2018-05-08 10:27:10 +010049 pk.c \
50 pk_wrap.c \
51 pkparse.c \
52 pkwrite.c \
53 sha256.c \
54 sha512.c \
55 ecdsa.c \
56 ecp_curves.c \
57 ecp.c \
58 rsa.c \
Roberto Vargas180c4bc2018-05-08 10:27:10 +010059 x509.c \
60 x509_crt.c \
61 )
62
Yann Gautierfd566c32024-01-19 17:44:41 +010063ifeq (${MBEDTLS_MAJOR}, 2)
64 LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \
65 rsa_internal.c \
66 )
67else ifeq (${MBEDTLS_MAJOR}, 3)
68 LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \
69 bignum_core.c \
70 rsa_alt_helpers.c \
71 hash_info.c \
72 )
73
74 # Currently on Mbedtls-3 there is outstanding bug due to usage
75 # of redundant declaration[1], So disable redundant-decls
76 # compilation flag to avoid compilation error when compiling with
77 # Mbedtls-3.
78 # [1]: https://github.com/Mbed-TLS/mbedtls/issues/6910
79 LIBMBEDTLS_CFLAGS += -Wno-error=redundant-decls
80endif
81
Roberto Vargas180c4bc2018-05-08 10:27:10 +010082# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
Justin Chadwell6a415a52019-09-09 15:24:31 +010083# algorithm to use. If the variable is not defined, select it based on
84# algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined,
85# then it is set to `rsa`.
Roberto Vargas180c4bc2018-05-08 10:27:10 +010086ifeq (${TF_MBEDTLS_KEY_ALG},)
87 ifeq (${KEY_ALG}, ecdsa)
88 TF_MBEDTLS_KEY_ALG := ecdsa
89 else
90 TF_MBEDTLS_KEY_ALG := rsa
91 endif
92endif
93
Justin Chadwellaacff742019-07-29 17:13:10 +010094ifeq (${TF_MBEDTLS_KEY_SIZE},)
95 ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),)
96 ifeq (${KEY_SIZE},)
97 TF_MBEDTLS_KEY_SIZE := 2048
98 else
99 TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
100 endif
101 endif
102endif
103
Roberto Vargas180c4bc2018-05-08 10:27:10 +0100104ifeq (${HASH_ALG}, sha384)
105 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384
106else ifeq (${HASH_ALG}, sha512)
Alexei Fedorov0ab49642020-03-20 18:38:55 +0000107 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512
Roberto Vargas180c4bc2018-05-08 10:27:10 +0100108else
109 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256
110endif
111
112ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
113 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA
114else ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
115 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA
116else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
117 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA
118else
119 $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
120endif
121
Sumit Garg7cda17b2019-11-15 10:43:00 +0530122ifeq (${DECRYPTION_SUPPORT}, aes_gcm)
123 TF_MBEDTLS_USE_AES_GCM := 1
124else
125 TF_MBEDTLS_USE_AES_GCM := 0
126endif
127
Roberto Vargas180c4bc2018-05-08 10:27:10 +0100128# Needs to be set to drive mbed TLS configuration correctly
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500129$(eval $(call add_defines,\
130 $(sort \
131 TF_MBEDTLS_KEY_ALG_ID \
132 TF_MBEDTLS_KEY_SIZE \
133 TF_MBEDTLS_HASH_ALG_ID \
134 TF_MBEDTLS_USE_AES_GCM \
135)))
Roberto Vargas180c4bc2018-05-08 10:27:10 +0100136
137$(eval $(call MAKE_LIB,mbedtls))
Juan Castillo7d37aa12015-04-02 15:44:20 +0100138
Juan Castillo7d37aa12015-04-02 15:44:20 +0100139endif