forked from espressif/esp-idf
fix(mbedtls/sha): Fix some local variable's types to avoid any substraction overflow error
- Though such a case would not occur given the way it is used the driver layer
This commit is contained in:
@@ -135,8 +135,8 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, const unsigned cha
|
|||||||
|
|
||||||
int mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen )
|
int mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen )
|
||||||
{
|
{
|
||||||
size_t fill;
|
size_t fill, left, len;
|
||||||
uint32_t left, len, local_len = 0;
|
uint32_t local_len = 0;
|
||||||
|
|
||||||
if ( !ilen || (input == NULL)) {
|
if ( !ilen || (input == NULL)) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -160,7 +160,7 @@ int mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input,
|
|||||||
local_len = 64;
|
local_len = 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = (ilen / 64) * 64;
|
len = SHA_ALIGN_DOWN(ilen , 64);
|
||||||
|
|
||||||
if ( len || local_len) {
|
if ( len || local_len) {
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ int mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input,
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t length_processed = 0;
|
uint32_t length_processed = 0;
|
||||||
while ( len - length_processed > 0 ) {
|
while ( len - length_processed != 0 ) {
|
||||||
esp_internal_sha1_block_process(ctx, input + length_processed);
|
esp_internal_sha1_block_process(ctx, input + length_processed);
|
||||||
length_processed += 64;
|
length_processed += 64;
|
||||||
}
|
}
|
||||||
|
@@ -152,8 +152,8 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, const unsigned
|
|||||||
int mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
|
int mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
|
||||||
size_t ilen )
|
size_t ilen )
|
||||||
{
|
{
|
||||||
size_t fill;
|
size_t fill, left, len;
|
||||||
uint32_t left, len, local_len = 0;
|
uint32_t local_len = 0;
|
||||||
|
|
||||||
if ( ilen == 0 ) {
|
if ( ilen == 0 ) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -179,7 +179,8 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *inp
|
|||||||
local_len = 64;
|
local_len = 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = (ilen / 64) * 64;
|
len = SHA_ALIGN_DOWN(ilen , 64);
|
||||||
|
|
||||||
if ( len || local_len) {
|
if ( len || local_len) {
|
||||||
|
|
||||||
esp_sha_acquire_hardware();
|
esp_sha_acquire_hardware();
|
||||||
@@ -202,7 +203,7 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *inp
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t length_processed = 0;
|
uint32_t length_processed = 0;
|
||||||
while ( len - length_processed > 0 ) {
|
while ( len - length_processed != 0 ) {
|
||||||
esp_internal_sha256_block_process(ctx, input + length_processed);
|
esp_internal_sha256_block_process(ctx, input + length_processed);
|
||||||
length_processed += 64;
|
length_processed += 64;
|
||||||
}
|
}
|
||||||
|
@@ -190,14 +190,14 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, const unsigned
|
|||||||
int mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
|
int mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
|
||||||
size_t ilen )
|
size_t ilen )
|
||||||
{
|
{
|
||||||
size_t fill;
|
size_t fill, left, len;
|
||||||
unsigned int left, len, local_len = 0;
|
uint32_t local_len = 0;
|
||||||
|
|
||||||
if ( ilen == 0 ) {
|
if ( ilen == 0 ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
left = (unsigned int) (ctx->total[0] & 0x7F);
|
left = (size_t) (ctx->total[0] & 0x7F);
|
||||||
fill = 128 - left;
|
fill = 128 - left;
|
||||||
|
|
||||||
ctx->total[0] += (uint64_t) ilen;
|
ctx->total[0] += (uint64_t) ilen;
|
||||||
@@ -215,7 +215,8 @@ int mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *inp
|
|||||||
local_len = 128;
|
local_len = 128;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = (ilen / 128) * 128;
|
len = SHA_ALIGN_DOWN(ilen , 128);
|
||||||
|
|
||||||
if ( len || local_len) {
|
if ( len || local_len) {
|
||||||
|
|
||||||
esp_sha_acquire_hardware();
|
esp_sha_acquire_hardware();
|
||||||
@@ -243,7 +244,7 @@ int mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *inp
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t length_processed = 0;
|
uint32_t length_processed = 0;
|
||||||
while ( len - length_processed > 0 ) {
|
while ( len - length_processed != 0 ) {
|
||||||
esp_internal_sha512_block_process(ctx, input + length_processed);
|
esp_internal_sha512_block_process(ctx, input + length_processed);
|
||||||
length_processed += 128;
|
length_processed += 128;
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,8 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
#endif /* SOC_SHA_SUPPORT_DMA */
|
#endif /* SOC_SHA_SUPPORT_DMA */
|
||||||
|
|
||||||
|
#define SHA_ALIGN_DOWN(num, align) ((num) & ~((align) - 1))
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SHA_BLOCK_MODE,
|
SHA_BLOCK_MODE,
|
||||||
#if SOC_SHA_SUPPORT_DMA
|
#if SOC_SHA_SUPPORT_DMA
|
||||||
|
Reference in New Issue
Block a user