[NUC472/M487] Guard against SHA internal state size is not word-aligned in SHA alter.

pull/4925/head
ccli8 2017-11-09 09:36:25 +08:00
parent 8ba07815ed
commit 980cb6b9c8
2 changed files with 10 additions and 0 deletions

View File

@ -24,6 +24,7 @@
#include "nu_bitutil.h" #include "nu_bitutil.h"
#include "mbed_assert.h" #include "mbed_assert.h"
#include "mbed_error.h"
#include "crypto-misc.h" #include "crypto-misc.h"
#include <string.h> #include <string.h>
@ -416,6 +417,10 @@ void crypto_sha_update_nobuf(crypto_sha_context *ctx, const unsigned char *input
void crypto_sha_getinternstate(unsigned char output[], size_t olen) void crypto_sha_getinternstate(unsigned char output[], size_t olen)
{ {
if (olen & 0x3) {
error("Internal error in SHA alter. SHA internal state size requires to be a multiple of 4 bytes.");
}
uint32_t *in_pos = (uint32_t *) &CRPT->HMAC_DGST[0]; uint32_t *in_pos = (uint32_t *) &CRPT->HMAC_DGST[0];
unsigned char *out_pos = output; unsigned char *out_pos = output;
uint32_t rmn = olen; uint32_t rmn = olen;

View File

@ -24,6 +24,7 @@
#include "nu_bitutil.h" #include "nu_bitutil.h"
#include "mbed_assert.h" #include "mbed_assert.h"
#include "mbed_error.h"
#include "crypto-misc.h" #include "crypto-misc.h"
#include <string.h> #include <string.h>
@ -312,6 +313,10 @@ void crypto_sha_update_nobuf(crypto_sha_context *ctx, const unsigned char *input
void crypto_sha_getinternstate(unsigned char output[], size_t olen) void crypto_sha_getinternstate(unsigned char output[], size_t olen)
{ {
if (olen & 0x3) {
error("Internal error in SHA alter. SHA internal state size requires to be a multiple of 4 bytes.");
}
uint32_t *in_pos = (uint32_t *) &CRPT->SHA_DGST0; uint32_t *in_pos = (uint32_t *) &CRPT->SHA_DGST0;
unsigned char *out_pos = output; unsigned char *out_pos = output;
uint32_t rmn = olen; uint32_t rmn = olen;