Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 1 | # |
laurenw-arm | b3b6de7 | 2024-03-05 14:55:18 -0600 | [diff] [blame] | 2 | # Copyright (c) 2015-2024, Arm Limited. All rights reserved. |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 3 | # |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | # SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 5 | # |
| 6 | |
| 7 | ifneq (${MBEDTLS_COMMON_MK},1) |
| 8 | MBEDTLS_COMMON_MK := 1 |
| 9 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 10 | # MBEDTLS_DIR must be set to the mbed TLS main directory (it must contain |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 11 | # the 'include' and 'library' subdirectories). |
| 12 | ifeq (${MBEDTLS_DIR},) |
| 13 | $(error Error: MBEDTLS_DIR not set) |
| 14 | endif |
| 15 | |
Roberto Vargas | d51207e | 2018-06-04 15:15:04 +0100 | [diff] [blame] | 16 | MBEDTLS_INC = -I${MBEDTLS_DIR}/include |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 17 | |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 18 | MBEDTLS_MAJOR=$(shell grep -hP "define MBEDTLS_VERSION_MAJOR" ${MBEDTLS_DIR}/include/mbedtls/*.h | grep -oe '\([0-9.]*\)') |
| 19 | MBEDTLS_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 | |
laurenw-arm | b3b6de7 | 2024-03-05 14:55:18 -0600 | [diff] [blame] | 22 | ifneq (${MBEDTLS_MAJOR}, 3) |
| 23 | $(error Error: TF-A only supports MbedTLS versions > 3.x) |
| 24 | endif |
| 25 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 26 | # Specify mbed TLS configuration file |
laurenw-arm | b3b6de7 | 2024-03-05 14:55:18 -0600 | [diff] [blame] | 27 | ifeq (${PSA_CRYPTO},1) |
| 28 | MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/psa_mbedtls_config.h>" |
| 29 | else |
| 30 | MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/mbedtls_config-3.h>" |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 31 | endif |
| 32 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 33 | $(eval $(call add_define,MBEDTLS_CONFIG_FILE)) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 34 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 35 | MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c |
| 36 | |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 37 | LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 38 | aes.c \ |
| 39 | asn1parse.c \ |
| 40 | asn1write.c \ |
| 41 | cipher.c \ |
| 42 | cipher_wrap.c \ |
| 43 | constant_time.c \ |
| 44 | memory_buffer_alloc.c \ |
| 45 | oid.c \ |
| 46 | platform.c \ |
| 47 | platform_util.c \ |
| 48 | bignum.c \ |
laurenw-arm | b3b6de7 | 2024-03-05 14:55:18 -0600 | [diff] [blame] | 49 | bignum_core.c \ |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 50 | gcm.c \ |
| 51 | md.c \ |
| 52 | pk.c \ |
Jimmy Brisson | 640d991 | 2024-04-10 10:20:13 -0500 | [diff] [blame] | 53 | pk_ecc.c \ |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 54 | pk_wrap.c \ |
| 55 | pkparse.c \ |
| 56 | pkwrite.c \ |
| 57 | sha256.c \ |
| 58 | sha512.c \ |
| 59 | ecdsa.c \ |
| 60 | ecp_curves.c \ |
| 61 | ecp.c \ |
| 62 | rsa.c \ |
laurenw-arm | b3b6de7 | 2024-03-05 14:55:18 -0600 | [diff] [blame] | 63 | rsa_alt_helpers.c \ |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 64 | x509.c \ |
| 65 | x509_crt.c \ |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 66 | ) |
| 67 | |
Manish V Badarkhe | 78e14f8 | 2023-09-06 09:08:28 +0100 | [diff] [blame] | 68 | ifeq (${PSA_CRYPTO},1) |
Jimmy Brisson | 640d991 | 2024-04-10 10:20:13 -0500 | [diff] [blame] | 69 | LIBMBEDTLS_CFLAGS += -Wno-error=unused-but-set-variable |
Manish V Badarkhe | 78e14f8 | 2023-09-06 09:08:28 +0100 | [diff] [blame] | 70 | LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 71 | psa_crypto.c \ |
| 72 | psa_crypto_client.c \ |
Manish V Badarkhe | 78e14f8 | 2023-09-06 09:08:28 +0100 | [diff] [blame] | 73 | psa_crypto_hash.c \ |
| 74 | psa_crypto_rsa.c \ |
| 75 | psa_crypto_ecp.c \ |
| 76 | psa_crypto_slot_management.c \ |
Ryan Everett | 822cd6a | 2024-08-12 13:15:53 +0100 | [diff] [blame^] | 77 | psa_crypto_aead.c \ |
| 78 | psa_crypto_cipher.c \ |
Jimmy Brisson | 640d991 | 2024-04-10 10:20:13 -0500 | [diff] [blame] | 79 | psa_util.c \ |
Manish V Badarkhe | 78e14f8 | 2023-09-06 09:08:28 +0100 | [diff] [blame] | 80 | ) |
| 81 | endif |
| 82 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 83 | # The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key |
Justin Chadwell | 3168a20 | 2019-09-09 15:24:31 +0100 | [diff] [blame] | 84 | # algorithm to use. If the variable is not defined, select it based on |
| 85 | # algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined, |
| 86 | # then it is set to `rsa`. |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 87 | ifeq (${TF_MBEDTLS_KEY_ALG},) |
| 88 | ifeq (${KEY_ALG}, ecdsa) |
| 89 | TF_MBEDTLS_KEY_ALG := ecdsa |
| 90 | else |
| 91 | TF_MBEDTLS_KEY_ALG := rsa |
| 92 | endif |
| 93 | endif |
| 94 | |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 95 | ifeq (${TF_MBEDTLS_KEY_SIZE},) |
| 96 | ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),) |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 97 | ifeq (${KEY_SIZE},) |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 98 | TF_MBEDTLS_KEY_SIZE := 2048 |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 99 | else ifneq ($(filter $(KEY_SIZE), 1024 2048 3072 4096),) |
| 100 | TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE} |
| 101 | else |
| 102 | $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}") |
| 103 | endif |
| 104 | else ifneq ($(findstring ecdsa,${TF_MBEDTLS_KEY_ALG}),) |
| 105 | ifeq (${KEY_SIZE},) |
| 106 | TF_MBEDTLS_KEY_SIZE := 256 |
| 107 | else ifneq ($(filter $(KEY_SIZE), 256 384),) |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 108 | TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE} |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 109 | else |
| 110 | $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}") |
| 111 | endif |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 112 | endif |
| 113 | endif |
| 114 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 115 | ifeq (${HASH_ALG}, sha384) |
| 116 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384 |
| 117 | else ifeq (${HASH_ALG}, sha512) |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 118 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512 |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 119 | else |
| 120 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256 |
| 121 | endif |
| 122 | |
Jimmy Brisson | 9ce5eb4 | 2024-07-11 10:10:55 -0500 | [diff] [blame] | 123 | ifeq (${MBOOT_EL_HASH_ALG}, sha256) |
| 124 | $(eval $(call add_define,TF_MBEDTLS_MBOOT_USE_SHA256)) |
| 125 | else ifeq (${MBOOT_EL_HASH_ALG}, sha384) |
| 126 | $(eval $(call add_define,TF_MBEDTLS_MBOOT_USE_SHA384)) |
| 127 | else ifeq (${MBOOT_EL_HASH_ALG}, sha512) |
| 128 | $(eval $(call add_define,TF_MBEDTLS_MBOOT_USE_SHA512)) |
| 129 | endif |
| 130 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 131 | ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa) |
| 132 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA |
| 133 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa) |
| 134 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA |
| 135 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa) |
| 136 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA |
| 137 | else |
| 138 | $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS") |
| 139 | endif |
| 140 | |
Sumit Garg | 392e4df | 2019-11-15 10:43:00 +0530 | [diff] [blame] | 141 | ifeq (${DECRYPTION_SUPPORT}, aes_gcm) |
| 142 | TF_MBEDTLS_USE_AES_GCM := 1 |
| 143 | else |
| 144 | TF_MBEDTLS_USE_AES_GCM := 0 |
| 145 | endif |
| 146 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 147 | # Needs to be set to drive mbed TLS configuration correctly |
Leonardo Sandoval | 65fca7c | 2020-09-10 12:18:27 -0500 | [diff] [blame] | 148 | $(eval $(call add_defines,\ |
| 149 | $(sort \ |
| 150 | TF_MBEDTLS_KEY_ALG_ID \ |
| 151 | TF_MBEDTLS_KEY_SIZE \ |
| 152 | TF_MBEDTLS_HASH_ALG_ID \ |
| 153 | TF_MBEDTLS_USE_AES_GCM \ |
| 154 | ))) |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 155 | |
| 156 | $(eval $(call MAKE_LIB,mbedtls)) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 157 | |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 158 | endif |