Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 1 | # |
dp-arm | 52b1fe5 | 2017-03-07 10:08:42 +0000 | [diff] [blame] | 2 | # Copyright (c) 2015-2017, 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 | include drivers/auth/mbedtls/mbedtls_common.mk |
| 8 | |
David Cunado | b101018 | 2017-05-08 09:48:34 +0100 | [diff] [blame] | 9 | # The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key |
Soby Mathew | 13b1605 | 2017-08-31 11:49:32 +0100 | [diff] [blame] | 10 | # algorithm to use. If the variable is not defined, select it based on algorithm |
| 11 | # used for key generation `KEY_ALG`. If `KEY_ALG` is not defined or is |
Soby Mathew | 2fd70f6 | 2017-08-31 11:50:29 +0100 | [diff] [blame] | 12 | # defined to `rsa`/`rsa_1_5`, then set the variable to `rsa`. |
David Cunado | b101018 | 2017-05-08 09:48:34 +0100 | [diff] [blame] | 13 | ifeq (${TF_MBEDTLS_KEY_ALG},) |
Soby Mathew | 13b1605 | 2017-08-31 11:49:32 +0100 | [diff] [blame] | 14 | ifeq (${KEY_ALG}, ecdsa) |
| 15 | TF_MBEDTLS_KEY_ALG := ecdsa |
| 16 | else |
| 17 | TF_MBEDTLS_KEY_ALG := rsa |
| 18 | endif |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 19 | endif |
| 20 | |
David Cunado | b101018 | 2017-05-08 09:48:34 +0100 | [diff] [blame] | 21 | # If MBEDTLS_KEY_ALG build flag is defined use it to set TF_MBEDTLS_KEY_ALG for |
| 22 | # backward compatibility |
| 23 | ifdef MBEDTLS_KEY_ALG |
| 24 | ifeq (${ERROR_DEPRECATED},1) |
| 25 | $(error "MBEDTLS_KEY_ALG is deprecated. Please use the new build flag TF_MBEDTLS_KEY_ALG") |
| 26 | endif |
| 27 | $(warning "MBEDTLS_KEY_ALG is deprecated. Please use the new build flag TF_MBEDTLS_KEY_ALG") |
| 28 | TF_MBEDTLS_KEY_ALG := ${MBEDTLS_KEY_ALG} |
| 29 | endif |
| 30 | |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 31 | MBEDTLS_CRYPTO_SOURCES := drivers/auth/mbedtls/mbedtls_crypto.c \ |
| 32 | $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 33 | bignum.c \ |
| 34 | md.c \ |
| 35 | md_wrap.c \ |
| 36 | pk.c \ |
| 37 | pk_wrap.c \ |
| 38 | pkparse.c \ |
| 39 | pkwrite.c \ |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 40 | ) |
| 41 | |
Qixiang Xu | 1a1f291 | 2017-11-09 13:56:29 +0800 | [diff] [blame] | 42 | ifeq (${HASH_ALG}, sha384) |
| 43 | MBEDTLS_CRYPTO_SOURCES += \ |
| 44 | $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 45 | sha256.c \ |
| 46 | sha512.c \ |
| 47 | ) |
| 48 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384 |
| 49 | else ifeq (${HASH_ALG}, sha512) |
| 50 | MBEDTLS_CRYPTO_SOURCES += \ |
| 51 | $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 52 | sha256.c \ |
| 53 | sha512.c \ |
| 54 | ) |
| 55 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512 |
| 56 | else |
| 57 | MBEDTLS_CRYPTO_SOURCES += \ |
| 58 | $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 59 | sha256.c \ |
| 60 | ) |
| 61 | TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256 |
| 62 | endif |
| 63 | |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 64 | # Key algorithm specific files |
Qixiang Xu | aa05eea | 2017-08-24 15:26:39 +0800 | [diff] [blame] | 65 | MBEDTLS_ECDSA_CRYPTO_SOURCES += $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 66 | ecdsa.c \ |
| 67 | ecp_curves.c \ |
| 68 | ecp.c \ |
| 69 | ) |
| 70 | |
| 71 | MBEDTLS_RSA_CRYPTO_SOURCES += $(addprefix ${MBEDTLS_DIR}/library/, \ |
| 72 | rsa.c \ |
| 73 | ) |
| 74 | |
David Cunado | b101018 | 2017-05-08 09:48:34 +0100 | [diff] [blame] | 75 | ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa) |
Qixiang Xu | aa05eea | 2017-08-24 15:26:39 +0800 | [diff] [blame] | 76 | MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_ECDSA_CRYPTO_SOURCES) |
David Cunado | c7a1b19 | 2017-05-10 16:38:44 +0100 | [diff] [blame] | 77 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA |
David Cunado | b101018 | 2017-05-08 09:48:34 +0100 | [diff] [blame] | 78 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa) |
Qixiang Xu | aa05eea | 2017-08-24 15:26:39 +0800 | [diff] [blame] | 79 | MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_RSA_CRYPTO_SOURCES) |
David Cunado | c7a1b19 | 2017-05-10 16:38:44 +0100 | [diff] [blame] | 80 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA |
Qixiang Xu | aa05eea | 2017-08-24 15:26:39 +0800 | [diff] [blame] | 81 | else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa) |
| 82 | MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_ECDSA_CRYPTO_SOURCES) |
| 83 | MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_RSA_CRYPTO_SOURCES) |
| 84 | TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 85 | else |
David Cunado | b101018 | 2017-05-08 09:48:34 +0100 | [diff] [blame] | 86 | $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS") |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 87 | endif |
| 88 | |
dp-arm | 52b1fe5 | 2017-03-07 10:08:42 +0000 | [diff] [blame] | 89 | # Needs to be set to drive mbed TLS configuration correctly |
David Cunado | c7a1b19 | 2017-05-10 16:38:44 +0100 | [diff] [blame] | 90 | $(eval $(call add_define,TF_MBEDTLS_KEY_ALG_ID)) |
Qixiang Xu | 1a1f291 | 2017-11-09 13:56:29 +0800 | [diff] [blame] | 91 | $(eval $(call add_define,TF_MBEDTLS_HASH_ALG_ID)) |