8b4a38176a
Test that hash operation functions fail when given a hash algorithm that is not supported or an algorithm that is not a hash. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
39 lines
1 KiB
Text
39 lines
1 KiB
Text
/* BEGIN_HEADER */
|
|
|
|
#include "psa/crypto.h"
|
|
#include "test/psa_crypto_helpers.h"
|
|
|
|
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
* depends_on:MBEDTLS_PSA_CRYPTO_C
|
|
* END_DEPENDENCIES
|
|
*/
|
|
|
|
/* BEGIN_CASE */
|
|
void hash_fail( int alg_arg, int expected_status_arg )
|
|
{
|
|
psa_status_t expected_status = expected_status_arg;
|
|
psa_algorithm_t alg = alg_arg;
|
|
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
|
|
uint8_t input[1] = {'A'};
|
|
uint8_t output[PSA_HASH_MAX_SIZE] = {0};
|
|
size_t length = SIZE_MAX;
|
|
|
|
PSA_INIT( );
|
|
|
|
TEST_EQUAL( expected_status,
|
|
psa_hash_setup( &operation, alg ) );
|
|
TEST_EQUAL( expected_status,
|
|
psa_hash_compute( alg, input, sizeof( input ),
|
|
output, sizeof( output ), &length ) );
|
|
TEST_EQUAL( expected_status,
|
|
psa_hash_compare( alg, input, sizeof( input ),
|
|
output, sizeof( output ) ) );
|
|
|
|
exit:
|
|
psa_hash_abort( &operation );
|
|
PSA_DONE( );
|
|
}
|
|
/* END_CASE */
|