2018-10-24 09:45:18 +00:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
|
|
* depends_on:MBEDTLS_PSA_CRYPTO_C
|
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
2018-12-17 22:35:42 +00:00
|
|
|
/* BEGIN_CASE */
|
2018-10-24 09:45:18 +00:00
|
|
|
void hash_finish( int alg_arg, data_t *input, data_t *expected_hash )
|
|
|
|
{
|
|
|
|
psa_algorithm_t alg = alg_arg;
|
|
|
|
unsigned char actual_hash[PSA_HASH_MAX_SIZE];
|
|
|
|
size_t actual_hash_length;
|
2019-01-04 11:47:44 +00:00
|
|
|
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
|
2018-10-24 09:45:18 +00:00
|
|
|
|
2018-12-17 23:18:46 +00:00
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
|
|
|
|
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
|
|
|
|
PSA_ASSERT( psa_hash_update( &operation,
|
|
|
|
input->x, input->len ) );
|
|
|
|
PSA_ASSERT( psa_hash_finish( &operation,
|
|
|
|
actual_hash, sizeof( actual_hash ),
|
|
|
|
&actual_hash_length ) );
|
2018-10-24 09:45:18 +00:00
|
|
|
ASSERT_COMPARE( expected_hash->x, expected_hash->len,
|
|
|
|
actual_hash, actual_hash_length );
|
|
|
|
|
|
|
|
exit:
|
2020-08-26 08:24:13 +00:00
|
|
|
psa_hash_abort( &operation );
|
2019-05-28 13:10:21 +00:00
|
|
|
PSA_DONE( );
|
2018-10-24 09:45:18 +00:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void hash_verify( int alg_arg, data_t *input, data_t *expected_hash )
|
|
|
|
{
|
|
|
|
psa_algorithm_t alg = alg_arg;
|
2019-01-04 11:47:44 +00:00
|
|
|
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
|
2018-10-24 09:45:18 +00:00
|
|
|
|
2018-12-17 23:18:46 +00:00
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
2018-10-24 09:45:18 +00:00
|
|
|
|
2018-12-17 23:18:46 +00:00
|
|
|
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
|
|
|
|
PSA_ASSERT( psa_hash_update( &operation,
|
|
|
|
input->x,
|
|
|
|
input->len ) );
|
|
|
|
PSA_ASSERT( psa_hash_verify( &operation,
|
|
|
|
expected_hash->x,
|
|
|
|
expected_hash->len ) );
|
2018-10-24 09:45:18 +00:00
|
|
|
|
|
|
|
exit:
|
2020-08-26 08:24:13 +00:00
|
|
|
psa_hash_abort( &operation );
|
2019-05-28 13:10:21 +00:00
|
|
|
PSA_DONE( );
|
2018-10-24 09:45:18 +00:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void hash_multi_part( int alg_arg, data_t *input, data_t *expected_hash )
|
|
|
|
{
|
|
|
|
psa_algorithm_t alg = alg_arg;
|
2018-10-29 11:34:37 +00:00
|
|
|
unsigned char actual_hash[PSA_HASH_MAX_SIZE];
|
2018-10-24 09:45:18 +00:00
|
|
|
size_t actual_hash_length;
|
2019-01-04 11:47:44 +00:00
|
|
|
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
|
2019-01-19 11:03:41 +00:00
|
|
|
psa_hash_operation_t operation2 = PSA_HASH_OPERATION_INIT;
|
2018-10-29 11:34:37 +00:00
|
|
|
uint32_t len = 0;
|
2018-10-24 09:45:18 +00:00
|
|
|
|
2018-12-17 23:18:46 +00:00
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
2018-10-24 09:45:18 +00:00
|
|
|
|
2018-10-29 11:34:37 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
memset( actual_hash, 0, sizeof( actual_hash ) );
|
2018-12-17 23:18:46 +00:00
|
|
|
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
|
2018-10-24 09:45:18 +00:00
|
|
|
|
2018-12-17 23:18:46 +00:00
|
|
|
PSA_ASSERT( psa_hash_update( &operation,
|
|
|
|
input->x, len ) );
|
2019-01-19 11:03:41 +00:00
|
|
|
PSA_ASSERT( psa_hash_clone( &operation, &operation2 ) );
|
2018-12-17 23:18:46 +00:00
|
|
|
PSA_ASSERT( psa_hash_update( &operation,
|
|
|
|
input->x + len, input->len - len ) );
|
2019-01-19 11:03:41 +00:00
|
|
|
PSA_ASSERT( psa_hash_update( &operation2,
|
|
|
|
input->x + len, input->len - len ) );
|
2018-10-24 09:45:18 +00:00
|
|
|
|
2018-12-17 23:18:46 +00:00
|
|
|
PSA_ASSERT( psa_hash_finish( &operation,
|
|
|
|
actual_hash, sizeof( actual_hash ),
|
|
|
|
&actual_hash_length ) );
|
2018-10-29 11:34:37 +00:00
|
|
|
ASSERT_COMPARE( expected_hash->x, expected_hash->len,
|
|
|
|
actual_hash, actual_hash_length );
|
|
|
|
|
2019-01-19 11:03:41 +00:00
|
|
|
PSA_ASSERT( psa_hash_finish( &operation2,
|
|
|
|
actual_hash, sizeof( actual_hash ),
|
|
|
|
&actual_hash_length ) );
|
|
|
|
ASSERT_COMPARE( expected_hash->x, expected_hash->len,
|
|
|
|
actual_hash, actual_hash_length );
|
2018-10-29 11:34:37 +00:00
|
|
|
} while( len++ != input->len );
|
2018-10-24 09:45:18 +00:00
|
|
|
|
|
|
|
exit:
|
2020-08-26 08:24:13 +00:00
|
|
|
psa_hash_abort( &operation );
|
|
|
|
psa_hash_abort( &operation2 );
|
2019-05-28 13:10:21 +00:00
|
|
|
PSA_DONE( );
|
2018-10-24 09:45:18 +00:00
|
|
|
}
|
|
|
|
/* END_CASE */
|