Re-introduce ENUM validation in sha256.c

Signed-off-by: Tuvshinzaya Erdenekhuu <tuvshinzaya.erdenekhuu@arm.com>
This commit is contained in:
Tuvshinzaya Erdenekhuu 2022-08-05 15:59:19 +01:00
parent df2f560316
commit 696dfb6b1e

View File

@ -149,10 +149,6 @@ static int mbedtls_a64_crypto_sha256_determine_support( void )
#endif /* MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT */ #endif /* MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT */
#define SHA256_VALIDATE_RET(cond) \
MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA256_BAD_INPUT_DATA )
#define SHA256_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond )
#if !defined(MBEDTLS_SHA256_ALT) #if !defined(MBEDTLS_SHA256_ALT)
#define SHA256_BLOCK_SIZE 64 #define SHA256_BLOCK_SIZE 64
@ -182,9 +178,11 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
int mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 ) int mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
{ {
#if defined(MBEDTLS_SHA224_C) #if defined(MBEDTLS_SHA224_C)
SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 ); if( is224 != 0 && is224 != 1 )
return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
#else #else
SHA256_VALIDATE_RET( is224 == 0 ); if( is224 != 0 )
return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
#endif #endif
ctx->total[0] = 0; ctx->total[0] = 0;
@ -689,9 +687,11 @@ int mbedtls_sha256( const unsigned char *input,
mbedtls_sha256_context ctx; mbedtls_sha256_context ctx;
#if defined(MBEDTLS_SHA224_C) #if defined(MBEDTLS_SHA224_C)
SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 ); if( is224 != 0 && is224 != 1 )
return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
#else #else
SHA256_VALIDATE_RET( is224 == 0 ); if( is224 != 0 )
return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
#endif #endif
mbedtls_sha256_init( &ctx ); mbedtls_sha256_init( &ctx );