Add hash bad paths test

Increase code coverage
This commit is contained in:
itayzafrir 2018-10-18 18:01:10 +03:00
parent 18b1a227ac
commit ec93d30b45
2 changed files with 60 additions and 0 deletions

View file

@ -428,6 +428,10 @@ PSA hash verify: RIPEMD160
depends_on:MBEDTLS_RIPEMD160_C
hash_verify:PSA_ALG_RIPEMD160:"bd":"5089265ee5d9af75d12dbf7ea2f27dbdee435b37"
PSA hash: bad paths
depends_on:MBEDTLS_SHA256_C
hash_bad_paths:
PSA MAC setup: good, HMAC-SHA-256
depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C
mac_setup:PSA_KEY_TYPE_HMAC:"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f":PSA_ALG_HMAC(PSA_ALG_SHA_256):PSA_SUCCESS

View file

@ -1628,6 +1628,62 @@ exit:
}
/* END_CASE */
/* BEGIN_CASE */
void hash_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;
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 buffer than expected */
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_verify( &operation,
hash, expected_size - 1 ) ==
PSA_ERROR_INVALID_SIGNATURE );
/* psa_hash_verify with a non-matching hash buffer */
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_update( &operation,
input, sizeof( input ) ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_verify( &operation,
hash, expected_size ) ==
PSA_ERROR_INVALID_SIGNATURE );
exit:
mbedtls_psa_crypto_free( );
}
/* END_CASE */
/* BEGIN_CASE */
void mac_setup( int key_type_arg,
data_t *key,