mirror of https://github.com/ARMmbed/mbed-os.git
Improve fix calling Accumulate function every time in finish function
parent
cba538854d
commit
53027fd590
|
@ -170,17 +170,12 @@ void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
|
|||
if (st_md5_restore_hw_context(ctx) != 1) {
|
||||
return; // Return HASH_BUSY timout error here
|
||||
}
|
||||
if (ctx->sbuf_len > 0) {
|
||||
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, ctx->sbuf, ctx->sbuf_len) != 0) {
|
||||
return; // Return error code here
|
||||
}
|
||||
}
|
||||
/* The following test can happen when the input is empty, and mbedtls_md5_update has never been called */
|
||||
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;
|
||||
/* Last accumulation for extra bytes in sbuf_len */
|
||||
/* This allows the HW flags to be in place in case mbedtls_sha256_update has not been called yet */
|
||||
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, ctx->sbuf, ctx->sbuf_len) != 0) {
|
||||
return; // Return error code here
|
||||
}
|
||||
|
||||
mbedtls_zeroize( ctx->sbuf, ST_MD5_BLOCK_SIZE);
|
||||
ctx->sbuf_len = 0;
|
||||
__HAL_HASH_START_DIGEST();
|
||||
|
|
|
@ -169,16 +169,10 @@ void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] )
|
|||
return; // Return HASH_BUSY timout error here
|
||||
}
|
||||
|
||||
if (ctx->sbuf_len > 0) {
|
||||
if (HAL_HASH_SHA1_Accumulate(&ctx->hhash_sha1, ctx->sbuf, ctx->sbuf_len) != 0) {
|
||||
return; // Return error code here
|
||||
}
|
||||
}
|
||||
/* The following test can happen when the input is empty, and mbedtls_sha1_update has never been called */
|
||||
if(ctx->hhash_sha1.Phase == HAL_HASH_PHASE_READY) {
|
||||
/* Select the SHA1 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_SHA1 | HASH_CR_INIT;
|
||||
/* Last accumulation for extra bytes in sbuf_len */
|
||||
/* This allows the HW flags to be in place in case mbedtls_sha256_update has not been called yet */
|
||||
if (HAL_HASH_SHA1_Accumulate(&ctx->hhash_sha1, ctx->sbuf, ctx->sbuf_len) != 0) {
|
||||
return; // Return error code here
|
||||
}
|
||||
mbedtls_zeroize(ctx->sbuf, ST_SHA1_BLOCK_SIZE);
|
||||
ctx->sbuf_len = 0;
|
||||
|
|
|
@ -187,29 +187,18 @@ void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32
|
|||
if (st_sha256_restore_hw_context(ctx) != 1) {
|
||||
return; // Return HASH_BUSY timout error here
|
||||
}
|
||||
if (ctx->sbuf_len > 0) {
|
||||
if (ctx->is224 == 0) {
|
||||
if (HAL_HASHEx_SHA256_Accumulate(&ctx->hhash_sha256, ctx->sbuf, ctx->sbuf_len) != 0) {
|
||||
return; // Return error code here
|
||||
}
|
||||
} else {
|
||||
if (HAL_HASHEx_SHA224_Accumulate(&ctx->hhash_sha256, ctx->sbuf, ctx->sbuf_len) != 0) {
|
||||
return; // Return error code here
|
||||
}
|
||||
}
|
||||
}
|
||||
/* The following test can happen when the input is empty, and mbedtls_sha256_update has never been called */
|
||||
if(ctx->hhash_sha256.Phase == HAL_HASH_PHASE_READY) {
|
||||
if (ctx->is224 == 0) {
|
||||
/* Select the SHA256 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_SHA256 | HASH_CR_INIT;
|
||||
} else {
|
||||
/* Select the SHA224 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_SHA224 | HASH_CR_INIT;
|
||||
/* Last accumulation for extra bytes in sbuf_len */
|
||||
/* This allows the HW flags to be in place in case mbedtls_sha256_update has not been called yet */
|
||||
if (ctx->is224 == 0) {
|
||||
if (HAL_HASHEx_SHA256_Accumulate(&ctx->hhash_sha256, ctx->sbuf, ctx->sbuf_len) != 0) {
|
||||
return; // Return error code here
|
||||
}
|
||||
} else {
|
||||
if (HAL_HASHEx_SHA224_Accumulate(&ctx->hhash_sha256, ctx->sbuf, ctx->sbuf_len) != 0) {
|
||||
return; // Return error code here
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_zeroize(ctx->sbuf, ST_SHA256_BLOCK_SIZE);
|
||||
ctx->sbuf_len = 0;
|
||||
__HAL_HASH_START_DIGEST();
|
||||
|
|
Loading…
Reference in New Issue