From aa09e7d409e00b8b51dc272b403c945d0193c31d Mon Sep 17 00:00:00 2001 From: jeromecoutant Date: Mon, 30 Mar 2020 14:14:36 +0200 Subject: [PATCH] STM32 MBEDTLS: Keep specific STM32L4 implementation --- .../aes_alt.c => aes_alt_stm32l4.c} | 21 +++++++++---------- .../aes_alt.h => aes_alt_stm32l4.h} | 8 ++++--- 2 files changed, 15 insertions(+), 14 deletions(-) rename features/mbedtls/targets/TARGET_STM/{TARGET_STM32L4/aes_alt.c => aes_alt_stm32l4.c} (95%) rename features/mbedtls/targets/TARGET_STM/{TARGET_STM32L4/aes_alt.h => aes_alt_stm32l4.h} (98%) diff --git a/features/mbedtls/targets/TARGET_STM/TARGET_STM32L4/aes_alt.c b/features/mbedtls/targets/TARGET_STM/aes_alt_stm32l4.c similarity index 95% rename from features/mbedtls/targets/TARGET_STM/TARGET_STM32L4/aes_alt.c rename to features/mbedtls/targets/TARGET_STM/aes_alt_stm32l4.c index fcaadb685a..56ec6174ef 100644 --- a/features/mbedtls/targets/TARGET_STM/TARGET_STM32L4/aes_alt.c +++ b/features/mbedtls/targets/TARGET_STM/aes_alt_stm32l4.c @@ -1,5 +1,5 @@ /* - * Hardware aes implementation for STM32F4 STM32F7 and STM32L4 families + * Hardware AES implementation for STM32L4 family ******************************************************************************* * Copyright (c) 2017, STMicroelectronics * SPDX-License-Identifier: Apache-2.0 @@ -18,17 +18,15 @@ * */ -#include +#if (TARGET_STM32L4) + #include "mbedtls/aes.h" #if defined(MBEDTLS_AES_ALT) +#include + #include "mbedtls/platform.h" -//the following defines are provided to maintain compatibility between STM32 families -#define __HAL_RCC_CRYP_CLK_ENABLE __HAL_RCC_AES_CLK_ENABLE -#define __HAL_RCC_CRYP_FORCE_RESET __HAL_RCC_AES_FORCE_RESET -#define __HAL_RCC_CRYP_RELEASE_RESET __HAL_RCC_AES_RELEASE_RESET -#define CRYP AES static int aes_set_key(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits) { @@ -48,7 +46,7 @@ static int aes_set_key(mbedtls_aes_context *ctx, const unsigned char *key, unsig } ctx->hcryp_aes.Init.DataType = CRYP_DATATYPE_8B; - ctx->hcryp_aes.Instance = CRYP; + ctx->hcryp_aes.Instance = AES; /* Deinitializes the CRYP peripheral */ if (HAL_CRYP_DeInit(&ctx->hcryp_aes) == HAL_ERROR) { @@ -56,7 +54,7 @@ static int aes_set_key(mbedtls_aes_context *ctx, const unsigned char *key, unsig } /* Enable CRYP clock */ - __HAL_RCC_CRYP_CLK_ENABLE(); + __HAL_RCC_AES_CLK_ENABLE(); ctx->hcryp_aes.Init.pKey = ctx->aes_key; ctx->hcryp_aes.Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; @@ -97,10 +95,10 @@ void mbedtls_aes_free(mbedtls_aes_context *ctx) } #endif /* DUAL_CORE */ /* Force the CRYP Periheral Clock Reset */ - __HAL_RCC_CRYP_FORCE_RESET(); + __HAL_RCC_AES_FORCE_RESET(); /* Release the CRYP Periheral Clock Reset */ - __HAL_RCC_CRYP_RELEASE_RESET(); + __HAL_RCC_AES_RELEASE_RESET(); #if defined(DUAL_CORE) LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, HSEM_CR_COREID_CURRENT); #endif /* DUAL_CORE */ @@ -388,3 +386,4 @@ void mbedtls_aes_decrypt(mbedtls_aes_context *ctx, } #endif /* MBEDTLS_DEPRECATED_REMOVED */ #endif /*MBEDTLS_AES_ALT*/ +#endif /* TARGET_STM32L4 */ diff --git a/features/mbedtls/targets/TARGET_STM/TARGET_STM32L4/aes_alt.h b/features/mbedtls/targets/TARGET_STM/aes_alt_stm32l4.h similarity index 98% rename from features/mbedtls/targets/TARGET_STM/TARGET_STM32L4/aes_alt.h rename to features/mbedtls/targets/TARGET_STM/aes_alt_stm32l4.h index a134172895..d8e49c646f 100644 --- a/features/mbedtls/targets/TARGET_STM/TARGET_STM32L4/aes_alt.h +++ b/features/mbedtls/targets/TARGET_STM/aes_alt_stm32l4.h @@ -17,10 +17,11 @@ * limitations under the License. * */ -#ifndef MBEDTLS_AES_ALT_H -#define MBEDTLS_AES_ALT_H +#ifndef MBEDTLS_STM32L4_AES_ALT_H +#define MBEDTLS_STM32L4_AES_ALT_H +#if (TARGET_STM32L4) #if defined(MBEDTLS_AES_ALT) #include "mbedtls/platform.h" #include "mbedtls/config.h" @@ -303,5 +304,6 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt(mbedtls_aes_context *ctx, #endif /* MBEDTLS_AES_ALT */ -#endif /* MBEDTLS_AES_ALT_H */ +#endif /* TARGET_STM32L4 */ +#endif /* MBEDTLS_STM32L4_AES_ALT_H */