mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-27 11:14:20 +01:00
952f40962a
Create a specific file for helper functions that are related to the PSA API. The reason for a separate file is so that it can include <psa/crypto.h>, without forcing this header inclusion into every test suite. In this commit, psa_helpers.function doesn't need psa/crypto.h yet, but this will be the case in a subsequent commit. Move PSA_ASSERT to psa_helpers.function, since that's the sort of things it's for. Include "psa_helpers.function" from the PSA crypto tests. In the ITS test, don't include "psa_helpers". The ITS tests are meant to stand alone from the rest of the library.
101 lines
3.2 KiB
Plaintext
101 lines
3.2 KiB
Plaintext
/* BEGIN_HEADER */
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "psa_helpers.function"
|
|
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
* depends_on:MBEDTLS_PSA_CRYPTO_C
|
|
* END_DEPENDENCIES
|
|
*/
|
|
|
|
/* BEGIN_CASE */
|
|
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;
|
|
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
|
|
|
|
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 ) );
|
|
ASSERT_COMPARE( expected_hash->x, expected_hash->len,
|
|
actual_hash, actual_hash_length );
|
|
|
|
exit:
|
|
mbedtls_psa_crypto_free( );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE */
|
|
void hash_verify( int alg_arg, data_t *input, data_t *expected_hash )
|
|
{
|
|
psa_algorithm_t alg = alg_arg;
|
|
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
|
|
|
|
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_verify( &operation,
|
|
expected_hash->x,
|
|
expected_hash->len ) );
|
|
|
|
exit:
|
|
mbedtls_psa_crypto_free( );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE */
|
|
void hash_multi_part( 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;
|
|
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
|
|
psa_hash_operation_t operation2 = PSA_HASH_OPERATION_INIT;
|
|
uint32_t len = 0;
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
|
|
do
|
|
{
|
|
memset( actual_hash, 0, sizeof( actual_hash ) );
|
|
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
|
|
|
|
PSA_ASSERT( psa_hash_update( &operation,
|
|
input->x, len ) );
|
|
PSA_ASSERT( psa_hash_clone( &operation, &operation2 ) );
|
|
PSA_ASSERT( psa_hash_update( &operation,
|
|
input->x + len, input->len - len ) );
|
|
PSA_ASSERT( psa_hash_update( &operation2,
|
|
input->x + len, input->len - len ) );
|
|
|
|
PSA_ASSERT( psa_hash_finish( &operation,
|
|
actual_hash, sizeof( actual_hash ),
|
|
&actual_hash_length ) );
|
|
ASSERT_COMPARE( expected_hash->x, expected_hash->len,
|
|
actual_hash, actual_hash_length );
|
|
|
|
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 );
|
|
} while( len++ != input->len );
|
|
|
|
exit:
|
|
mbedtls_psa_crypto_free( );
|
|
}
|
|
/* END_CASE */
|