mbedtls/tests/suites/test_suite_psa_crypto_op_fail.function
Gilles Peskine 8b4a38176a Generate test cases for hash operation failure
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>
2022-03-16 13:54:25 +01:00

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 */