blob: 54c819c19c0c73c8e0cb5370c91a1a28e7f4cef1 [file] [log] [blame]
Juan Castilloa57a4d52015-04-02 15:44:20 +01001#
Manish V Badarkhee112a5a2021-10-06 23:41:50 +01002# Copyright (c) 2015-2021, 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
Juan Castillobae6b2a2015-11-05 09:24:53 +000018# Specify mbed TLS configuration file
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000019MBEDTLS_CONFIG_FILE := "<drivers/auth/mbedtls/mbedtls_config.h>"
Juan Castillobae6b2a2015-11-05 09:24:53 +000020$(eval $(call add_define,MBEDTLS_CONFIG_FILE))
Juan Castilloa57a4d52015-04-02 15:44:20 +010021
Roberto Vargas502290b2018-05-08 10:27:10 +010022MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c
23
24
25LIBMBEDTLS_SRCS := $(addprefix ${MBEDTLS_DIR}/library/, \
Sumit Garg392e4df2019-11-15 10:43:00 +053026 aes.c \
Roberto Vargas502290b2018-05-08 10:27:10 +010027 asn1parse.c \
28 asn1write.c \
Sumit Garg392e4df2019-11-15 10:43:00 +053029 cipher.c \
30 cipher_wrap.c \
Roberto Vargas502290b2018-05-08 10:27:10 +010031 memory_buffer_alloc.c \
32 oid.c \
33 platform.c \
34 platform_util.c \
35 bignum.c \
Sumit Garg392e4df2019-11-15 10:43:00 +053036 gcm.c \
Roberto Vargas502290b2018-05-08 10:27:10 +010037 md.c \
Roberto Vargas502290b2018-05-08 10:27:10 +010038 pk.c \
39 pk_wrap.c \
40 pkparse.c \
41 pkwrite.c \
42 sha256.c \
43 sha512.c \
44 ecdsa.c \
45 ecp_curves.c \
46 ecp.c \
47 rsa.c \
48 rsa_internal.c \
49 x509.c \
50 x509_crt.c \
51 )
52
53# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
Justin Chadwell3168a202019-09-09 15:24:31 +010054# algorithm to use. If the variable is not defined, select it based on
55# algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined,
56# then it is set to `rsa`.
Roberto Vargas502290b2018-05-08 10:27:10 +010057ifeq (${TF_MBEDTLS_KEY_ALG},)
58 ifeq (${KEY_ALG}, ecdsa)
59 TF_MBEDTLS_KEY_ALG := ecdsa
60 else
61 TF_MBEDTLS_KEY_ALG := rsa
62 endif
63endif
64
Justin Chadwellf9b32c12019-07-29 17:13:10 +010065ifeq (${TF_MBEDTLS_KEY_SIZE},)
66 ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),)
67 ifeq (${KEY_SIZE},)
68 TF_MBEDTLS_KEY_SIZE := 2048
69 else
70 TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
71 endif
72 endif
73endif
74
Roberto Vargas502290b2018-05-08 10:27:10 +010075ifeq (${HASH_ALG}, sha384)
76 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384
77else ifeq (${HASH_ALG}, sha512)
Alexei Fedorov25d7c882020-03-20 18:38:55 +000078 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512
Roberto Vargas502290b2018-05-08 10:27:10 +010079else
80 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256
81endif
82
83ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
84 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA
85else ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
86 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA
87else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
88 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA
89else
90 $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
91endif
92
Sumit Garg392e4df2019-11-15 10:43:00 +053093ifeq (${DECRYPTION_SUPPORT}, aes_gcm)
94 TF_MBEDTLS_USE_AES_GCM := 1
95else
96 TF_MBEDTLS_USE_AES_GCM := 0
97endif
98
Manish V Badarkhee112a5a2021-10-06 23:41:50 +010099ifeq ($(MEASURED_BOOT),1)
100 ifeq (${TPM_HASH_ALG}, sha256)
101 TF_MBEDTLS_TPM_HASH_ALG_ID := TF_MBEDTLS_SHA256
102 else ifeq (${TPM_HASH_ALG}, sha384)
103 TF_MBEDTLS_TPM_HASH_ALG_ID := TF_MBEDTLS_SHA384
104 else ifeq (${TPM_HASH_ALG}, sha512)
105 TF_MBEDTLS_TPM_HASH_ALG_ID := TF_MBEDTLS_SHA512
106 else
107 $(error "TPM_HASH_ALG not defined.")
108 endif
109endif
110
Roberto Vargas502290b2018-05-08 10:27:10 +0100111# Needs to be set to drive mbed TLS configuration correctly
Leonardo Sandoval65fca7c2020-09-10 12:18:27 -0500112$(eval $(call add_defines,\
113 $(sort \
114 TF_MBEDTLS_KEY_ALG_ID \
115 TF_MBEDTLS_KEY_SIZE \
116 TF_MBEDTLS_HASH_ALG_ID \
117 TF_MBEDTLS_USE_AES_GCM \
118)))
Roberto Vargas502290b2018-05-08 10:27:10 +0100119
Manish V Badarkhee112a5a2021-10-06 23:41:50 +0100120ifeq ($(MEASURED_BOOT),1)
121 $(eval $(call add_define,TF_MBEDTLS_TPM_HASH_ALG_ID))
122endif
123
Roberto Vargas502290b2018-05-08 10:27:10 +0100124$(eval $(call MAKE_LIB,mbedtls))
Juan Castilloa57a4d52015-04-02 15:44:20 +0100125
Juan Castilloa57a4d52015-04-02 15:44:20 +0100126endif