Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 1 | # |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 2 | # Copyright (c) 2015-2020, ARM Limited and Contributors. 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 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 18 | # Specify mbed TLS configuration file |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 19 | MBEDTLS_CONFIG_FILE := "<drivers/auth/mbedtls/mbedtls_config.h>" |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 20 | $(eval $(call add_define,MBEDTLS_CONFIG_FILE)) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 21 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 22 | MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c |
| 23 | |
| 24 | |
| 25 | LIBMBEDTLS_SRCS := $(addprefix ${MBEDTLS_DIR}/library/, \ |
Sumit Garg | 392e4df | 2019-11-15 10:43:00 +0530 | [diff] [blame] | 26 | aes.c \ |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 27 | asn1parse.c \ |
| 28 | asn1write.c \ |
Sumit Garg | 392e4df | 2019-11-15 10:43:00 +0530 | [diff] [blame] | 29 | cipher.c \ |
| 30 | cipher_wrap.c \ |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 31 | memory_buffer_alloc.c \ |
| 32 | oid.c \ |
| 33 | platform.c \ |
| 34 | platform_util.c \ |
| 35 | bignum.c \ |
Sumit Garg | 392e4df | 2019-11-15 10:43:00 +0530 | [diff] [blame] | 36 | gcm.c \ |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 37 | md.c \ |
| 38 | md_wrap.c \ |
| 39 | pk.c \ |
| 40 | pk_wrap.c \ |
| 41 | pkparse.c \ |
| 42 | pkwrite.c \ |
| 43 | sha256.c \ |
| 44 | sha512.c \ |
| 45 | ecdsa.c \ |
| 46 | ecp_curves.c \ |
| 47 | ecp.c \ |
| 48 | rsa.c \ |
| 49 | rsa_internal.c \ |
| 50 | x509.c \ |
| 51 | x509_crt.c \ |
| 52 | ) |
| 53 | |
| 54 | # 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] | 55 | # algorithm to use. If the variable is not defined, select it based on |
| 56 | # algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined, |
| 57 | # then it is set to `rsa`. |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 58 | ifeq (${TF_MBEDTLS_KEY_ALG},) |
| 59 | ifeq (${KEY_ALG}, ecdsa) |
| 60 | TF_MBEDTLS_KEY_ALG := ecdsa |
| 61 | else |
| 62 | TF_MBEDTLS_KEY_ALG := rsa |
| 63 | endif |
| 64 | endif |
| 65 | |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 66 | ifeq (${TF_MBEDTLS_KEY_SIZE},) |
| 67 | ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),) |
| 68 | ifeq (${KEY_SIZE},) |
| 69 | TF_MBEDTLS_KEY_SIZE := 2048 |
| 70 | else |
| 71 | TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE} |
| 72 | endif |
| 73 | endif |
| 74 | endif |
| 75 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 76 | ifeq (${HASH_ALG}, sha384) |
| 77 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384 |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 78 | MBEDTLS_MD_ID := MBEDTLS_MD_SHA384 |
| 79 | TPM_ALG_ID := TPM_ALG_SHA384 |
| 80 | TCG_DIGEST_SIZE := 48 |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 81 | else ifeq (${HASH_ALG}, sha512) |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 82 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512 |
| 83 | MBEDTLS_MD_ID := MBEDTLS_MD_SHA512 |
| 84 | TPM_ALG_ID := TPM_ALG_SHA512 |
| 85 | TCG_DIGEST_SIZE := 64 |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 86 | else |
| 87 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256 |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 88 | MBEDTLS_MD_ID := MBEDTLS_MD_SHA256 |
| 89 | TPM_ALG_ID := TPM_ALG_SHA256 |
| 90 | TCG_DIGEST_SIZE := 32 |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 91 | endif |
| 92 | |
| 93 | ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa) |
| 94 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA |
| 95 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa) |
| 96 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA |
| 97 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa) |
| 98 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA |
| 99 | else |
| 100 | $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS") |
| 101 | endif |
| 102 | |
Sumit Garg | 392e4df | 2019-11-15 10:43:00 +0530 | [diff] [blame] | 103 | ifeq (${DECRYPTION_SUPPORT}, aes_gcm) |
| 104 | TF_MBEDTLS_USE_AES_GCM := 1 |
| 105 | else |
| 106 | TF_MBEDTLS_USE_AES_GCM := 0 |
| 107 | endif |
| 108 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 109 | # Needs to be set to drive mbed TLS configuration correctly |
| 110 | $(eval $(call add_define,TF_MBEDTLS_KEY_ALG_ID)) |
Justin Chadwell | f9b32c1 | 2019-07-29 17:13:10 +0100 | [diff] [blame] | 111 | $(eval $(call add_define,TF_MBEDTLS_KEY_SIZE)) |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 112 | $(eval $(call add_define,TF_MBEDTLS_HASH_ALG_ID)) |
Sumit Garg | 392e4df | 2019-11-15 10:43:00 +0530 | [diff] [blame] | 113 | $(eval $(call add_define,TF_MBEDTLS_USE_AES_GCM)) |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 114 | |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 115 | # Set definitions for measured boot driver |
| 116 | $(eval $(call add_define,MBEDTLS_MD_ID)) |
| 117 | $(eval $(call add_define,TPM_ALG_ID)) |
| 118 | $(eval $(call add_define,TCG_DIGEST_SIZE)) |
| 119 | |
Roberto Vargas | 502290b | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 120 | $(eval $(call MAKE_LIB,mbedtls)) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 121 | |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 122 | endif |