Skip to content

Commit 744c364

Browse files
committed
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.
1 parent d92e4b5 commit 744c364

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

features/mbedtls/targets/TARGET_STM/md5_alt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ void mbedtls_md5_starts( mbedtls_md5_context *ctx )
100100

101101
/* HASH Configuration */
102102
ctx->hhash_md5.Init.DataType = HASH_DATATYPE_8B;
103+
/* clear CR ALGO value */
104+
HASH->CR &= ~HASH_CR_ALGO_Msk;
103105
if (HAL_HASH_Init(&ctx->hhash_md5) != 0) {
104106
// return error code
105107
return;

features/mbedtls/targets/TARGET_STM/sha1_alt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
9898

9999
/* HASH Configuration */
100100
ctx->hhash_sha1.Init.DataType = HASH_DATATYPE_8B;
101+
/* clear CR ALGO value */
102+
HASH->CR &= ~HASH_CR_ALGO_Msk;
101103
if (HAL_HASH_Init(&ctx->hhash_sha1) == HAL_ERROR) {
102104
// error found to be returned
103105
return;

features/mbedtls/targets/TARGET_STM/sha256_alt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
9999
ctx->is224 = is224;
100100
/* HASH Configuration */
101101
ctx->hhash_sha256.Init.DataType = HASH_DATATYPE_8B;
102+
/* clear CR ALGO value */
103+
HASH->CR &= ~HASH_CR_ALGO_Msk;
102104
if (HAL_HASH_Init(&ctx->hhash_sha256) == HAL_ERROR) {
103105
// error found to be returned
104106
return;

0 commit comments

Comments
 (0)