mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-25 01:35:38 +00:00
aead test scenario
This commit is contained in:
parent
579d359007
commit
9112693930
|
@ -573,3 +573,73 @@ exit:
|
|||
mbedtls_psa_crypto_free( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aead_encrypt_decrypt( int key_type_arg, char *key_hex,
|
||||
int alg_arg, char *input_hex,
|
||||
cahr* additional_data, int additional_data_length )
|
||||
{
|
||||
int slot = 1;
|
||||
psa_key_type_t key_type = key_type_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
unsigned char *key_data = NULL;
|
||||
size_t key_size;
|
||||
unsigned char *input_data = NULL;
|
||||
size_t input_size;
|
||||
unsigned char *output_data = NULL;
|
||||
size_t output_length;
|
||||
unsigned char *output_data2 = NULL;
|
||||
size_t output_length2;
|
||||
psa_status_t actual_status;
|
||||
uint8_t* nonce = NULL;
|
||||
size_t nonce_length = 16;
|
||||
size_t tag_length = 16;
|
||||
|
||||
|
||||
key_data = unhexify_alloc( key_hex, &key_size );
|
||||
TEST_ASSERT( key_data != NULL );
|
||||
input_data = unhexify_alloc( input_hex, &input_size );
|
||||
TEST_ASSERT( input_data != NULL );
|
||||
output_data = mbedtls_calloc( 1, input_size + tag_length );
|
||||
TEST_ASSERT( output_data != NULL );
|
||||
if( alg == PSA_ALG_CCM )
|
||||
{
|
||||
nonce_length = 12;
|
||||
}
|
||||
nonce = mbedtls_calloc( 1, nonce_length );
|
||||
TEST_ASSERT( nonce != NULL );
|
||||
for( int i = 0; i < nonce_length; ++nonce_length )
|
||||
nonce[i] = i;
|
||||
|
||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||
|
||||
TEST_ASSERT( psa_import_key( slot, key_type,
|
||||
key_data, key_size ) == PSA_SUCCESS );
|
||||
|
||||
TEST_ASSERT( psa_aead_encrypt( slot, alg,
|
||||
nonce, nonce_length,
|
||||
additional_data, additional_data_length,
|
||||
input_data, input_size, output_data,
|
||||
input_size, &output_length ) );
|
||||
|
||||
output_data2 = mbedtls_calloc( 1, output_length );
|
||||
TEST_ASSERT( output_data2 != NULL );
|
||||
|
||||
TEST_ASSERT( psa_aead_decrypt( slot, alg,
|
||||
nonce, nonce_length,
|
||||
additional_data, additional_data_length,
|
||||
output_data, output_length - tag_length, output_data2,
|
||||
output_length, &output_length2 ) );
|
||||
|
||||
TEST_ASSERT( memcmp( input, output_data2,
|
||||
input_size ) == 0 );
|
||||
|
||||
|
||||
exit:
|
||||
psa_destroy_key( slot );
|
||||
mbedtls_free( key_data );
|
||||
mbedtls_free( input_data );
|
||||
mbedtls_free( signature );
|
||||
mbedtls_psa_crypto_free( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
|
Loading…
Reference in a new issue