Separate SHA224 from SHA256 config options.

These options are still dependant on each other.
This is an intermediate step.

Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
This commit is contained in:
Mateusz Starzyk 2021-04-19 16:46:28 +02:00
parent 6fce30fc49
commit e3c48b4a88
34 changed files with 439 additions and 305 deletions

View file

@ -105,6 +105,12 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
SHA256_VALIDATE_RET( ctx != NULL );
SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 );
#if defined(MBEDTLS_SHA224_C)
SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 );
#else
SHA256_VALIDATE_RET( is224 == 0 );
#endif
ctx->total[0] = 0;
ctx->total[1] = 0;
@ -122,6 +128,7 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
}
else
{
#if defined(MBEDTLS_SHA224_C)
/* SHA-224 */
ctx->state[0] = 0xC1059ED8;
ctx->state[1] = 0x367CD507;
@ -131,6 +138,7 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
ctx->state[5] = 0x68581511;
ctx->state[6] = 0x64F98FA7;
ctx->state[7] = 0xBEFA4FA4;
#endif
}
ctx->is224 = is224;
@ -388,7 +396,9 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
PUT_UINT32_BE( ctx->state[5], output, 20 );
PUT_UINT32_BE( ctx->state[6], output, 24 );
#if defined(MBEDTLS_SHA224_C)
if( ctx->is224 == 0 )
#endif
PUT_UINT32_BE( ctx->state[7], output, 28 );
return( 0 );
@ -407,7 +417,12 @@ int mbedtls_sha256_ret( const unsigned char *input,
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
mbedtls_sha256_context ctx;
#if defined(MBEDTLS_SHA224_C)
SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 );
#else
SHA256_VALIDATE_RET( is224 == 0 );
#endif
SHA256_VALIDATE_RET( ilen == 0 || input != NULL );
SHA256_VALIDATE_RET( (unsigned char *)output != NULL );