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) |
| 24 | MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/mbedtls_config-2.h>" |
| 25 | else ifeq (${MBEDTLS_MAJOR}, 3) |
| 26 | MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/mbedtls_config-3.h>" |
| 27 | endif |
| 28 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 29 | $(eval $(call add_define,MBEDTLS_CONFIG_FILE)) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 30 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 31 | MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c |
| 32 | |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 33 | LIBMBEDTLS_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 | memory_buffer_alloc.c \ |
| 41 | oid.c \ |
| 42 | platform.c \ |
| 43 | platform_util.c \ |
| 44 | bignum.c \ |
| 45 | gcm.c \ |
| 46 | md.c \ |
| 47 | pk.c \ |
| 48 | pk_wrap.c \ |
| 49 | pkparse.c \ |
| 50 | pkwrite.c \ |
| 51 | sha256.c \ |
| 52 | sha512.c \ |
| 53 | ecdsa.c \ |
| 54 | ecp_curves.c \ |
| 55 | ecp.c \ |
| 56 | rsa.c \ |
| 57 | x509.c \ |
| 58 | x509_crt.c \ |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 59 | ) |
| 60 | |
Govindraj Raja | dee8b6f | 2023-01-12 15:34:12 +0000 | [diff] [blame] | 61 | ifeq (${MBEDTLS_MAJOR}, 2) |
| 62 | LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 63 | rsa_internal.c \ |
| 64 | ) |
| 65 | else ifeq (${MBEDTLS_MAJOR}, 3) |
| 66 | LIBMBEDTLS_SRCS += $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 67 | bignum_core.c \ |
| 68 | rsa_alt_helpers.c \ |
| 69 | hash_info.c \ |
| 70 | ) |
| 71 | |
| 72 | # Currently on Mbedtls-3 there is outstanding bug due to usage |
| 73 | # of redundant declaration[1], So disable redundant-decls |
| 74 | # compilation flag to avoid compilation error when compiling with |
| 75 | # Mbedtls-3. |
| 76 | # [1]: https://github.com/Mbed-TLS/mbedtls/issues/6910 |
| 77 | LIBMBEDTLS_CFLAGS += -Wno-error=redundant-decls |
| 78 | endif |
| 79 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 80 | # 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] | 81 | # algorithm to use. If the variable is not defined, select it based on |
| 82 | # algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined, |
| 83 | # then it is set to `rsa`. |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 84 | ifeq (${TF_MBEDTLS_KEY_ALG},) |
| 85 | ifeq (${KEY_ALG}, ecdsa) |
| 86 | TF_MBEDTLS_KEY_ALG := ecdsa |
| 87 | else |
| 88 | TF_MBEDTLS_KEY_ALG := rsa |
| 89 | endif |
| 90 | endif |
| 91 | |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 92 | ifeq (${TF_MBEDTLS_KEY_SIZE},) |
| 93 | ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),) |
| 94 | ifeq (${KEY_SIZE},) |
| 95 | TF_MBEDTLS_KEY_SIZE := 2048 |
| 96 | else |
| 97 | TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE} |
| 98 | endif |
| 99 | endif |
| 100 | endif |
| 101 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 102 | ifeq (${HASH_ALG}, sha384) |
| 103 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384 |
| 104 | else ifeq (${HASH_ALG}, sha512) |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 105 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512 |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 106 | else |
| 107 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256 |
| 108 | endif |
| 109 | |
| 110 | ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa) |
| 111 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA |
| 112 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa) |
| 113 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA |
| 114 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa) |
| 115 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA |
| 116 | else |
| 117 | $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS") |
| 118 | endif |
| 119 | |
Sumit Garg | 392e4df | 2019-11-15 10:43:00 +0530 | [diff] [blame] | 120 | ifeq (${DECRYPTION_SUPPORT}, aes_gcm) |
| 121 | TF_MBEDTLS_USE_AES_GCM := 1 |
| 122 | else |
| 123 | TF_MBEDTLS_USE_AES_GCM := 0 |
| 124 | endif |
| 125 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 126 | # Needs to be set to drive mbed TLS configuration correctly |
Leonardo Sandoval | 65fca7c | 2020-09-10 12:18:27 -0500 | [diff] [blame] | 127 | $(eval $(call add_defines,\ |
| 128 | $(sort \ |
| 129 | TF_MBEDTLS_KEY_ALG_ID \ |
| 130 | TF_MBEDTLS_KEY_SIZE \ |
| 131 | TF_MBEDTLS_HASH_ALG_ID \ |
| 132 | TF_MBEDTLS_USE_AES_GCM \ |
| 133 | ))) |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 134 | |
| 135 | $(eval $(call MAKE_LIB,mbedtls)) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 136 | |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 137 | endif |