arm-trusted-firmware/drivers/auth/mbedtls/mbedtls_common.mk

128 lines
3.2 KiB
Makefile
Raw Normal View History

#
# Copyright (c) 2015-2022, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
ifneq (${MBEDTLS_COMMON_MK},1)
MBEDTLS_COMMON_MK := 1
# MBEDTLS_DIR must be set to the mbed TLS main directory (it must contain
# the 'include' and 'library' subdirectories).
ifeq (${MBEDTLS_DIR},)
$(error Error: MBEDTLS_DIR not set)
endif
MBEDTLS_INC = -I${MBEDTLS_DIR}/include
# Specify mbed TLS configuration file
MBEDTLS_CONFIG_FILE ?= "<drivers/auth/mbedtls/mbedtls_config.h>"
$(eval $(call add_define,MBEDTLS_CONFIG_FILE))
MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c
LIBMBEDTLS_SRCS := $(addprefix ${MBEDTLS_DIR}/library/, \
aes.c \
asn1parse.c \
asn1write.c \
cipher.c \
cipher_wrap.c \
memory_buffer_alloc.c \
oid.c \
platform.c \
platform_util.c \
bignum.c \
gcm.c \
md.c \
pk.c \
pk_wrap.c \
pkparse.c \
pkwrite.c \
sha256.c \
sha512.c \
ecdsa.c \
ecp_curves.c \
ecp.c \
rsa.c \
rsa_internal.c \
x509.c \
x509_crt.c \
build(deps): upgrade to mbed TLS 2.28.0 Upgrade to the latest and greatest 2.x release of Mbed TLS library (i.e. v2.28.0) to take advantage of their bug fixes. Note that the Mbed TLS project published version 3.x some time ago. However, as this is a major release with API breakages, upgrading to 3.x might require some more involved changes in TF-A, which we are not ready to do. We shall upgrade to mbed TLS 3.x after the v2.7 release of TF-A. Actually, the upgrade this time simply boils down to including the new source code module 'constant_time.c' into the firmware. To quote mbed TLS v2.28.0 release notes [1]: The mbedcrypto library includes a new source code module constant_time.c, containing various functions meant to resist timing side channel attacks. This module does not have a separate configuration option, and functions from this module will be included in the build as required. As a matter of fact, if one is attempting to link TF-A against mbed TLS v2.28.0 without the present patch, one gets some linker errors due to missing symbols from this new module. Apart from this, none of the items listed in mbed TLS release notes [1] directly affect TF-A. Special note on the following one: Fix a bug in mbedtls_gcm_starts() when the bit length of the iv exceeds 2^32. In TF-A, we do use mbedtls_gcm_starts() when the firmware decryption feature is enabled with AES-GCM as the authenticated decryption algorithm (DECRYPTION_SUPPORT=aes_gcm). However, the iv_len variable which gets passed to mbedtls_gcm_starts() is an unsigned int, i.e. a 32-bit value which by definition is always less than 2**32. Therefore, we are immune to this bug. With this upgrade, the size of BL1 and BL2 binaries does not appear to change on a standard sample test build (with trusted boot and measured boot enabled). [1] https://github.com/Mbed-TLS/mbedtls/releases/tag/v2.28.0 Change-Id: Icd5dbf527395e9e22c8fd6b77427188bd7237fd6 Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
2022-04-21 09:21:29 +01:00
constant_time.c \
)
# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
# algorithm to use. If the variable is not defined, select it based on
# algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined,
# then it is set to `rsa`.
ifeq (${TF_MBEDTLS_KEY_ALG},)
ifeq (${KEY_ALG}, ecdsa)
TF_MBEDTLS_KEY_ALG := ecdsa
else
TF_MBEDTLS_KEY_ALG := rsa
endif
endif
ifeq (${TF_MBEDTLS_KEY_SIZE},)
ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),)
ifeq (${KEY_SIZE},)
TF_MBEDTLS_KEY_SIZE := 2048
else
TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
endif
endif
endif
ifeq (${HASH_ALG}, sha384)
TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384
else ifeq (${HASH_ALG}, sha512)
TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512
else
TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256
endif
ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA
else ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA
else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA
else
$(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
endif
ifeq (${DECRYPTION_SUPPORT}, aes_gcm)
TF_MBEDTLS_USE_AES_GCM := 1
else
TF_MBEDTLS_USE_AES_GCM := 0
endif
ifeq ($(MEASURED_BOOT),1)
ifeq (${TPM_HASH_ALG}, sha256)
TF_MBEDTLS_TPM_HASH_ALG_ID := TF_MBEDTLS_SHA256
else ifeq (${TPM_HASH_ALG}, sha384)
TF_MBEDTLS_TPM_HASH_ALG_ID := TF_MBEDTLS_SHA384
else ifeq (${TPM_HASH_ALG}, sha512)
TF_MBEDTLS_TPM_HASH_ALG_ID := TF_MBEDTLS_SHA512
else
$(error "TPM_HASH_ALG not defined.")
endif
endif
# Needs to be set to drive mbed TLS configuration correctly
$(eval $(call add_defines,\
$(sort \
TF_MBEDTLS_KEY_ALG_ID \
TF_MBEDTLS_KEY_SIZE \
TF_MBEDTLS_HASH_ALG_ID \
TF_MBEDTLS_USE_AES_GCM \
)))
ifeq ($(MEASURED_BOOT),1)
$(eval $(call add_define,TF_MBEDTLS_TPM_HASH_ALG_ID))
endif
$(eval $(call MAKE_LIB,mbedtls))
endif