Skip to content

Commit 3250e2d

Browse files
committed
Fix #5079. Add the support of call to mbedtls_xxx_finish even if mbedtls_xxx_udate
was not called since mbedtls_xxx_start
1 parent cf5065c commit 3250e2d

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

features/mbedtls/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/mbedtls_device.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222

2323
#define MBEDTLS_AES_ALT
2424

25-
/* FIXME: Don't enable SHA1, SHA256 and MD5 hardware acceleration until issue
26-
* #5079 is fixed. (https://github.com/ARMmbed/mbed-os/issues/5079) */
27-
/* #define MBEDTLS_SHA256_ALT */
25+
#define MBEDTLS_SHA256_ALT
2826

29-
/* #define MBEDTLS_SHA1_ALT */
27+
#define MBEDTLS_SHA1_ALT
3028

31-
/* #define MBEDTLS_MD5_ALT */
29+
#define MBEDTLS_MD5_ALT
3230

3331
#endif /* MBEDTLS_DEVICE_H */

features/mbedtls/targets/TARGET_STM/md5_alt.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
175175
return; // Return error code here
176176
}
177177
}
178+
/* The following test can happen when the input is empty, and mbedtls_md5_update has never been called */
179+
if(ctx->hhash_md5.Phase == HAL_HASH_PHASE_READY) {
180+
/* Select the MD5 mode and reset the HASH processor core, so that the HASH will be ready to compute
181+
the message digest of a new message */
182+
HASH->CR |= HASH_ALGOSELECTION_MD5 | HASH_CR_INIT;
183+
}
178184
mbedtls_zeroize( ctx->sbuf, ST_MD5_BLOCK_SIZE);
179185
ctx->sbuf_len = 0;
180186
__HAL_HASH_START_DIGEST();

features/mbedtls/targets/TARGET_STM/sha1_alt.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] )
174174
return; // Return error code here
175175
}
176176
}
177+
/* The following test can happen when the input is empty, and mbedtls_sha1_update has never been called */
178+
if(ctx->hhash_sha1.Phase == HAL_HASH_PHASE_READY) {
179+
/* Select the SHA1 mode and reset the HASH processor core, so that the HASH will be ready to compute
180+
the message digest of a new message */
181+
HASH->CR |= HASH_ALGOSELECTION_SHA1 | HASH_CR_INIT;
182+
}
177183
mbedtls_zeroize(ctx->sbuf, ST_SHA1_BLOCK_SIZE);
178184
ctx->sbuf_len = 0;
179185
__HAL_HASH_START_DIGEST();

features/mbedtls/targets/TARGET_STM/sha256_alt.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32
198198
}
199199
}
200200
}
201+
/* The following test can happen when the input is empty, and mbedtls_sha256_update has never been called */
202+
if(ctx->hhash_sha256.Phase == HAL_HASH_PHASE_READY) {
203+
if (ctx->is224 == 0) {
204+
/* Select the SHA256 mode and reset the HASH processor core, so that the HASH will be ready to compute
205+
the message digest of a new message */
206+
HASH->CR |= HASH_ALGOSELECTION_SHA256 | HASH_CR_INIT;
207+
} else {
208+
/* Select the SHA224 mode and reset the HASH processor core, so that the HASH will be ready to compute
209+
the message digest of a new message */
210+
HASH->CR |= HASH_ALGOSELECTION_SHA224 | HASH_CR_INIT;
211+
}
212+
}
201213
mbedtls_zeroize(ctx->sbuf, ST_SHA256_BLOCK_SIZE);
202214
ctx->sbuf_len = 0;
203215
__HAL_HASH_START_DIGEST();

0 commit comments

Comments
 (0)