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 \ |
Jimmy Brisson | 640d991 | 2024-04-10 10:20:13 -0500 | [diff] [blame] | 77 | psa_util.c \ |
Manish V Badarkhe | 78e14f8 | 2023-09-06 09:08:28 +0100 | [diff] [blame] | 78 | ) |
| 79 | endif |
| 80 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 81 | # 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] | 82 | # algorithm to use. If the variable is not defined, select it based on |
| 83 | # algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined, |
| 84 | # then it is set to `rsa`. |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 85 | ifeq (${TF_MBEDTLS_KEY_ALG},) |
| 86 | ifeq (${KEY_ALG}, ecdsa) |
| 87 | TF_MBEDTLS_KEY_ALG := ecdsa |
| 88 | else |
| 89 | TF_MBEDTLS_KEY_ALG := rsa |
| 90 | endif |
| 91 | endif |
| 92 | |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 93 | ifeq (${TF_MBEDTLS_KEY_SIZE},) |
| 94 | ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),) |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 95 | ifeq (${KEY_SIZE},) |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 96 | TF_MBEDTLS_KEY_SIZE := 2048 |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 97 | else ifneq ($(filter $(KEY_SIZE), 1024 2048 3072 4096),) |
| 98 | TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE} |
| 99 | else |
| 100 | $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}") |
| 101 | endif |
| 102 | else ifneq ($(findstring ecdsa,${TF_MBEDTLS_KEY_ALG}),) |
| 103 | ifeq (${KEY_SIZE},) |
| 104 | TF_MBEDTLS_KEY_SIZE := 256 |
| 105 | else ifneq ($(filter $(KEY_SIZE), 256 384),) |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 106 | TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE} |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 107 | else |
| 108 | $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}") |
| 109 | endif |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 110 | endif |
| 111 | endif |
| 112 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 113 | ifeq (${HASH_ALG}, sha384) |
| 114 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384 |
| 115 | else ifeq (${HASH_ALG}, sha512) |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 116 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512 |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 117 | else |
| 118 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256 |
| 119 | endif |
| 120 | |
| 121 | ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa) |
| 122 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA |
| 123 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa) |
| 124 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA |
| 125 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa) |
| 126 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA |
| 127 | else |
| 128 | $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS") |
| 129 | endif |
| 130 | |
Sumit Garg | 392e4df | 2019-11-15 10:43:00 +0530 | [diff] [blame] | 131 | ifeq (${DECRYPTION_SUPPORT}, aes_gcm) |
| 132 | TF_MBEDTLS_USE_AES_GCM := 1 |
| 133 | else |
| 134 | TF_MBEDTLS_USE_AES_GCM := 0 |
| 135 | endif |
| 136 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 137 | # Needs to be set to drive mbed TLS configuration correctly |
Leonardo Sandoval | 65fca7c | 2020-09-10 12:18:27 -0500 | [diff] [blame] | 138 | $(eval $(call add_defines,\ |
| 139 | $(sort \ |
| 140 | TF_MBEDTLS_KEY_ALG_ID \ |
| 141 | TF_MBEDTLS_KEY_SIZE \ |
| 142 | TF_MBEDTLS_HASH_ALG_ID \ |
| 143 | TF_MBEDTLS_USE_AES_GCM \ |
| 144 | ))) |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 145 | |
| 146 | $(eval $(call MAKE_LIB,mbedtls)) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 147 | |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 148 | endif |