From 77ac355864cbb0e88aaef37a8bd3b23bed947b11 Mon Sep 17 00:00:00 2001 From: adustm Date: Mon, 15 May 2017 13:54:09 +0200 Subject: [PATCH] Fix use case with size = 0 (md5_selftest #1) --- features/mbedtls/targets/TARGET_STM/md5_alt.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/features/mbedtls/targets/TARGET_STM/md5_alt.c b/features/mbedtls/targets/TARGET_STM/md5_alt.c index 8db07f4416..f7cf12b0d3 100644 --- a/features/mbedtls/targets/TARGET_STM/md5_alt.c +++ b/features/mbedtls/targets/TARGET_STM/md5_alt.c @@ -86,6 +86,15 @@ void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, s unsigned char i=0; int currentlen = ilen; /* store mechanism to handle 64 bytes per 64 bytes */ + if (currentlen == 0){ // change HW status is size if 0 + if(ctx->hhash_md5.Phase == HAL_HASH_PHASE_READY) + { + /* Select the MD5 mode and reset the HASH processor core, so that the HASH will be ready to compute + the message digest of a new message */ + HASH->CR |= HASH_ALGOSELECTION_MD5 | HASH_CR_INIT; + } + ctx->hhash_md5.Phase = HAL_HASH_PHASE_PROCESS; + } while ((currentlen+ctx->sbuf_len) >=64) { if (ctx->sbuf_len ==0) { /* straight forward */ mbedtls_md5_process(ctx, input+(i*64));