Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 1 | # |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 2 | # Copyright (c) 2015-2023, 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 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 22 | # Specify mbed TLS configuration file |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 23 | ifeq (${MBEDTLS_MAJOR}, 2) |
Govindraj Raja | 8d68395 | 2023-11-10 09:00:09 -0600 | [diff] [blame] | 24 | $(info Deprecation Notice: Please migrate to Mbedtls version 3.x (refer to TF-A documentation for the exact version number)) |
| 25 | MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/mbedtls_config-2.h>" |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 26 | else ifeq (${MBEDTLS_MAJOR}, 3) |
Manish V Badarkhe | 78e14f8 | 2023-09-06 09:08:28 +0100 | [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>" |
| 31 | endif |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 32 | endif |
| 33 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 34 | $(eval $(call add_define,MBEDTLS_CONFIG_FILE)) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 35 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 36 | MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c |
| 37 | |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 38 | LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 39 | aes.c \ |
| 40 | asn1parse.c \ |
| 41 | asn1write.c \ |
| 42 | cipher.c \ |
| 43 | cipher_wrap.c \ |
| 44 | constant_time.c \ |
| 45 | memory_buffer_alloc.c \ |
| 46 | oid.c \ |
| 47 | platform.c \ |
| 48 | platform_util.c \ |
| 49 | bignum.c \ |
| 50 | gcm.c \ |
| 51 | md.c \ |
| 52 | pk.c \ |
| 53 | pk_wrap.c \ |
| 54 | pkparse.c \ |
| 55 | pkwrite.c \ |
| 56 | sha256.c \ |
| 57 | sha512.c \ |
| 58 | ecdsa.c \ |
| 59 | ecp_curves.c \ |
| 60 | ecp.c \ |
| 61 | rsa.c \ |
| 62 | x509.c \ |
| 63 | x509_crt.c \ |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 64 | ) |
| 65 | |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 66 | ifeq (${MBEDTLS_MAJOR}, 2) |
| 67 | LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 68 | rsa_internal.c \ |
| 69 | ) |
| 70 | else ifeq (${MBEDTLS_MAJOR}, 3) |
| 71 | LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 72 | bignum_core.c \ |
| 73 | rsa_alt_helpers.c \ |
| 74 | hash_info.c \ |
| 75 | ) |
| 76 | |
| 77 | # Currently on Mbedtls-3 there is outstanding bug due to usage |
| 78 | # of redundant declaration[1], So disable redundant-decls |
| 79 | # compilation flag to avoid compilation error when compiling with |
| 80 | # Mbedtls-3. |
| 81 | # [1]: https://github.com/Mbed-TLS/mbedtls/issues/6910 |
| 82 | LIBMBEDTLS_CFLAGS += -Wno-error=redundant-decls |
| 83 | endif |
| 84 | |
Manish V Badarkhe | 78e14f8 | 2023-09-06 09:08:28 +0100 | [diff] [blame] | 85 | ifeq (${PSA_CRYPTO},1) |
| 86 | LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 87 | psa_crypto.c \ |
| 88 | psa_crypto_client.c \ |
| 89 | psa_crypto_driver_wrappers.c \ |
| 90 | psa_crypto_hash.c \ |
| 91 | psa_crypto_rsa.c \ |
| 92 | psa_crypto_ecp.c \ |
| 93 | psa_crypto_slot_management.c \ |
| 94 | ) |
| 95 | endif |
| 96 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 97 | # 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] | 98 | # algorithm to use. If the variable is not defined, select it based on |
| 99 | # algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined, |
| 100 | # then it is set to `rsa`. |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 101 | ifeq (${TF_MBEDTLS_KEY_ALG},) |
| 102 | ifeq (${KEY_ALG}, ecdsa) |
| 103 | TF_MBEDTLS_KEY_ALG := ecdsa |
| 104 | else |
| 105 | TF_MBEDTLS_KEY_ALG := rsa |
| 106 | endif |
| 107 | endif |
| 108 | |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 109 | ifeq (${TF_MBEDTLS_KEY_SIZE},) |
| 110 | ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),) |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 111 | ifeq (${KEY_SIZE},) |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 112 | TF_MBEDTLS_KEY_SIZE := 2048 |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 113 | else ifneq ($(filter $(KEY_SIZE), 1024 2048 3072 4096),) |
| 114 | TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE} |
| 115 | else |
| 116 | $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}") |
| 117 | endif |
| 118 | else ifneq ($(findstring ecdsa,${TF_MBEDTLS_KEY_ALG}),) |
| 119 | ifeq (${KEY_SIZE},) |
| 120 | TF_MBEDTLS_KEY_SIZE := 256 |
| 121 | else ifneq ($(filter $(KEY_SIZE), 256 384),) |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 122 | TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE} |
laurenw-arm | f709c27 | 2023-08-15 14:56:46 -0500 | [diff] [blame] | 123 | else |
| 124 | $(error "Invalid value for KEY_SIZE: ${KEY_SIZE}") |
| 125 | endif |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 126 | endif |
| 127 | endif |
| 128 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 129 | ifeq (${HASH_ALG}, sha384) |
| 130 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384 |
| 131 | else ifeq (${HASH_ALG}, sha512) |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 132 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512 |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 133 | else |
| 134 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256 |
| 135 | endif |
| 136 | |
| 137 | ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa) |
| 138 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA |
| 139 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa) |
| 140 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA |
| 141 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa) |
| 142 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA |
| 143 | else |
| 144 | $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS") |
| 145 | endif |
| 146 | |
Sumit Garg | 392e4df | 2019-11-15 10:43:00 +0530 | [diff] [blame] | 147 | ifeq (${DECRYPTION_SUPPORT}, aes_gcm) |
| 148 | TF_MBEDTLS_USE_AES_GCM := 1 |
| 149 | else |
| 150 | TF_MBEDTLS_USE_AES_GCM := 0 |
| 151 | endif |
| 152 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 153 | # Needs to be set to drive mbed TLS configuration correctly |
Leonardo Sandoval | 65fca7c | 2020-09-10 12:18:27 -0500 | [diff] [blame] | 154 | $(eval $(call add_defines,\ |
| 155 | $(sort \ |
| 156 | TF_MBEDTLS_KEY_ALG_ID \ |
| 157 | TF_MBEDTLS_KEY_SIZE \ |
| 158 | TF_MBEDTLS_HASH_ALG_ID \ |
| 159 | TF_MBEDTLS_USE_AES_GCM \ |
| 160 | ))) |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 161 | |
| 162 | $(eval $(call MAKE_LIB,mbedtls)) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 163 | |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 164 | endif |