blob: 4b83015417b1c3ed1b1b8c8b7938d4bae5d4fce6 [file] [log] [blame]
Juan Castilloa57a4d52015-04-02 15:44:20 +01001#
Justin Chadwellf9b32c12019-07-29 17:13:10 +01002# Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
Juan Castilloa57a4d52015-04-02 15:44:20 +01003#
dp-armfa3cf0b2017-05-03 09:38:09 +01004# SPDX-License-Identifier: BSD-3-Clause
Juan Castilloa57a4d52015-04-02 15:44:20 +01005#
6
7ifneq (${MBEDTLS_COMMON_MK},1)
8MBEDTLS_COMMON_MK := 1
9
Juan Castillobae6b2a2015-11-05 09:24:53 +000010# MBEDTLS_DIR must be set to the mbed TLS main directory (it must contain
Juan Castilloa57a4d52015-04-02 15:44:20 +010011# the 'include' and 'library' subdirectories).
12ifeq (${MBEDTLS_DIR},)
13 $(error Error: MBEDTLS_DIR not set)
14endif
15
Roberto Vargasd51207e2018-06-04 15:15:04 +010016MBEDTLS_INC = -I${MBEDTLS_DIR}/include
Juan Castilloa57a4d52015-04-02 15:44:20 +010017
Juan Castillobae6b2a2015-11-05 09:24:53 +000018# Specify mbed TLS configuration file
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000019MBEDTLS_CONFIG_FILE := "<drivers/auth/mbedtls/mbedtls_config.h>"
Juan Castillobae6b2a2015-11-05 09:24:53 +000020$(eval $(call add_define,MBEDTLS_CONFIG_FILE))
Juan Castilloa57a4d52015-04-02 15:44:20 +010021
Roberto Vargas502290b2018-05-08 10:27:10 +010022MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c
23
24
25LIBMBEDTLS_SRCS := $(addprefix ${MBEDTLS_DIR}/library/, \
26 asn1parse.c \
27 asn1write.c \
28 memory_buffer_alloc.c \
29 oid.c \
30 platform.c \
31 platform_util.c \
32 bignum.c \
33 md.c \
34 md_wrap.c \
35 pk.c \
36 pk_wrap.c \
37 pkparse.c \
38 pkwrite.c \
39 sha256.c \
40 sha512.c \
41 ecdsa.c \
42 ecp_curves.c \
43 ecp.c \
44 rsa.c \
45 rsa_internal.c \
46 x509.c \
47 x509_crt.c \
48 )
49
50# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key
Justin Chadwell3168a202019-09-09 15:24:31 +010051# algorithm to use. If the variable is not defined, select it based on
52# algorithm used for key generation `KEY_ALG`. If `KEY_ALG` is not defined,
53# then it is set to `rsa`.
Roberto Vargas502290b2018-05-08 10:27:10 +010054ifeq (${TF_MBEDTLS_KEY_ALG},)
55 ifeq (${KEY_ALG}, ecdsa)
56 TF_MBEDTLS_KEY_ALG := ecdsa
57 else
58 TF_MBEDTLS_KEY_ALG := rsa
59 endif
60endif
61
Justin Chadwellf9b32c12019-07-29 17:13:10 +010062ifeq (${TF_MBEDTLS_KEY_SIZE},)
63 ifneq ($(findstring rsa,${TF_MBEDTLS_KEY_ALG}),)
64 ifeq (${KEY_SIZE},)
65 TF_MBEDTLS_KEY_SIZE := 2048
66 else
67 TF_MBEDTLS_KEY_SIZE := ${KEY_SIZE}
68 endif
69 endif
70endif
71
Roberto Vargas502290b2018-05-08 10:27:10 +010072ifeq (${HASH_ALG}, sha384)
73 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384
74else ifeq (${HASH_ALG}, sha512)
75 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512
76else
77 TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256
78endif
79
80ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa)
81 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA
82else ifeq (${TF_MBEDTLS_KEY_ALG},rsa)
83 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA
84else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa)
85 TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA
86else
87 $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS")
88endif
89
90# Needs to be set to drive mbed TLS configuration correctly
91$(eval $(call add_define,TF_MBEDTLS_KEY_ALG_ID))
Justin Chadwellf9b32c12019-07-29 17:13:10 +010092$(eval $(call add_define,TF_MBEDTLS_KEY_SIZE))
Roberto Vargas502290b2018-05-08 10:27:10 +010093$(eval $(call add_define,TF_MBEDTLS_HASH_ALG_ID))
94
95
96$(eval $(call MAKE_LIB,mbedtls))
Juan Castilloa57a4d52015-04-02 15:44:20 +010097
Juan Castilloa57a4d52015-04-02 15:44:20 +010098endif