Adapt SHA-256 selftest to NO_SHA224

This commit is contained in:
Manuel Pégourié-Gonnard 2019-07-16 15:37:56 +02:00
parent 8463d29156
commit abebdd16ef

View File

@ -477,8 +477,9 @@ static const size_t sha256_test_buflen[3] =
3, 56, 1000 3, 56, 1000
}; };
static const unsigned char sha256_test_sum[6][32] = static const unsigned char sha256_test_sum[][32] =
{ {
#if !defined(MBEDTLS_SHA256_NO_SHA224)
/* /*
* SHA-224 test vectors * SHA-224 test vectors
*/ */
@ -494,6 +495,7 @@ static const unsigned char sha256_test_sum[6][32] =
0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B, 0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B,
0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE, 0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE,
0x4E, 0xE7, 0xAD, 0x67 }, 0x4E, 0xE7, 0xAD, 0x67 },
#endif /* !MBEDTLS_SHA256_NO_SHA224 */
/* /*
* SHA-256 test vectors * SHA-256 test vectors
@ -512,6 +514,9 @@ static const unsigned char sha256_test_sum[6][32] =
0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 } 0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 }
}; };
#define SHA256_TEST_SUM_N \
( sizeof( sha256_test_sum ) / sizeof( sha256_test_sum[0] ) )
/* /*
* Checkup routine * Checkup routine
*/ */
@ -533,10 +538,14 @@ int mbedtls_sha256_self_test( int verbose )
mbedtls_sha256_init( &ctx ); mbedtls_sha256_init( &ctx );
for( i = 0; i < 6; i++ ) for( i = 0; i < (int) SHA256_TEST_SUM_N; i++ )
{ {
j = i % 3; j = i % 3;
#if !defined(MBEDTLS_SHA256_NO_SHA224)
k = i < 3; k = i < 3;
#else
k = 0;
#endif
if( verbose != 0 ) if( verbose != 0 )
mbedtls_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 ); mbedtls_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 );