Split test hash_bad_paths into 3 different tests
1. Rename hash_bad_paths to hash_verify_bad_paths 2. Add test hash_update_bad_paths 3. Add test hash_finish_bad_paths The different scenarios tested as part of hash_bad_paths are moved to the relevant test.
This commit is contained in:
parent
4271df932c
commit
58028321b9
2 changed files with 58 additions and 23 deletions
|
@ -356,9 +356,17 @@ PSA hash setup: bad (not a hash algorithm)
|
|||
depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C
|
||||
hash_setup:PSA_ALG_HMAC(PSA_ALG_SHA_256):PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
PSA hash: bad paths
|
||||
PSA hash verify: bad paths
|
||||
depends_on:MBEDTLS_SHA256_C
|
||||
hash_bad_paths:
|
||||
hash_verify_bad_paths:
|
||||
|
||||
PSA hash update: bad paths
|
||||
depends_on:MBEDTLS_SHA256_C
|
||||
hash_update_bad_paths:
|
||||
|
||||
PSA hash finish: bad paths
|
||||
depends_on:MBEDTLS_SHA256_C
|
||||
hash_finish_bad_paths:
|
||||
|
||||
PSA MAC setup: good, HMAC-SHA-256
|
||||
depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C
|
||||
|
|
|
@ -1568,14 +1568,13 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hash_bad_paths( )
|
||||
void hash_verify_bad_paths( )
|
||||
{
|
||||
psa_algorithm_t alg = PSA_ALG_SHA_256;
|
||||
unsigned char hash[PSA_HASH_MAX_SIZE] = { 0 };
|
||||
size_t expected_size = PSA_HASH_SIZE( alg );
|
||||
unsigned char input[] = "input";
|
||||
psa_hash_operation_t operation;
|
||||
size_t hash_len;
|
||||
|
||||
/* SHA-256 hash digest of the string 'input' with 2 extra bytes appended at
|
||||
* the end */
|
||||
|
@ -1588,31 +1587,12 @@ void hash_bad_paths( )
|
|||
|
||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||
|
||||
/* psa_hash_update without calling psa_hash_setup beforehand */
|
||||
memset( &operation, 0, sizeof( operation ) );
|
||||
TEST_ASSERT( psa_hash_update( &operation,
|
||||
input, sizeof( input ) ) ==
|
||||
PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
/* psa_hash_finish without calling psa_hash_setup beforehand */
|
||||
memset( &operation, 0, sizeof( operation ) );
|
||||
TEST_ASSERT( psa_hash_finish( &operation,
|
||||
hash, expected_size,
|
||||
&hash_len ) == PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
/* psa_hash_verify without calling psa_hash_setup beforehand */
|
||||
memset( &operation, 0, sizeof( operation ) );
|
||||
TEST_ASSERT( psa_hash_verify( &operation,
|
||||
hash, expected_size ) ==
|
||||
PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
/* psa_hash_finish with a smaller hash buffer than expected */
|
||||
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
|
||||
TEST_ASSERT( psa_hash_finish( &operation,
|
||||
hash, expected_size - 1,
|
||||
&hash_len ) == PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
|
||||
|
||||
/* psa_hash_verify with a smaller hash digest than expected */
|
||||
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
|
||||
TEST_ASSERT( psa_hash_verify( &operation,
|
||||
|
@ -1644,6 +1624,53 @@ exit:
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hash_update_bad_paths( )
|
||||
{
|
||||
unsigned char input[] = "input";
|
||||
psa_hash_operation_t operation;
|
||||
|
||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||
|
||||
/* psa_hash_update without calling psa_hash_setup beforehand */
|
||||
memset( &operation, 0, sizeof( operation ) );
|
||||
TEST_ASSERT( psa_hash_update( &operation,
|
||||
input, sizeof( input ) ) ==
|
||||
PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
exit:
|
||||
mbedtls_psa_crypto_free( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hash_finish_bad_paths( )
|
||||
{
|
||||
psa_algorithm_t alg = PSA_ALG_SHA_256;
|
||||
unsigned char hash[PSA_HASH_MAX_SIZE] = { 0 };
|
||||
size_t expected_size = PSA_HASH_SIZE( alg );
|
||||
psa_hash_operation_t operation;
|
||||
size_t hash_len;
|
||||
|
||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||
|
||||
/* psa_hash_finish without calling psa_hash_setup beforehand */
|
||||
memset( &operation, 0, sizeof( operation ) );
|
||||
TEST_ASSERT( psa_hash_finish( &operation,
|
||||
hash, expected_size,
|
||||
&hash_len ) == PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
/* psa_hash_finish with a smaller hash buffer than expected */
|
||||
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
|
||||
TEST_ASSERT( psa_hash_finish( &operation,
|
||||
hash, expected_size - 1,
|
||||
&hash_len ) == PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
|
||||
exit:
|
||||
mbedtls_psa_crypto_free( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mac_setup( int key_type_arg,
|
||||
data_t *key,
|
||||
|
|
Loading…
Reference in a new issue