diff --git a/docs/auth-framework.rst b/docs/auth-framework.rst index 765d9f89b98f541f4b23373fda8a3daa1e3ce230..3a054c7fb915c3587eac7cdb87a3adb2f81837a0 100644 --- a/docs/auth-framework.rst +++ b/docs/auth-framework.rst @@ -921,9 +921,12 @@ three functions: int verify_hash(void *data_ptr, unsigned int data_len, void *digest_info_ptr, unsigned int digest_info_len); -The key algorithm (rsa, ecdsa) must be specified in the build system using the -``TF_MBEDTLS_KEY_ALG`` variable, so the Makefile can include the corresponding -sources in the build. +The mbedTLS library algorithm support is configured by the +``TF_MBEDTLS_KEY_ALG`` variable which can take in 3 values: `rsa`, `ecdsa` or +`rsa+ecdsa`. This variable allows the Makefile to include the corresponding +sources in the build for the various algorthms. Setting the variable to +`rsa+ecdsa` enables support for both rsa and ecdsa algorithms in the mbedTLS +library. Note: If code size is a concern, the build option ``MBEDTLS_SHA256_SMALLER`` can be defined in the platform Makefile. It will make mbed TLS use an implementation @@ -931,7 +934,7 @@ of SHA-256 with smaller memory footprint (~1.5 KB less) but slower (~30%). -------------- -*Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.* +*Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.* .. _Trusted Board Boot: ./trusted-board-boot.rst .. _Platform Porting Guide: ./porting-guide.rst diff --git a/docs/user-guide.rst b/docs/user-guide.rst index 1ff080d7343ed3702b5fadaaca470e11fa6b1342..67af42562c04a63b3c5635a5086bb49b714f872d 100644 --- a/docs/user-guide.rst +++ b/docs/user-guide.rst @@ -643,6 +643,11 @@ ARM development platform specific build options ``arm_rotpk_rsa.der``, located in ``plat/arm/board/common/rotpk``. To use this option, ``arm_rotprivk_rsa.pem`` must be specified as ``ROT_KEY`` when creating the certificates. + - ``devel_ecdsa`` : return a development public key hash embedded in the BL1 + and BL2 binaries. This hash has been obtained from the ECDSA public key + ``arm_rotpk_ecdsa.der``, located in ``plat/arm/board/common/rotpk``. To use + this option, ``arm_rotprivk_ecdsa.pem`` must be specified as ``ROT_KEY`` + when creating the certificates. - ``ARM_TSP_RAM_LOCATION``: location of the TSP binary. Options: @@ -990,6 +995,10 @@ images with support for these features: in the ARM platform port. The private/public RSA key pair may be found in ``plat/arm/board/common/rotpk``. + - ``ARM_ROTPK_LOCATION=devel_ecdsa``: use the ROTPK hash that is hardcoded + in the ARM platform port. The private/public ECDSA key pair may be + found in ``plat/arm/board/common/rotpk``. + Example of command line using RSA development keys: :: diff --git a/drivers/auth/mbedtls/mbedtls_common.c b/drivers/auth/mbedtls/mbedtls_common.c index e9aa409b5f81c13878f93dded92697f877870e33..205c2432afd404cf55e2a5de0a68371f00864192 100644 --- a/drivers/auth/mbedtls/mbedtls_common.c +++ b/drivers/auth/mbedtls/mbedtls_common.c @@ -14,8 +14,9 @@ /* * mbed TLS heap */ -#if (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA) -#define MBEDTLS_HEAP_SIZE (14*1024) +#if (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA) \ + || (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA) +#define MBEDTLS_HEAP_SIZE (13*1024) #elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA) #define MBEDTLS_HEAP_SIZE (7*1024) #endif diff --git a/drivers/auth/mbedtls/mbedtls_crypto.mk b/drivers/auth/mbedtls/mbedtls_crypto.mk index 21b857bffe4a3465daaee700776674cdbce20165..d6fc7eb53ecfebea3b56e51e8d620bd523b64908 100644 --- a/drivers/auth/mbedtls/mbedtls_crypto.mk +++ b/drivers/auth/mbedtls/mbedtls_crypto.mk @@ -41,18 +41,26 @@ MBEDTLS_CRYPTO_SOURCES := drivers/auth/mbedtls/mbedtls_crypto.c \ ) # Key algorithm specific files +MBEDTLS_ECDSA_CRYPTO_SOURCES += $(addprefix ${MBEDTLS_DIR}/library/, \ + ecdsa.c \ + ecp_curves.c \ + ecp.c \ + ) + +MBEDTLS_RSA_CRYPTO_SOURCES += $(addprefix ${MBEDTLS_DIR}/library/, \ + rsa.c \ + ) + ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa) - MBEDTLS_CRYPTO_SOURCES += $(addprefix ${MBEDTLS_DIR}/library/, \ - ecdsa.c \ - ecp_curves.c \ - ecp.c \ - ) + MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_ECDSA_CRYPTO_SOURCES) TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA else ifeq (${TF_MBEDTLS_KEY_ALG},rsa) - MBEDTLS_CRYPTO_SOURCES += $(addprefix ${MBEDTLS_DIR}/library/, \ - rsa.c \ - ) + MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_RSA_CRYPTO_SOURCES) TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA +else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa) + MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_ECDSA_CRYPTO_SOURCES) + MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_RSA_CRYPTO_SOURCES) + 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 diff --git a/include/drivers/auth/mbedtls/mbedtls_config.h b/include/drivers/auth/mbedtls/mbedtls_config.h index fdeb52bb6a9d4b67dd92dadd000fc2e9d22ac393..ca2d9fad8d1f9da6b3b7c3e4d9777b129f90440e 100644 --- a/include/drivers/auth/mbedtls/mbedtls_config.h +++ b/include/drivers/auth/mbedtls/mbedtls_config.h @@ -9,8 +9,9 @@ /* * Key algorithms currently supported on mbed TLS libraries */ -#define TF_MBEDTLS_RSA 1 -#define TF_MBEDTLS_ECDSA 2 +#define TF_MBEDTLS_RSA 1 +#define TF_MBEDTLS_ECDSA 2 +#define TF_MBEDTLS_RSA_AND_ECDSA 3 /* * Configuration file to build mbed TLS with the required features for @@ -30,7 +31,6 @@ #define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION #define MBEDTLS_X509_CHECK_KEY_USAGE #define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE -#define MBEDTLS_X509_RSASSA_PSS_SUPPORT #define MBEDTLS_ASN1_PARSE_C #define MBEDTLS_ASN1_WRITE_C @@ -56,6 +56,13 @@ #define MBEDTLS_ECP_DP_SECP256R1_ENABLED #elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA) #define MBEDTLS_RSA_C +#define MBEDTLS_X509_RSASSA_PSS_SUPPORT +#elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA) +#define MBEDTLS_RSA_C +#define MBEDTLS_X509_RSASSA_PSS_SUPPORT +#define MBEDTLS_ECDSA_C +#define MBEDTLS_ECP_C +#define MBEDTLS_ECP_DP_SECP256R1_ENABLED #endif #define MBEDTLS_SHA256_C diff --git a/include/plat/arm/board/common/board_arm_def.h b/include/plat/arm/board/common/board_arm_def.h index 751c3bb10fbd94b3b44aa26248e3dc2de2013289..4d145005d26e9f5a97e5679df13d29f9a2c1e7d1 100644 --- a/include/plat/arm/board/common/board_arm_def.h +++ b/include/plat/arm/board/common/board_arm_def.h @@ -64,7 +64,7 @@ * PLAT_ARM_MAX_BL1_RW_SIZE is calculated using the current BL1 RW debug size * plus a little space for growth. */ -#define PLAT_ARM_MAX_BL1_RW_SIZE 0xA000 +#define PLAT_ARM_MAX_BL1_RW_SIZE 0xB000 /* * PLAT_ARM_MAX_BL2_SIZE is calculated using the current BL2 debug size plus a diff --git a/plat/arm/board/common/board_arm_trusted_boot.c b/plat/arm/board/common/board_arm_trusted_boot.c index 5d36d1780ef1f7a020ba81d56a655d5e82feeabe..6c03c91b5df8b727d2a98147270ae67dba59e820 100644 --- a/plat/arm/board/common/board_arm_trusted_boot.c +++ b/plat/arm/board/common/board_arm_trusted_boot.c @@ -18,6 +18,7 @@ /* ROTPK locations */ #define ARM_ROTPK_REGS_ID 1 #define ARM_ROTPK_DEVEL_RSA_ID 2 +#define ARM_ROTPK_DEVEL_ECDSA_ID 3 static const unsigned char rotpk_hash_hdr[] = \ "\x30\x31\x30\x0D\x06\x09\x60\x86\x48" \ @@ -41,6 +42,12 @@ static const unsigned char arm_devel_rotpk_hash[] = \ "\x37\x7A\x72\x47\x1B\xEC\x32\x73" \ "\xE9\x92\x32\xE2\x49\x59\xF6\x5E" \ "\x8B\x4A\x4A\x46\xD8\x22\x9A\xDA"; +#elif (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_ECDSA_ID) +static const unsigned char arm_devel_rotpk_hash[] = \ + "\x2E\x40\xBF\x6E\xF9\x12\xBB\x98" \ + "\x31\x71\x09\x0E\x1E\x15\x3D\x0B" \ + "\xFD\xD1\xCC\x69\x4A\x98\xEB\x8B" \ + "\xA0\xB0\x20\x86\x4E\x6C\x07\x17"; #endif /* @@ -69,7 +76,8 @@ int plat_get_rotpk_info(void *cookie, void **key_ptr, unsigned int *key_len, memcpy(rotpk_hash_der, rotpk_hash_hdr, rotpk_hash_hdr_len); dst = (uint8_t *)&rotpk_hash_der[rotpk_hash_hdr_len]; -#if (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_RSA_ID) +#if (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_RSA_ID) \ + || (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_ECDSA_ID) memcpy(dst, arm_devel_rotpk_hash, SHA256_BYTES); #elif (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_REGS_ID) uint32_t *src, tmp; @@ -121,7 +129,8 @@ int plat_get_rotpk_info(void *cookie, void **key_ptr, unsigned int *key_len, *dst++ = (uint8_t)((tmp >> 8) & 0xFF); *dst++ = (uint8_t)(tmp & 0xFF); } -#endif /* (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_RSA_ID) */ +#endif /* (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_RSA_ID) \ + || (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_ECDSA_ID) */ *key_ptr = (void *)rotpk_hash_der; *key_len = (unsigned int)sizeof(rotpk_hash_der); diff --git a/plat/arm/board/common/board_common.mk b/plat/arm/board/common/board_common.mk index 46672982c3f3dd65679ae78f12e6529ff03f7961..643047ce77c102623e78be655c3f97d637206063 100644 --- a/plat/arm/board/common/board_common.mk +++ b/plat/arm/board/common/board_common.mk @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. +# Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -22,7 +22,11 @@ ifneq (${TRUSTED_BOARD_BOOT},0) ifeq (${ARM_ROTPK_LOCATION}, regs) ARM_ROTPK_LOCATION_ID = ARM_ROTPK_REGS_ID else ifeq (${ARM_ROTPK_LOCATION}, devel_rsa) + KEY_ALG := rsa ARM_ROTPK_LOCATION_ID = ARM_ROTPK_DEVEL_RSA_ID + else ifeq (${ARM_ROTPK_LOCATION}, devel_ecdsa) + KEY_ALG := ecdsa + ARM_ROTPK_LOCATION_ID = ARM_ROTPK_DEVEL_ECDSA_ID else $(error "Unsupported ARM_ROTPK_LOCATION value") endif diff --git a/plat/arm/board/common/rotpk/arm_rotpk_ecdsa.der b/plat/arm/board/common/rotpk/arm_rotpk_ecdsa.der new file mode 100644 index 0000000000000000000000000000000000000000..254787720cfd07278a7dd446f9feec5e06f1d431 Binary files /dev/null and b/plat/arm/board/common/rotpk/arm_rotpk_ecdsa.der differ diff --git a/plat/arm/board/common/rotpk/arm_rotpk_ecdsa_sha256.bin b/plat/arm/board/common/rotpk/arm_rotpk_ecdsa_sha256.bin new file mode 100644 index 0000000000000000000000000000000000000000..c5e123abb328f815a68fe9dce929660dc910ce69 --- /dev/null +++ b/plat/arm/board/common/rotpk/arm_rotpk_ecdsa_sha256.bin @@ -0,0 +1 @@ +.@¿nù»˜1q =ýÑÌiJ˜ë‹ ° †Nl \ No newline at end of file diff --git a/plat/arm/board/common/rotpk/arm_rotprivk_ecdsa.pem b/plat/arm/board/common/rotpk/arm_rotprivk_ecdsa.pem new file mode 100644 index 0000000000000000000000000000000000000000..fb328e3cdf1758179c37feaffe206a0df6d57aad --- /dev/null +++ b/plat/arm/board/common/rotpk/arm_rotprivk_ecdsa.pem @@ -0,0 +1,5 @@ +-----BEGIN EC PRIVATE KEY----- +MHcCAQEEINSaX6nvzS3teiBJA7WlTLRKJOajpy29o2cArLbUXoZBoAoGCCqGSM49 +AwEHoUQDQgAEm+ZIvTQ44aKk83DhVLsvsFpKDP/Ch9vA+4Hp+fmVfX6gDH8K1OBi +SpRf7FJ9RGPIn2H6xst+a1OtLMWUDRqGkQ== +-----END EC PRIVATE KEY----- diff --git a/plat/arm/board/juno/include/platform_def.h b/plat/arm/board/juno/include/platform_def.h index f1714e137e8e570fe77dee9226a122da864d4b82..7794af550ad11580863eb8f0f931eb9e40a297dd 100644 --- a/plat/arm/board/juno/include/platform_def.h +++ b/plat/arm/board/juno/include/platform_def.h @@ -96,7 +96,7 @@ * plus a little space for growth. */ #if TRUSTED_BOARD_BOOT -# define PLAT_ARM_MAX_BL1_RW_SIZE 0x9000 +# define PLAT_ARM_MAX_BL1_RW_SIZE 0xA000 #else # define PLAT_ARM_MAX_BL1_RW_SIZE 0x6000 #endif @@ -106,7 +106,7 @@ * little space for growth. */ #if TRUSTED_BOARD_BOOT -# define PLAT_ARM_MAX_BL2_SIZE 0x18000 +# define PLAT_ARM_MAX_BL2_SIZE 0x19000 #else # define PLAT_ARM_MAX_BL2_SIZE 0xC000 #endif @@ -114,8 +114,12 @@ /* * PLAT_ARM_MAX_BL31_SIZE is calculated using the current BL31 debug size plus a * little space for growth. + * SCP_BL2 image is loaded into the space BL31 -> BL1_RW_BASE. + * For TBB use case, PLAT_ARM_MAX_BL1_RW_SIZE has been increased and therefore + * PLAT_ARM_MAX_BL31_SIZE has been increased to ensure SCP_BL2 has the same + * space available. */ -#define PLAT_ARM_MAX_BL31_SIZE 0x1D000 +#define PLAT_ARM_MAX_BL31_SIZE 0x1E000 /* * Since free SRAM space is scant, enable the ASSERTION message size diff --git a/plat/arm/board/juno/platform.mk b/plat/arm/board/juno/platform.mk index 79916cdadef167f8b438baf65202a51f0218e4bc..5cd125bff07f9b2b391916f34468dc2403c66ba5 100644 --- a/plat/arm/board/juno/platform.mk +++ b/plat/arm/board/juno/platform.mk @@ -91,6 +91,3 @@ include plat/arm/common/arm_common.mk include plat/arm/soc/common/soc_css.mk include plat/arm/css/common/css_common.mk -ifeq (${KEY_ALG},ecdsa) - $(error "ECDSA key algorithm is not fully supported on Juno.") -endif