xref: /rk3399_ARM-atf/drivers/auth/mbedtls/mbedtls_common.mk (revision 5782b890d29646924d8bd3f46acdc73a6e02feb2)
17d37aa17SJuan Castillo#
251e06159SGovindraj Raja# Copyright (c) 2015-2023, Arm Limited. All rights reserved.
37d37aa17SJuan Castillo#
482cb2c1aSdp-arm# SPDX-License-Identifier: BSD-3-Clause
57d37aa17SJuan Castillo#
67d37aa17SJuan Castillo
77d37aa17SJuan Castilloifneq (${MBEDTLS_COMMON_MK},1)
87d37aa17SJuan CastilloMBEDTLS_COMMON_MK	:=	1
97d37aa17SJuan Castillo
107d37aa17SJuan Castillo# MBEDTLS_DIR must be set to the mbed TLS main directory (it must contain
117d37aa17SJuan Castillo# the 'include' and 'library' subdirectories).
127d37aa17SJuan Castilloifeq (${MBEDTLS_DIR},)
137d37aa17SJuan Castillo  $(error Error: MBEDTLS_DIR not set)
147d37aa17SJuan Castilloendif
157d37aa17SJuan Castillo
16ea7a57a3SRoberto VargasMBEDTLS_INC		=	-I${MBEDTLS_DIR}/include
177d37aa17SJuan Castillo
1851e06159SGovindraj RajaMBEDTLS_MAJOR=$(shell grep -hP "define MBEDTLS_VERSION_MAJOR" ${MBEDTLS_DIR}/include/mbedtls/*.h | grep -oe '\([0-9.]*\)')
1951e06159SGovindraj RajaMBEDTLS_MINOR=$(shell grep -hP "define MBEDTLS_VERSION_MINOR" ${MBEDTLS_DIR}/include/mbedtls/*.h | grep -oe '\([0-9.]*\)')
2051e06159SGovindraj Raja$(info MBEDTLS_VERSION_MAJOR is [${MBEDTLS_MAJOR}] MBEDTLS_VERSION_MINOR is [${MBEDTLS_MINOR}])
2151e06159SGovindraj Raja
227d37aa17SJuan Castillo# Specify mbed TLS configuration file
2351e06159SGovindraj Rajaifeq (${MBEDTLS_MAJOR}, 2)
2451e06159SGovindraj Raja	MBEDTLS_CONFIG_FILE	?=	"<drivers/auth/mbedtls/mbedtls_config-2.h>"
2551e06159SGovindraj Rajaelse ifeq (${MBEDTLS_MAJOR}, 3)
26*5782b890SManish V Badarkhe	ifeq (${PSA_CRYPTO},1)
27*5782b890SManish V Badarkhe		MBEDTLS_CONFIG_FILE     ?=      "<drivers/auth/mbedtls/psa_mbedtls_config.h>"
28*5782b890SManish V Badarkhe	else
2951e06159SGovindraj Raja		MBEDTLS_CONFIG_FILE	?=	"<drivers/auth/mbedtls/mbedtls_config-3.h>"
3051e06159SGovindraj Raja	endif
31*5782b890SManish V Badarkheendif
3251e06159SGovindraj Raja
33649dbf6fSJuan Castillo$(eval $(call add_define,MBEDTLS_CONFIG_FILE))
347d37aa17SJuan Castillo
35180c4bc2SRoberto VargasMBEDTLS_SOURCES	+=		drivers/auth/mbedtls/mbedtls_common.c
36180c4bc2SRoberto Vargas
373be9c276SMate Toth-PalLIBMBEDTLS_SRCS		+= $(addprefix ${MBEDTLS_DIR}/library/,		\
387cda17bbSSumit Garg					aes.c 				\
397d37aa17SJuan Castillo					asn1parse.c 			\
407d37aa17SJuan Castillo					asn1write.c 			\
417cda17bbSSumit Garg					cipher.c 			\
427cda17bbSSumit Garg					cipher_wrap.c 			\
4351e06159SGovindraj Raja					constant_time.c			\
447d37aa17SJuan Castillo					memory_buffer_alloc.c		\
457d37aa17SJuan Castillo					oid.c 				\
467d37aa17SJuan Castillo					platform.c 			\
47d25b527cSJeenu Viswambharan					platform_util.c			\
48180c4bc2SRoberto Vargas					bignum.c			\
497cda17bbSSumit Garg					gcm.c 				\
50180c4bc2SRoberto Vargas					md.c				\
51180c4bc2SRoberto Vargas					pk.c 				\
52180c4bc2SRoberto Vargas					pk_wrap.c 			\
53180c4bc2SRoberto Vargas					pkparse.c 			\
54180c4bc2SRoberto Vargas					pkwrite.c 			\
55180c4bc2SRoberto Vargas					sha256.c            		\
56180c4bc2SRoberto Vargas					sha512.c            		\
57180c4bc2SRoberto Vargas					ecdsa.c				\
58180c4bc2SRoberto Vargas					ecp_curves.c			\
59180c4bc2SRoberto Vargas					ecp.c				\
60180c4bc2SRoberto Vargas					rsa.c				\
61180c4bc2SRoberto Vargas					x509.c 				\
62180c4bc2SRoberto Vargas					x509_crt.c 			\
637d37aa17SJuan Castillo					)
647d37aa17SJuan Castillo
6551e06159SGovindraj Rajaifeq (${MBEDTLS_MAJOR}, 2)
6651e06159SGovindraj Raja	LIBMBEDTLS_SRCS +=  $(addprefix ${MBEDTLS_DIR}/library/,	\
6751e06159SGovindraj Raja						rsa_internal.c		\
6851e06159SGovindraj Raja						)
6951e06159SGovindraj Rajaelse ifeq (${MBEDTLS_MAJOR}, 3)
7051e06159SGovindraj Raja	LIBMBEDTLS_SRCS +=  $(addprefix ${MBEDTLS_DIR}/library/,	\
7151e06159SGovindraj Raja						bignum_core.c		\
7251e06159SGovindraj Raja						rsa_alt_helpers.c	\
7351e06159SGovindraj Raja						hash_info.c		\
7451e06159SGovindraj Raja						)
7551e06159SGovindraj Raja
7651e06159SGovindraj Raja	# Currently on Mbedtls-3 there is outstanding bug due to usage
7751e06159SGovindraj Raja	# of redundant declaration[1], So disable redundant-decls
7851e06159SGovindraj Raja	# compilation flag to avoid compilation error when compiling with
7951e06159SGovindraj Raja	# Mbedtls-3.
8051e06159SGovindraj Raja	# [1]: https://github.com/Mbed-TLS/mbedtls/issues/6910
8151e06159SGovindraj Raja	LIBMBEDTLS_CFLAGS += -Wno-error=redundant-decls
8251e06159SGovindraj Rajaendif
8351e06159SGovindraj Raja
84*5782b890SManish V Badarkheifeq (${PSA_CRYPTO},1)
85*5782b890SManish V BadarkheLIBMBEDTLS_SRCS         += $(addprefix ${MBEDTLS_DIR}/library/,    	\
86*5782b890SManish V Badarkhe					psa_crypto.c                   	\
87*5782b890SManish V Badarkhe					psa_crypto_client.c            	\
88*5782b890SManish V Badarkhe					psa_crypto_driver_wrappers.c   	\
89*5782b890SManish V Badarkhe					psa_crypto_hash.c              	\
90*5782b890SManish V Badarkhe					psa_crypto_rsa.c               	\
91*5782b890SManish V Badarkhe					psa_crypto_ecp.c               	\
92*5782b890SManish V Badarkhe					psa_crypto_slot_management.c   	\
93*5782b890SManish V Badarkhe					)
94*5782b890SManish V Badarkheendif
95*5782b890SManish V Badarkhe
96180c4bc2SRoberto Vargas# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
976a415a50SJustin Chadwell# algorithm to use. If the variable is not defined, select it based on
986a415a50SJustin Chadwell# algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined,
996a415a50SJustin Chadwell# then it is set to `rsa`.
100180c4bc2SRoberto Vargasifeq (${TF_MBEDTLS_KEY_ALG},)
101180c4bc2SRoberto Vargas    ifeq (${KEY_ALG}, ecdsa)
102180c4bc2SRoberto Vargas        TF_MBEDTLS_KEY_ALG		:=	ecdsa
103180c4bc2SRoberto Vargas    else
104180c4bc2SRoberto Vargas        TF_MBEDTLS_KEY_ALG		:=	rsa
105180c4bc2SRoberto Vargas    endif
106180c4bc2SRoberto Vargasendif
107180c4bc2SRoberto Vargas
108aacff749SJustin Chadwellifeq (${TF_MBEDTLS_KEY_SIZE},)
109aacff749SJustin Chadwell    ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),)
110aacff749SJustin Chadwell	ifeq (${KEY_SIZE},)
111aacff749SJustin Chadwell            TF_MBEDTLS_KEY_SIZE		:=	2048
112aacff749SJustin Chadwell	else
113aacff749SJustin Chadwell            TF_MBEDTLS_KEY_SIZE		:=	${KEY_SIZE}
114aacff749SJustin Chadwell	endif
115aacff749SJustin Chadwell    endif
116aacff749SJustin Chadwellendif
117aacff749SJustin Chadwell
118180c4bc2SRoberto Vargasifeq (${HASH_ALG}, sha384)
119180c4bc2SRoberto Vargas    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA384
120180c4bc2SRoberto Vargaselse ifeq (${HASH_ALG}, sha512)
121180c4bc2SRoberto Vargas    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA512
122180c4bc2SRoberto Vargaselse
123180c4bc2SRoberto Vargas    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA256
124180c4bc2SRoberto Vargasendif
125180c4bc2SRoberto Vargas
126180c4bc2SRoberto Vargasifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
127180c4bc2SRoberto Vargas    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_ECDSA
128180c4bc2SRoberto Vargaselse ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
129180c4bc2SRoberto Vargas    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_RSA
130180c4bc2SRoberto Vargaselse ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
131180c4bc2SRoberto Vargas    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_RSA_AND_ECDSA
132180c4bc2SRoberto Vargaselse
133180c4bc2SRoberto Vargas    $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
134180c4bc2SRoberto Vargasendif
135180c4bc2SRoberto Vargas
1367cda17bbSSumit Gargifeq (${DECRYPTION_SUPPORT}, aes_gcm)
1377cda17bbSSumit Garg    TF_MBEDTLS_USE_AES_GCM	:=	1
1387cda17bbSSumit Gargelse
1397cda17bbSSumit Garg    TF_MBEDTLS_USE_AES_GCM	:=	0
1407cda17bbSSumit Gargendif
1417cda17bbSSumit Garg
142180c4bc2SRoberto Vargas# Needs to be set to drive mbed TLS configuration correctly
143327131c4SLeonardo Sandoval$(eval $(call add_defines,\
144327131c4SLeonardo Sandoval    $(sort \
145327131c4SLeonardo Sandoval        TF_MBEDTLS_KEY_ALG_ID \
146327131c4SLeonardo Sandoval        TF_MBEDTLS_KEY_SIZE \
147327131c4SLeonardo Sandoval        TF_MBEDTLS_HASH_ALG_ID \
148327131c4SLeonardo Sandoval        TF_MBEDTLS_USE_AES_GCM \
149327131c4SLeonardo Sandoval)))
150180c4bc2SRoberto Vargas
151180c4bc2SRoberto Vargas$(eval $(call MAKE_LIB,mbedtls))
152180c4bc2SRoberto Vargas
1537d37aa17SJuan Castilloendif
154