From 10c51388499e663c84f4c3819f96de5158af40f3 Mon Sep 17 00:00:00 2001 From: Martin Kojtal <0xc0170@gmail.com> Date: Wed, 2 Aug 2017 14:04:15 +0100 Subject: [PATCH] STM mbedtls: clear algo value for md5/sha1 and sha256 The hw block for mbedtls is shared, thus HASH algo value should be cleared in the init. --- features/mbedtls/targets/TARGET_STM/md5_alt.c | 2 ++ features/mbedtls/targets/TARGET_STM/sha1_alt.c | 2 ++ features/mbedtls/targets/TARGET_STM/sha256_alt.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/features/mbedtls/targets/TARGET_STM/md5_alt.c b/features/mbedtls/targets/TARGET_STM/md5_alt.c index 5a3e816f93..1a954ca213 100644 --- a/features/mbedtls/targets/TARGET_STM/md5_alt.c +++ b/features/mbedtls/targets/TARGET_STM/md5_alt.c @@ -100,6 +100,8 @@ void mbedtls_md5_starts( mbedtls_md5_context *ctx ) /* HASH Configuration */ ctx->hhash_md5.Init.DataType = HASH_DATATYPE_8B; + /* clear CR ALGO value */ + HASH->CR &= ~HASH_CR_ALGO_Msk; if (HAL_HASH_Init(&ctx->hhash_md5) != 0) { // return error code return; diff --git a/features/mbedtls/targets/TARGET_STM/sha1_alt.c b/features/mbedtls/targets/TARGET_STM/sha1_alt.c index 98317c21fa..cfd90416f2 100644 --- a/features/mbedtls/targets/TARGET_STM/sha1_alt.c +++ b/features/mbedtls/targets/TARGET_STM/sha1_alt.c @@ -98,6 +98,8 @@ void mbedtls_sha1_starts( mbedtls_sha1_context *ctx ) /* HASH Configuration */ ctx->hhash_sha1.Init.DataType = HASH_DATATYPE_8B; + /* clear CR ALGO value */ + HASH->CR &= ~HASH_CR_ALGO_Msk; if (HAL_HASH_Init(&ctx->hhash_sha1) == HAL_ERROR) { // error found to be returned return; diff --git a/features/mbedtls/targets/TARGET_STM/sha256_alt.c b/features/mbedtls/targets/TARGET_STM/sha256_alt.c index a3354e9968..6729cdac2e 100644 --- a/features/mbedtls/targets/TARGET_STM/sha256_alt.c +++ b/features/mbedtls/targets/TARGET_STM/sha256_alt.c @@ -99,6 +99,8 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 ) ctx->is224 = is224; /* HASH Configuration */ ctx->hhash_sha256.Init.DataType = HASH_DATATYPE_8B; + /* clear CR ALGO value */ + HASH->CR &= ~HASH_CR_ALGO_Msk; if (HAL_HASH_Init(&ctx->hhash_sha256) == HAL_ERROR) { // error found to be returned return;