Merge pull request #5516 from tom-daubney-arm/M-AEAD_dispatch_tests
M-AEAD driver dispatch tests
This commit is contained in:
commit
cccbe0eb88
@ -780,3 +780,15 @@ asymmetric_encrypt:PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256):"30818902818100af057d396ee8
|
||||
PSA encrypt transparent driver: fallback not available RSA OAEP-SHA-256
|
||||
depends_on:!MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP
|
||||
asymmetric_encrypt:PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256):"30818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001":"af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3":"874bf0ffc2f2a71d14671ddd0171c954d7fdbf50281e4f6d99ea0e1ebcf82faa58e7b595ffb293d1abe17f110b37c48cc0f36c37e84d876621d327f64bbe08457d3ec4098ba2fa0a319fba411c2841ed7be83196a8cdf9daa5d00694bc335fc4c32217fe0488bce9cb7202e59468b1ead119000477db2ca797fac19eda3f58c1":"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad":"":"":PSA_ERROR_NOT_SUPPORTED:PSA_ERROR_NOT_SUPPORTED
|
||||
|
||||
PSA multi-part AEAD encrypt setup, AES-GCM, 128 bytes #1
|
||||
depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
|
||||
aead_encrypt_setup:PSA_KEY_TYPE_AES:"a0ec7b0052541d9e9c091fb7fc481409":PSA_ALG_GCM:"00e440846db73a490573deaf3728c94f":"a3cfcb832e935eb5bc3812583b3a1b2e82920c07fda3668a35d939d8f11379bb606d39e6416b2ef336fffb15aec3f47a71e191f4ff6c56ff15913562619765b26ae094713d60bab6ab82bfc36edaaf8c7ce2cf5906554dcc5933acdb9cb42c1d24718efdc4a09256020b024b224cfe602772bd688c6c8f1041a46f7ec7d51208":"5431d93278c35cfcd7ffa9ce2de5c6b922edffd5055a9eaa5b54cae088db007cf2d28efaf9edd1569341889073e87c0a88462d77016744be62132fd14a243ed6e30e12cd2f7d08a8daeec161691f3b27d4996df8745d74402ee208e4055615a8cb069d495cf5146226490ac615d7b17ab39fb4fdd098e4e7ee294d34c1312826":"3b6de52f6e582d317f904ee768895bd4d0790912efcf27b58651d0eb7eb0b2f07222c6ffe9f7e127d98ccb132025b098a67dc0ec0083235e9f83af1ae1297df4319547cbcb745cebed36abc1f32a059a05ede6c00e0da097521ead901ad6a73be20018bda4c323faa135169e21581e5106ac20853642e9d6b17f1dd925c87281":"4365847fe0b7b7fbed325953df344a96":PSA_SUCCESS:PSA_SUCCESS
|
||||
|
||||
PSA multi-part AEAD encrypt setup, AES-GCM, 128 bytes #1, fallback
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_GCM_C
|
||||
aead_encrypt_setup:PSA_KEY_TYPE_AES:"a0ec7b0052541d9e9c091fb7fc481409":PSA_ALG_GCM:"00e440846db73a490573deaf3728c94f":"a3cfcb832e935eb5bc3812583b3a1b2e82920c07fda3668a35d939d8f11379bb606d39e6416b2ef336fffb15aec3f47a71e191f4ff6c56ff15913562619765b26ae094713d60bab6ab82bfc36edaaf8c7ce2cf5906554dcc5933acdb9cb42c1d24718efdc4a09256020b024b224cfe602772bd688c6c8f1041a46f7ec7d51208":"5431d93278c35cfcd7ffa9ce2de5c6b922edffd5055a9eaa5b54cae088db007cf2d28efaf9edd1569341889073e87c0a88462d77016744be62132fd14a243ed6e30e12cd2f7d08a8daeec161691f3b27d4996df8745d74402ee208e4055615a8cb069d495cf5146226490ac615d7b17ab39fb4fdd098e4e7ee294d34c1312826":"3b6de52f6e582d317f904ee768895bd4d0790912efcf27b58651d0eb7eb0b2f07222c6ffe9f7e127d98ccb132025b098a67dc0ec0083235e9f83af1ae1297df4319547cbcb745cebed36abc1f32a059a05ede6c00e0da097521ead901ad6a73be20018bda4c323faa135169e21581e5106ac20853642e9d6b17f1dd925c87281":"4365847fe0b7b7fbed325953df344a96":PSA_ERROR_NOT_SUPPORTED:PSA_SUCCESS
|
||||
|
||||
PSA multi-part AEAD encrypt setup, AES-GCM, 128 bytes #1, INSUFFICIENT_MEMORY
|
||||
depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
|
||||
aead_encrypt_setup:PSA_KEY_TYPE_AES:"a0ec7b0052541d9e9c091fb7fc481409":PSA_ALG_GCM:"00e440846db73a490573deaf3728c94f":"a3cfcb832e935eb5bc3812583b3a1b2e82920c07fda3668a35d939d8f11379bb606d39e6416b2ef336fffb15aec3f47a71e191f4ff6c56ff15913562619765b26ae094713d60bab6ab82bfc36edaaf8c7ce2cf5906554dcc5933acdb9cb42c1d24718efdc4a09256020b024b224cfe602772bd688c6c8f1041a46f7ec7d51208":"5431d93278c35cfcd7ffa9ce2de5c6b922edffd5055a9eaa5b54cae088db007cf2d28efaf9edd1569341889073e87c0a88462d77016744be62132fd14a243ed6e30e12cd2f7d08a8daeec161691f3b27d4996df8745d74402ee208e4055615a8cb069d495cf5146226490ac615d7b17ab39fb4fdd098e4e7ee294d34c1312826":"3b6de52f6e582d317f904ee768895bd4d0790912efcf27b58651d0eb7eb0b2f07222c6ffe9f7e127d98ccb132025b098a67dc0ec0083235e9f83af1ae1297df4319547cbcb745cebed36abc1f32a059a05ede6c00e0da097521ead901ad6a73be20018bda4c323faa135169e21581e5106ac20853642e9d6b17f1dd925c87281":"4365847fe0b7b7fbed325953df344a96":PSA_ERROR_INSUFFICIENT_MEMORY:PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
|
@ -2328,3 +2328,123 @@ exit:
|
||||
PSA_DONE( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aead_encrypt_setup( int key_type_arg, data_t *key_data,
|
||||
int alg_arg,
|
||||
data_t *nonce,
|
||||
data_t *additional_data,
|
||||
data_t *input_data,
|
||||
data_t *expected_ciphertext,
|
||||
data_t *expected_tag,
|
||||
int forced_status_arg,
|
||||
int expected_status_arg )
|
||||
{
|
||||
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
psa_key_type_t key_type = key_type_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
size_t key_bits;
|
||||
psa_status_t forced_status = forced_status_arg;
|
||||
psa_status_t expected_status = expected_status_arg;
|
||||
uint8_t *output_data = NULL;
|
||||
size_t output_size = 0;
|
||||
size_t output_length = 0;
|
||||
size_t finish_output_length = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
|
||||
size_t tag_length = 0;
|
||||
uint8_t tag_buffer[PSA_AEAD_TAG_MAX_SIZE];
|
||||
|
||||
psa_aead_operation_t operation = psa_aead_operation_init();
|
||||
|
||||
mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
|
||||
|
||||
PSA_INIT( );
|
||||
|
||||
mbedtls_test_driver_aead_hooks.forced_status = forced_status;
|
||||
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
|
||||
psa_set_key_algorithm( &attributes, alg );
|
||||
psa_set_key_type( &attributes, key_type );
|
||||
|
||||
PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
|
||||
&key ) );
|
||||
PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
|
||||
key_bits = psa_get_key_bits( &attributes );
|
||||
|
||||
output_size = input_data->len + PSA_AEAD_TAG_LENGTH( key_type, key_bits,
|
||||
alg );
|
||||
|
||||
/* For all currently defined algorithms, PSA_AEAD_ENCRYPT_OUTPUT_SIZE
|
||||
* should be exact. */
|
||||
TEST_EQUAL( output_size,
|
||||
PSA_AEAD_ENCRYPT_OUTPUT_SIZE( key_type, alg, input_data->len ) );
|
||||
TEST_ASSERT( output_size <=
|
||||
PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( input_data->len ) );
|
||||
ASSERT_ALLOC( output_data, output_size );
|
||||
|
||||
status = psa_aead_encrypt_setup( &operation, key, alg );
|
||||
|
||||
TEST_EQUAL( status, expected_status );
|
||||
TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_encrypt_setup, 1 );
|
||||
|
||||
if( status == PSA_SUCCESS )
|
||||
{
|
||||
/* Set the nonce. */
|
||||
PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) );
|
||||
|
||||
TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_set_nonce,
|
||||
forced_status == PSA_SUCCESS ? 1 : 0 );
|
||||
|
||||
/* Check hooks hits and
|
||||
* set length (additional data and data to encrypt) */
|
||||
PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len,
|
||||
input_data->len ) );
|
||||
|
||||
TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_set_lengths,
|
||||
forced_status == PSA_SUCCESS ? 1 : 0 );
|
||||
|
||||
/* Pass the additional data */
|
||||
PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
|
||||
additional_data->len ) );
|
||||
|
||||
TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_update_ad,
|
||||
forced_status == PSA_SUCCESS ? 1 : 0 );
|
||||
|
||||
/* Pass the data to encrypt */
|
||||
PSA_ASSERT( psa_aead_update( &operation, input_data->x, input_data->len,
|
||||
output_data, output_size, &output_length ) );
|
||||
|
||||
TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_update,
|
||||
forced_status == PSA_SUCCESS ? 1 : 0 );
|
||||
|
||||
/* Finish the encryption operation */
|
||||
PSA_ASSERT( psa_aead_finish( &operation, output_data + output_length,
|
||||
output_size - output_length,
|
||||
&finish_output_length, tag_buffer,
|
||||
PSA_AEAD_TAG_MAX_SIZE, &tag_length ) );
|
||||
|
||||
TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_finish,
|
||||
forced_status == PSA_SUCCESS ? 1 : 0 );
|
||||
|
||||
TEST_EQUAL( mbedtls_test_driver_aead_hooks.hits_abort,
|
||||
forced_status == PSA_SUCCESS ? 1 : 0 );
|
||||
|
||||
/* Compare output_data and expected_ciphertext */
|
||||
ASSERT_COMPARE( expected_ciphertext->x, expected_ciphertext->len,
|
||||
output_data, output_length );
|
||||
|
||||
TEST_EQUAL( output_length + finish_output_length, expected_ciphertext->len );
|
||||
|
||||
/* Compare tag and expected_tag */
|
||||
ASSERT_COMPARE( expected_tag->x, expected_tag->len, tag_buffer, tag_length );
|
||||
}
|
||||
|
||||
exit:
|
||||
/* Cleanup */
|
||||
PSA_ASSERT( psa_destroy_key( key ) );
|
||||
mbedtls_free( output_data );
|
||||
PSA_DONE( );
|
||||
mbedtls_test_driver_aead_hooks = mbedtls_test_driver_aead_hooks_init();
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Loading…
Reference in New Issue
Block a user