blob: a7a895cf927e754b4be39e1b0f7977b73295f4af [file] [log] [blame]
Juan Castillo7d37aa12015-04-02 15:44:20 +01001#
Yann Gautier87f4a632024-05-20 17:05:46 +02002# Copyright (c) 2015-2024, 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
Yann Gautier87f4a632024-05-20 17:05:46 +020022ifneq (${MBEDTLS_MAJOR}, 3)
23 $(error Error: TF-A only supports MbedTLS versions > 3.x)
Yann Gautierfd566c32024-01-19 17:44:41 +010024endif
25
Yann Gautier87f4a632024-05-20 17:05:46 +020026# Specify mbed TLS configuration file
27 MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/mbedtls_config-3.h>"
28
Juan Castillo649dbf62015-11-05 09:24:53 +000029$(eval $(call add_define,MBEDTLS_CONFIG_FILE))
Juan Castillo7d37aa12015-04-02 15:44:20 +010030
Roberto Vargas180c4bc2018-05-08 10:27:10 +010031MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c
32
Yann Gautier87f4a632024-05-20 17:05:46 +020033LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \
34 aes.c \
35 asn1parse.c \
36 asn1write.c \
37 cipher.c \
38 cipher_wrap.c \
39 constant_time.c \
40 hash_info.c \
41 memory_buffer_alloc.c \
42 oid.c \
43 platform.c \
44 platform_util.c \
45 bignum.c \
46 bignum_core.c \
47 gcm.c \
48 md.c \
49 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 \
59 rsa_alt_helpers.c \
60 x509.c \
61 x509_crt.c \
Roberto Vargas180c4bc2018-05-08 10:27:10 +010062 )
63
Yann Gautier87f4a632024-05-20 17:05:46 +020064# Currently on Mbedtls-3 there is outstanding bug due to usage
65# of redundant declaration[1], So disable redundant-decls
66# compilation flag to avoid compilation error when compiling with
67# Mbedtls-3.
68# [1]: https://github.com/Mbed-TLS/mbedtls/issues/6910
69LIBMBEDTLS_CFLAGS += -Wno-error=redundant-decls
Yann Gautierfd566c32024-01-19 17:44:41 +010070
Roberto Vargas180c4bc2018-05-08 10:27:10 +010071# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
Justin Chadwell6a415a52019-09-09 15:24:31 +010072# algorithm to use. If the variable is not defined, select it based on
73# algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined,
74# then it is set to `rsa`.
Roberto Vargas180c4bc2018-05-08 10:27:10 +010075ifeq (${TF_MBEDTLS_KEY_ALG},)
76 ifeq (${KEY_ALG}, ecdsa)
77 TF_MBEDTLS_KEY_ALG := ecdsa
78 else
79 TF_MBEDTLS_KEY_ALG := rsa
80 endif
81endif
82
Justin Chadwellaacff742019-07-29 17:13:10 +010083ifeq (${TF_MBEDTLS_KEY_SIZE},)
84 ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),)
85 ifeq (${KEY_SIZE},)
86 TF_MBEDTLS_KEY_SIZE := 2048
87 else
88 TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
89 endif
90 endif
91endif
92
Roberto Vargas180c4bc2018-05-08 10:27:10 +010093ifeq (${HASH_ALG}, sha384)
94 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384
95else ifeq (${HASH_ALG}, sha512)
Alexei Fedorov0ab49642020-03-20 18:38:55 +000096 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512
Roberto Vargas180c4bc2018-05-08 10:27:10 +010097else
98 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256
99endif
100
101ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
102 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA
103else ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
104 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA
105else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
106 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA
107else
108 $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
109endif
110
Sumit Garg7cda17b2019-11-15 10:43:00 +0530111ifeq (${DECRYPTION_SUPPORT}, aes_gcm)
112 TF_MBEDTLS_USE_AES_GCM := 1
113else
114 TF_MBEDTLS_USE_AES_GCM := 0
115endif
116
Roberto Vargas180c4bc2018-05-08 10:27:10 +0100117# Needs to be set to drive mbed TLS configuration correctly
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500118$(eval $(call add_defines,\
119 $(sort \
120 TF_MBEDTLS_KEY_ALG_ID \
121 TF_MBEDTLS_KEY_SIZE \
122 TF_MBEDTLS_HASH_ALG_ID \
123 TF_MBEDTLS_USE_AES_GCM \
124)))
Roberto Vargas180c4bc2018-05-08 10:27:10 +0100125
126$(eval $(call MAKE_LIB,mbedtls))
Juan Castillo7d37aa12015-04-02 15:44:20 +0100127
Juan Castillo7d37aa12015-04-02 15:44:20 +0100128endif