Skip to content

Commit 50a8592

Browse files
kotkcyromanjoe
authored andcommitted
Fixed SHA ctx and ilen parameters checking
1 parent 7cbfa84 commit 50a8592

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha1_alt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ void mbedtls_sha1_init( mbedtls_sha1_context *ctx )
5555

5656
void mbedtls_sha1_free( mbedtls_sha1_context *ctx )
5757
{
58-
SHA1_VALIDATE( ctx != NULL );
58+
if (ctx == NULL)
59+
return;
5960

6061
cy_hw_sha_free(ctx, sizeof( mbedtls_sha1_context ));
6162
}
@@ -88,6 +89,9 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
8889
SHA1_VALIDATE_RET( ctx != NULL );
8990
SHA1_VALIDATE_RET( ilen == 0 || input != NULL );
9091

92+
if (ilen == 0)
93+
return;
94+
9195
return cy_hw_sha_update(&ctx->obj, &ctx->hashState, input, ilen);
9296
}
9397

features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha256_alt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ void mbedtls_sha256_init( mbedtls_sha256_context *ctx )
5454

5555
void mbedtls_sha256_free( mbedtls_sha256_context *ctx )
5656
{
57-
SHA256_VALIDATE ( ctx != NULL );
57+
if (ctx == NULL)
58+
return;
5859

5960
cy_hw_sha_free(ctx, sizeof( mbedtls_sha256_context ));
6061
}
@@ -88,6 +89,9 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char
8889
SHA256_VALIDATE_RET( ctx != NULL );
8990
SHA256_VALIDATE_RET( ilen == 0 || input != NULL );
9091

92+
if (ilen == 0)
93+
return;
94+
9195
return cy_hw_sha_update(&ctx->obj, &ctx->hashState, (uint8_t *)input, ilen);
9296
}
9397

features/mbedtls/targets/TARGET_Cypress/TARGET_PSOC6/sha512_alt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ void mbedtls_sha512_init( mbedtls_sha512_context *ctx )
5454

5555
void mbedtls_sha512_free( mbedtls_sha512_context *ctx )
5656
{
57-
SHA512_VALIDATE( ctx != NULL );
57+
if (ctx == NULL)
58+
return;
5859

5960
cy_hw_sha_free(ctx, sizeof( mbedtls_sha512_context ));
6061
}
@@ -87,6 +88,9 @@ int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx, const unsigned char
8788
{
8889
SHA512_VALIDATE_RET( ctx != NULL );
8990
SHA512_VALIDATE_RET( ilen == 0 || input != NULL );
91+
92+
if (ilen == 0)
93+
return;
9094

9195
return cy_hw_sha_update(&ctx->obj, &ctx->hashState, input, ilen);
9296
}

0 commit comments

Comments
 (0)