xref: /rk3399_ARM-atf/drivers/auth/mbedtls/mbedtls_common.mk (revision 557f7d806a62a460404f8d1bec84c9400585930b)
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)
265782b890SManish V Badarkhe	ifeq (${PSA_CRYPTO},1)
275782b890SManish V Badarkhe		MBEDTLS_CONFIG_FILE     ?=      "<drivers/auth/mbedtls/psa_mbedtls_config.h>"
285782b890SManish V Badarkhe	else
2951e06159SGovindraj Raja		MBEDTLS_CONFIG_FILE	?=	"<drivers/auth/mbedtls/mbedtls_config-3.h>"
3051e06159SGovindraj Raja	endif
315782b890SManish 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
845782b890SManish V Badarkheifeq (${PSA_CRYPTO},1)
855782b890SManish V BadarkheLIBMBEDTLS_SRCS         += $(addprefix ${MBEDTLS_DIR}/library/,    	\
865782b890SManish V Badarkhe					psa_crypto.c                   	\
875782b890SManish V Badarkhe					psa_crypto_client.c            	\
885782b890SManish V Badarkhe					psa_crypto_driver_wrappers.c   	\
895782b890SManish V Badarkhe					psa_crypto_hash.c              	\
905782b890SManish V Badarkhe					psa_crypto_rsa.c               	\
915782b890SManish V Badarkhe					psa_crypto_ecp.c               	\
925782b890SManish V Badarkhe					psa_crypto_slot_management.c   	\
935782b890SManish V Badarkhe					)
945782b890SManish V Badarkheendif
955782b890SManish 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
112*557f7d80Slaurenw-arm        else ifneq ($(filter $(KEY_SIZE), 1024 2048 3072 4096),)
113aacff749SJustin Chadwell            TF_MBEDTLS_KEY_SIZE		:=	${KEY_SIZE}
114*557f7d80Slaurenw-arm        else
115*557f7d80Slaurenw-arm            $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}")
116*557f7d80Slaurenw-arm        endif
117*557f7d80Slaurenw-arm    else ifneq ($(findstring ecdsa,${TF_MBEDTLS_KEY_ALG}),)
118*557f7d80Slaurenw-arm        ifeq (${KEY_SIZE},)
119*557f7d80Slaurenw-arm            TF_MBEDTLS_KEY_SIZE		:=	256
120*557f7d80Slaurenw-arm        else ifneq ($(filter $(KEY_SIZE), 256 384),)
121*557f7d80Slaurenw-arm            TF_MBEDTLS_KEY_SIZE		:=	${KEY_SIZE}
122*557f7d80Slaurenw-arm        else
123*557f7d80Slaurenw-arm            $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}")
124aacff749SJustin Chadwell        endif
125aacff749SJustin Chadwell    endif
126aacff749SJustin Chadwellendif
127aacff749SJustin Chadwell
128180c4bc2SRoberto Vargasifeq (${HASH_ALG}, sha384)
129180c4bc2SRoberto Vargas    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA384
130180c4bc2SRoberto Vargaselse ifeq (${HASH_ALG}, sha512)
131180c4bc2SRoberto Vargas    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA512
132180c4bc2SRoberto Vargaselse
133180c4bc2SRoberto Vargas    TF_MBEDTLS_HASH_ALG_ID	:=	TF_MBEDTLS_SHA256
134180c4bc2SRoberto Vargasendif
135180c4bc2SRoberto Vargas
136180c4bc2SRoberto Vargasifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
137180c4bc2SRoberto Vargas    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_ECDSA
138180c4bc2SRoberto Vargaselse ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
139180c4bc2SRoberto Vargas    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_RSA
140180c4bc2SRoberto Vargaselse ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
141180c4bc2SRoberto Vargas    TF_MBEDTLS_KEY_ALG_ID	:=	TF_MBEDTLS_RSA_AND_ECDSA
142180c4bc2SRoberto Vargaselse
143180c4bc2SRoberto Vargas    $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
144180c4bc2SRoberto Vargasendif
145180c4bc2SRoberto Vargas
1467cda17bbSSumit Gargifeq (${DECRYPTION_SUPPORT}, aes_gcm)
1477cda17bbSSumit Garg    TF_MBEDTLS_USE_AES_GCM	:=	1
1487cda17bbSSumit Gargelse
1497cda17bbSSumit Garg    TF_MBEDTLS_USE_AES_GCM	:=	0
1507cda17bbSSumit Gargendif
1517cda17bbSSumit Garg
152180c4bc2SRoberto Vargas# Needs to be set to drive mbed TLS configuration correctly
153327131c4SLeonardo Sandoval$(eval $(call add_defines,\
154327131c4SLeonardo Sandoval    $(sort \
155327131c4SLeonardo Sandoval        TF_MBEDTLS_KEY_ALG_ID \
156327131c4SLeonardo Sandoval        TF_MBEDTLS_KEY_SIZE \
157327131c4SLeonardo Sandoval        TF_MBEDTLS_HASH_ALG_ID \
158327131c4SLeonardo Sandoval        TF_MBEDTLS_USE_AES_GCM \
159327131c4SLeonardo Sandoval)))
160180c4bc2SRoberto Vargas
161180c4bc2SRoberto Vargas$(eval $(call MAKE_LIB,mbedtls))
162180c4bc2SRoberto Vargas
1637d37aa17SJuan Castilloendif
164