From 9fc299a1ccea216d51be967f27440e3d69349baa Mon Sep 17 00:00:00 2001 From: Kostiantyn Tkachov Date: Thu, 12 Sep 2019 01:30:54 +0200 Subject: [PATCH] Updated mbedTLS CRYPTO target to be more flexibly configured for supported boards --- .../TARGET_MXCRYPTO_01}/sha1_alt.h | 0 .../TARGET_MXCRYPTO_01}/sha256_alt.h | 0 .../TARGET_MXCRYPTO_01}/sha512_alt.h | 0 .../TARGET_MXCRYPTO_02}/sha1_alt.h | 0 .../TARGET_MXCRYPTO_02}/sha256_alt.h | 0 .../TARGET_MXCRYPTO_02}/sha512_alt.h | 0 .../{TARGET_PSOC6 => TARGET_MXCRYPTO}/aes_alt.c | 8 +++++--- .../{TARGET_PSOC6 => TARGET_MXCRYPTO}/aes_alt.h | 0 .../crypto_common.c | 2 +- .../crypto_common.h | 0 .../{TARGET_PSOC6 => TARGET_MXCRYPTO}/ecdsa_alt.c | 0 .../{TARGET_PSOC6 => TARGET_MXCRYPTO}/ecp_alt.c | 10 ++++++++++ .../{TARGET_PSOC6 => TARGET_MXCRYPTO}/ecp_alt.h | 0 .../ecp_curves_alt.c | 0 .../mbedtls_device.h | 0 .../{TARGET_PSOC6 => TARGET_MXCRYPTO}/sha1_alt.c | 4 ++-- .../{TARGET_PSOC6 => TARGET_MXCRYPTO}/sha256_alt.c | 4 ++-- .../{TARGET_PSOC6 => TARGET_MXCRYPTO}/sha512_alt.c | 4 ++-- targets/targets.json | 13 +++++++++---- 19 files changed, 31 insertions(+), 14 deletions(-) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6/TARGET_PSOC6_01 => TARGET_MXCRYPTO/TARGET_MXCRYPTO_01}/sha1_alt.h (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6/TARGET_PSOC6_01 => TARGET_MXCRYPTO/TARGET_MXCRYPTO_01}/sha256_alt.h (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6/TARGET_PSOC6_01 => TARGET_MXCRYPTO/TARGET_MXCRYPTO_01}/sha512_alt.h (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6/TARGET_PSOC6_02 => TARGET_MXCRYPTO/TARGET_MXCRYPTO_02}/sha1_alt.h (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6/TARGET_PSOC6_02 => TARGET_MXCRYPTO/TARGET_MXCRYPTO_02}/sha256_alt.h (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6/TARGET_PSOC6_02 => TARGET_MXCRYPTO/TARGET_MXCRYPTO_02}/sha512_alt.h (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/aes_alt.c (99%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/aes_alt.h (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/crypto_common.c (98%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/crypto_common.h (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/ecdsa_alt.c (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/ecp_alt.c (99%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/ecp_alt.h (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/ecp_curves_alt.c (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/mbedtls_device.h (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/sha1_alt.c (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/sha256_alt.c (100%) rename features/mbedtls/targets/TARGET_Cypress/{TARGET_PSOC6 => TARGET_MXCRYPTO}/sha512_alt.c (100%) diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_01/sha1_alt.h b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_01/sha1_alt.h similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_01/sha1_alt.h rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_01/sha1_alt.h diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_01/sha256_alt.h b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_01/sha256_alt.h similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_01/sha256_alt.h rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_01/sha256_alt.h diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_01/sha512_alt.h b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_01/sha512_alt.h similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_01/sha512_alt.h rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_01/sha512_alt.h diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_02/sha1_alt.h b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_02/sha1_alt.h similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_02/sha1_alt.h rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_02/sha1_alt.h diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_02/sha256_alt.h b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_02/sha256_alt.h similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_02/sha256_alt.h rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_02/sha256_alt.h diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_02/sha512_alt.h b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_02/sha512_alt.h similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_PSOC6_02/sha512_alt.h rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/TARGET_MXCRYPTO_02/sha512_alt.h diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/aes_alt.c b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/aes_alt.c similarity index 99% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/aes_alt.c rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/aes_alt.c index d234d22aa0..aacad6e48c 100644 --- a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/aes_alt.c +++ b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/aes_alt.c @@ -44,14 +44,14 @@ #include "mbedtls/platform.h" #include "mbedtls/platform_util.h" +#if defined(MBEDTLS_AES_ALT) + /* Parameter validation macros based on platform_util.h */ #define AES_VALIDATE_RET( cond ) \ MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_AES_BAD_INPUT_DATA ) #define AES_VALIDATE( cond ) \ MBEDTLS_INTERNAL_VALIDATE( cond ) -#if defined(MBEDTLS_AES_ALT) - #include "crypto_common.h" #include "cy_crypto_core.h" @@ -107,7 +107,9 @@ static int aes_set_keys( mbedtls_aes_context *ctx, const unsigned char *key, cy_en_crypto_aes_key_length_t key_length; cy_en_crypto_status_t status; - AES_VALIDATE( ctx != NULL ); + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( key != NULL ); + switch( keybits ) { diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/aes_alt.h b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/aes_alt.h similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/aes_alt.h rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/aes_alt.h diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/crypto_common.c b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/crypto_common.c similarity index 98% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/crypto_common.c rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/crypto_common.c index 4f7cc3becc..292cd7c468 100644 --- a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/crypto_common.c +++ b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/crypto_common.c @@ -168,5 +168,5 @@ void cy_hw_sha_clone( void *ctxDst, const void *ctxSrc, uint32_t ctxSize, CY_CRYPTO_CHECK_PARAM( shaBuffersDst != NULL ); Cy_Crypto_Core_MemCpy(((cy_hw_crypto_t *)ctxSrc)->base, ctxDst, ctxSrc, (uint16_t)ctxSize); - Cy_Crypto_Core_Sha_Init(((cy_hw_crypto_t *)ctxSrc)->base, hashStateDst, hashStateDst->mode, shaBuffersDst); + Cy_Crypto_Core_Sha_Init(((cy_hw_crypto_t *)ctxSrc)->base, hashStateDst, (cy_en_crypto_sha_mode_t)hashStateDst->mode, shaBuffersDst); } diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/crypto_common.h b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/crypto_common.h similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/crypto_common.h rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/crypto_common.h diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/ecdsa_alt.c b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/ecdsa_alt.c similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/ecdsa_alt.c rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/ecdsa_alt.c diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/ecp_alt.c b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/ecp_alt.c similarity index 99% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/ecp_alt.c rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/ecp_alt.c index 811363adb7..715cf98328 100644 --- a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/ecp_alt.c +++ b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/ecp_alt.c @@ -2669,21 +2669,31 @@ cy_en_crypto_ecc_curve_id_t cy_get_dp_idx(mbedtls_ecp_group_id gid) switch( gid ) { + #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) case MBEDTLS_ECP_DP_SECP192R1: dp_idx = CY_CRYPTO_ECC_ECP_SECP192R1; break; + #endif /* defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) */ + #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) case MBEDTLS_ECP_DP_SECP224R1: dp_idx = CY_CRYPTO_ECC_ECP_SECP224R1; break; + #endif /* defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) */ + #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) case MBEDTLS_ECP_DP_SECP256R1: dp_idx = CY_CRYPTO_ECC_ECP_SECP256R1; break; + #endif /* defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) */ + #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) case MBEDTLS_ECP_DP_SECP384R1: dp_idx = CY_CRYPTO_ECC_ECP_SECP384R1; break; + #endif /* defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) */ + #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) case MBEDTLS_ECP_DP_SECP521R1: dp_idx = CY_CRYPTO_ECC_ECP_SECP521R1; break; + #endif /* defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) */ default: dp_idx = CY_CRYPTO_ECC_ECP_NONE; diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/ecp_alt.h b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/ecp_alt.h similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/ecp_alt.h rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/ecp_alt.h diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/ecp_curves_alt.c b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/ecp_curves_alt.c similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/ecp_curves_alt.c rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/ecp_curves_alt.c diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/mbedtls_device.h b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/mbedtls_device.h similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/mbedtls_device.h rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/mbedtls_device.h diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha1_alt.c b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/sha1_alt.c similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha1_alt.c rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/sha1_alt.c index 7fb5b7404b..cdc4811a91 100644 --- a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha1_alt.c +++ b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/sha1_alt.c @@ -39,13 +39,13 @@ #include +#if defined(MBEDTLS_SHA1_ALT) + /* Parameter validation macros based on platform_util.h */ #define SHA1_VALIDATE_RET(cond) \ MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA1_BAD_INPUT_DATA ) #define SHA1_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond ) -#if defined(MBEDTLS_SHA1_ALT) - void mbedtls_sha1_init( mbedtls_sha1_context *ctx ) { SHA1_VALIDATE( ctx != NULL ); diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha256_alt.c b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/sha256_alt.c similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha256_alt.c rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/sha256_alt.c index f3c27ecd7a..cd11a257bc 100644 --- a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha256_alt.c +++ b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/sha256_alt.c @@ -38,13 +38,13 @@ #include +#if defined(MBEDTLS_SHA256_ALT) + /* Parameter validation macros based on platform_util.h */ #define SHA256_VALIDATE_RET(cond) \ MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA256_BAD_INPUT_DATA ) #define SHA256_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond ) -#if defined(MBEDTLS_SHA256_ALT) - void mbedtls_sha256_init( mbedtls_sha256_context *ctx ) { SHA256_VALIDATE( ctx != NULL ); diff --git a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha512_alt.c b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/sha512_alt.c similarity index 100% rename from features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha512_alt.c rename to features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/sha512_alt.c index 74de3b9c8b..f3dae2cb12 100644 --- a/features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha512_alt.c +++ b/features/mbedtls/targets/TARGET_Cypress/TARGET_MXCRYPTO/sha512_alt.c @@ -38,13 +38,13 @@ #include +#if defined(MBEDTLS_SHA512_ALT) + /* Parameter validation macros based on platform_util.h */ #define SHA512_VALIDATE_RET(cond) \ MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA512_BAD_INPUT_DATA ) #define SHA512_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond ) -#if defined(MBEDTLS_SHA512_ALT) - void mbedtls_sha512_init( mbedtls_sha512_context *ctx ) { SHA512_VALIDATE( ctx != NULL ); diff --git a/targets/targets.json b/targets/targets.json index 56893503c2..7f5d4098ad 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -8844,7 +8844,7 @@ "WATCHDOG" ], "release_versions": ["5"], - "extra_labels": ["Cypress", "PSOC6"], + "extra_labels": ["Cypress", "PSOC6", "MXCRYPTO"], "components_add": ["SOFTFP", "RTX"], "public": false, "overrides" : { @@ -8869,6 +8869,7 @@ "device_has_remove": ["ANALOGOUT"], "extra_labels_add": [ "PSOC6_02", + "MXCRYPTO_02", "CM0P_SLEEP", "WHD", "4343W", @@ -8887,6 +8888,7 @@ "device_has_remove": ["ANALOGOUT"], "extra_labels_add": [ "PSOC6_02", + "MXCRYPTO_02", "CM0P_SLEEP", "WHD", "43012", @@ -8905,6 +8907,7 @@ "supported_form_factors": ["ARDUINO"], "extra_labels_add": [ "PSOC6_01", + "MXCRYPTO_01", "CM0P_SLEEP", "WHD", "4343W", @@ -8946,6 +8949,7 @@ "supported_form_factors": ["ARDUINO"], "extra_labels_add": [ "PSOC6_01", + "MXCRYPTO_01", "CM0P_SLEEP" ], "macros_add": ["CY8C6347BZI_BLD53"], @@ -8961,7 +8965,7 @@ "components_remove": ["QSPIF"], "device_has_remove": ["QSPI"], "supported_form_factors": ["ARDUINO"], - "extra_labels_add": ["PSOC6_01"], + "extra_labels_add": ["PSOC6_01", "MXCRYPTO_01"], "macros_add": ["CYB06447BZI_D54", "PSOC6_DYNSRM_DISABLE=1", "CY_CFG_SYSCLK_WCO_ENABLED=1", @@ -8978,6 +8982,7 @@ "features": ["BLE"], "extra_labels_add": [ "PSOC6_01", + "MXCRYPTO_01", "CM0P_SLEEP", "WHD", "43012", @@ -8997,7 +9002,7 @@ "inherits": ["MCU_PSOC6_M0"], "supported_form_factors": ["ARDUINO"], "extra_labels_add": ["PSOC6_FUTURE", "CY8C63XX", "FUTURE_SEQUANA"], - "extra_labels_remove": ["PSOC6"], + "extra_labels_remove": ["PSOC6", "MXCRYPTO"], "device_has_remove": ["TRNG", "CRC", "I2CSLAVE", "USBDEVICE", "QSPI", "WATCHDOG"], "macros_add": ["CY8C6347BZI_BLD53"], "macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"], @@ -9031,7 +9036,7 @@ "supported_form_factors": ["ARDUINO"], "components_remove": ["QSPIF"], "extra_labels_add": ["PSOC6_FUTURE", "CY8C63XX", "CORDIO"], - "extra_labels_remove": ["PSOC6"], + "extra_labels_remove": ["PSOC6", "MXCRYPTO"], "device_has_remove": ["TRNG", "CRC", "I2CSLAVE", "USBDEVICE", "QSPI", "WATCHDOG"], "macros_add": ["CY8C6347BZI_BLD53"], "macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"],