Merge branch 'fix/sha_port_formatting_and_local_val_types' into 'master'

fix(mbedtls/sha): Fix formatting and change local variable's types

Closes IDF-12217 and IDF-12218

See merge request espressif/esp-idf!36792
This commit is contained in:
Mahavir Jain
2025-02-12 17:19:03 +08:00
4 changed files with 134 additions and 132 deletions

View File

@@ -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)
{
size_t fill;
uint32_t left, len, local_len = 0;
size_t fill, left, len;
uint32_t local_len = 0;
if (!ilen || (input == NULL)) {
return 0;
@@ -160,7 +160,7 @@ int mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input,
local_len = 64;
}
len = (ilen / 64) * 64;
len = SHA_ALIGN_DOWN(ilen , 64);
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;
while ( len - length_processed > 0 ) {
while (len - length_processed != 0) {
esp_internal_sha1_block_process(ctx, input + length_processed);
length_processed += 64;
}
@@ -229,7 +229,6 @@ int mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] )
last = ctx->total[0] & 0x3F;
padn = (last < 56) ? (56 - last) : (120 - last);
if ((ret = mbedtls_sha1_update(ctx, sha1_padding, padn)) != 0) {
return ret;
}

View File

@@ -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,
size_t ilen)
{
size_t fill;
uint32_t left, len, local_len = 0;
size_t fill, left, len;
uint32_t local_len = 0;
if (ilen == 0) {
return 0;
@@ -179,7 +179,8 @@ int mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *inp
local_len = 64;
}
len = (ilen / 64) * 64;
len = SHA_ALIGN_DOWN(ilen , 64);
if (len || local_len) {
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;
while ( len - length_processed > 0 ) {
while (len - length_processed != 0) {
esp_internal_sha256_block_process(ctx, input + length_processed);
length_processed += 64;
}

View File

@@ -187,17 +187,16 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, const unsigned
/*
* SHA-512 process buffer
*/
int mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
size_t ilen )
int mbedtls_sha512_update(mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen)
{
size_t fill;
unsigned int left, len, local_len = 0;
size_t fill, left, len;
uint32_t local_len = 0;
if (ilen == 0) {
return 0;
}
left = (unsigned int) (ctx->total[0] & 0x7F);
left = (size_t) (ctx->total[0] & 0x7F);
fill = 128 - left;
ctx->total[0] += (uint64_t) ilen;
@@ -215,7 +214,8 @@ int mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *inp
local_len = 128;
}
len = (ilen / 128) * 128;
len = SHA_ALIGN_DOWN(ilen , 128);
if (len || local_len) {
esp_sha_acquire_hardware();
@@ -243,7 +243,7 @@ int mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *inp
}
uint32_t length_processed = 0;
while ( len - length_processed > 0 ) {
while (len - length_processed != 0) {
esp_internal_sha512_block_process(ctx, input + length_processed);
length_processed += 128;
}

View File

@@ -37,6 +37,8 @@ extern "C" {
#endif
#endif /* SOC_SHA_SUPPORT_DMA */
#define SHA_ALIGN_DOWN(num, align) ((num) & ~((align) - 1))
typedef enum {
SHA_BLOCK_MODE,
#if SOC_SHA_SUPPORT_DMA