Skip to content

Commit 980cb6b

Browse files
committed
[NUC472/M487] Guard against SHA internal state size is not word-aligned in SHA alter.
1 parent 8ba0781 commit 980cb6b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha_alt_hw.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "nu_bitutil.h"
2626
#include "mbed_assert.h"
27+
#include "mbed_error.h"
2728
#include "crypto-misc.h"
2829

2930
#include <string.h>
@@ -416,6 +417,10 @@ void crypto_sha_update_nobuf(crypto_sha_context *ctx, const unsigned char *input
416417

417418
void crypto_sha_getinternstate(unsigned char output[], size_t olen)
418419
{
420+
if (olen & 0x3) {
421+
error("Internal error in SHA alter. SHA internal state size requires to be a multiple of 4 bytes.");
422+
}
423+
419424
uint32_t *in_pos = (uint32_t *) &CRPT->HMAC_DGST[0];
420425
unsigned char *out_pos = output;
421426
uint32_t rmn = olen;

features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha_alt_hw.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "nu_bitutil.h"
2626
#include "mbed_assert.h"
27+
#include "mbed_error.h"
2728
#include "crypto-misc.h"
2829

2930
#include <string.h>
@@ -312,6 +313,10 @@ void crypto_sha_update_nobuf(crypto_sha_context *ctx, const unsigned char *input
312313

313314
void crypto_sha_getinternstate(unsigned char output[], size_t olen)
314315
{
316+
if (olen & 0x3) {
317+
error("Internal error in SHA alter. SHA internal state size requires to be a multiple of 4 bytes.");
318+
}
319+
315320
uint32_t *in_pos = (uint32_t *) &CRPT->SHA_DGST0;
316321
unsigned char *out_pos = output;
317322
uint32_t rmn = olen;

0 commit comments

Comments
 (0)