diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data index b74a959bbb..49685b4f4e 100644 --- a/tests/suites/test_suite_psa_crypto.data +++ b/tests/suites/test_suite_psa_crypto.data @@ -2110,22 +2110,6 @@ PSA AEAD encrypt/decrypt: invalid algorithm (ChaCha20) depends_on:MBEDTLS_CHACHA20_C aead_encrypt_decrypt:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_STREAM_CIPHER:"":"":"":PSA_ERROR_NOT_SUPPORTED -PSA Multipart AEAD encrypt/decrypt, AES-GCM, 19 bytes #1 -depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES -aead_multipart_encrypt_decrypt:PSA_KEY_TYPE_AES:"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF":PSA_ALG_GCM:"000102030405060708090A0B0C0D0E0F":"000102030405060708090A0B":0:"0C0D0E0F101112131415161718191A1B1C1D1E":1:PSA_SUCCESS - -PSA Multipart AEAD encrypt/decrypt, AES GCM, 19 bytes #2 -depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES -aead_multipart_encrypt_decrypt:PSA_KEY_TYPE_AES:"D7828D13B2B0BDC325A76236DF93CC6B":PSA_ALG_GCM:"000102030405060708090A0B0C0D0E0F":"EC46BB63B02520C33C49FD70":0:"B96B49E21D621741632875DB7F6C9243D2D7C2":1:PSA_SUCCESS - -PSA Multipart AEAD encrypt/decrypt, AES-GCM, 19 bytes, 12 byte nonce , 1 -depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES -aead_multipart_encrypt_decrypt:PSA_KEY_TYPE_AES:"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF":PSA_ALG_GCM:"E462C58482FE8264AEEB7231":"000102030405060708090A0B":0:"0C0D0E0F101112131415161718191A1B1C1D1E":1:PSA_SUCCESS - -PSA Multipart AEAD encrypt/decrypt, AES GCM, 19 bytes, 12 byte nonce , 2 -depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES -aead_multipart_encrypt_decrypt:PSA_KEY_TYPE_AES:"D7828D13B2B0BDC325A76236DF93CC6B":PSA_ALG_GCM:"E462C58482FE8264AEEB7231":"EC46BB63B02520C33C49FD70":0:"B96B49E21D621741632875DB7F6C9243D2D7C2":1:PSA_SUCCESS - PSA Multipart AEAD encrypt, AES-GCM, 128 bytes #1 depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES aead_multipart_encrypt:PSA_KEY_TYPE_AES:"a0ec7b0052541d9e9c091fb7fc481409":PSA_ALG_GCM:"00e440846db73a490573deaf3728c94f":"a3cfcb832e935eb5bc3812583b3a1b2e82920c07fda3668a35d939d8f11379bb606d39e6416b2ef336fffb15aec3f47a71e191f4ff6c56ff15913562619765b26ae094713d60bab6ab82bfc36edaaf8c7ce2cf5906554dcc5933acdb9cb42c1d24718efdc4a09256020b024b224cfe602772bd688c6c8f1041a46f7ec7d51208":0:"5431d93278c35cfcd7ffa9ce2de5c6b922edffd5055a9eaa5b54cae088db007cf2d28efaf9edd1569341889073e87c0a88462d77016744be62132fd14a243ed6e30e12cd2f7d08a8daeec161691f3b27d4996df8745d74402ee208e4055615a8cb069d495cf5146226490ac615d7b17ab39fb4fdd098e4e7ee294d34c1312826":1:"3b6de52f6e582d317f904ee768895bd4d0790912efcf27b58651d0eb7eb0b2f07222c6ffe9f7e127d98ccb132025b098a67dc0ec0083235e9f83af1ae1297df4319547cbcb745cebed36abc1f32a059a05ede6c00e0da097521ead901ad6a73be20018bda4c323faa135169e21581e5106ac20853642e9d6b17f1dd925c872814365847fe0b7b7fbed325953df344a96" @@ -2366,13 +2350,13 @@ PSA Multipart AEAD decrypt: ChaCha20-Poly1305 (good tag, zero-length input) depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20 aead_multipart_decrypt:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:"070000004041424344454647":"":1:"a0784d7a4716f3feb4f64e7f4b39bf04":1:"":PSA_SUCCESS -PSA Multipart AEAD encrypt/decrypt: invalid algorithm (CTR) +PSA Multipart AEAD decrypt: invalid algorithm (CTR) depends_on:MBEDTLS_AES_C:MBEDTLS_GCM_C -aead_multipart_encrypt_decrypt:PSA_KEY_TYPE_AES:"D7828D13B2B0BDC325A76236DF93CC6B":PSA_ALG_CTR:"000102030405060708090A0B0C0D0E0F":"":0:"":1:PSA_ERROR_INVALID_ARGUMENT +aead_multipart_decrypt:PSA_KEY_TYPE_AES:"D7828D13B2B0BDC325A76236DF93CC6B":PSA_ALG_CTR:"000102030405060708090A0B0C0D0E0F":"":0:"":1:"":PSA_ERROR_INVALID_ARGUMENT -PSA Multipart AEAD encrypt/decrypt: invalid algorithm (ChaCha20) +PSA Multipart AEAD decrypt: invalid algorithm (ChaCha20) depends_on:MBEDTLS_CHACHA20_C -aead_multipart_encrypt_decrypt:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_STREAM_CIPHER:"":"":1:"":1:PSA_ERROR_INVALID_ARGUMENT +aead_multipart_decrypt:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_STREAM_CIPHER:"":"":1:"":1:"":PSA_ERROR_INVALID_ARGUMENT PSA Multipart Nonce Generation, AES - GCM, CAVS 14.0, IV = 12 depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index fdec30fb9f..1a5c23e8e0 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -705,404 +705,6 @@ exit: PSA_DONE( ); } -void aead_multipart_encrypt_decrypt_internal( int key_type_arg, - data_t *key_data, - int alg_arg, - data_t *nonce, - data_t *additional_data, - int ad_part_len, - data_t *input_data, - int data_part_len, - 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; - psa_aead_operation_t operation; - unsigned char *output_data = NULL; - unsigned char *part_data = NULL; - unsigned char *final_data = NULL; - size_t part_data_size; - size_t output_size = 0; - size_t finish_output_size = 0; - size_t output_length = 0; - unsigned char *output_data2 = NULL; - size_t output_size2 = 0; - size_t output_length2 = 0; - size_t key_bits = 0; - size_t tag_length = 0; - size_t tag_size = 0; - size_t nonce_length = 0; - uint8_t nonce_buffer[PSA_AEAD_NONCE_MAX_SIZE]; - uint8_t tag_buffer[PSA_AEAD_TAG_MAX_SIZE]; - uint32_t part_offset = 0; - size_t part_length = 0; - size_t output_part_length = 0; - psa_status_t status = PSA_ERROR_GENERIC_ERROR; - psa_status_t expected_status = expected_status_arg; - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - - PSA_ASSERT( psa_crypto_init( ) ); - - psa_set_key_usage_flags( &attributes, - PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT ); - 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 ); - - tag_length = PSA_AEAD_TAG_LENGTH( key_type, key_bits, alg ); - - TEST_ASSERT( tag_length <= PSA_AEAD_TAG_MAX_SIZE ); - - output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg, input_data->len ); - - ASSERT_ALLOC( output_data, output_size ); - - finish_output_size = PSA_AEAD_FINISH_OUTPUT_SIZE( key_type, alg ); - - TEST_ASSERT( finish_output_size <= PSA_AEAD_FINISH_OUTPUT_MAX_SIZE ); - - ASSERT_ALLOC( final_data, finish_output_size ); - - operation = psa_aead_operation_init( ); - - status = psa_aead_encrypt_setup( &operation, key, alg ); - - /* If the operation is not supported, just skip and not fail in case the - * encryption involves a common limitation of cryptography hardwares and - * an alternative implementation. */ - if( status == PSA_ERROR_NOT_SUPPORTED ) - { - MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 ); - MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce->len ); - } - - if( status != PSA_SUCCESS ) - { - TEST_EQUAL( status, expected_status ); - goto exit; - } - - nonce_length = nonce->len; - status = psa_aead_set_nonce( &operation, nonce->x, nonce->len ); - - if( status != PSA_SUCCESS ) - { - TEST_EQUAL( status, expected_status ); - goto exit; - } - -#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM) - if( operation.alg == PSA_ALG_GCM ) - { - status = psa_aead_set_lengths( &operation, additional_data->len, - input_data->len ); - - if( status != PSA_SUCCESS ) - { - TEST_EQUAL( status, expected_status ); - goto exit; - } - } -#endif - - if( ad_part_len != -1 ) - { - part_offset = 0; - - while( part_offset < additional_data->len ) - { - if( additional_data->len - part_offset < ( uint32_t ) ad_part_len ) - { - part_length = additional_data->len - part_offset; - } - else - { - part_length = ad_part_len; - } - - status = psa_aead_update_ad( &operation, - additional_data->x + part_offset, - part_length ); - - if( status != PSA_SUCCESS ) - { - TEST_EQUAL( status, expected_status ); - goto exit; - } - - part_offset += part_length; - } - } - else - { - status = psa_aead_update_ad( &operation, additional_data->x, - additional_data->len ); - - if( status != PSA_SUCCESS ) - { - TEST_EQUAL( status, expected_status ); - goto exit; - } - } - - if( data_part_len != -1 ) - { - /* Pass data in parts */ - part_data_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg, - ( size_t ) data_part_len ); - - ASSERT_ALLOC( part_data, part_data_size ); - - part_offset = 0; - - while( part_offset < input_data->len ) - { - if( input_data->len - part_offset < ( uint32_t ) data_part_len ) - { - part_length = input_data->len - part_offset; - } - else - { - part_length = data_part_len; - } - - status = psa_aead_update( &operation, - ( input_data->x + part_offset ), - part_length, part_data, - part_data_size, &output_part_length ); - - if( status != PSA_SUCCESS ) - { - TEST_EQUAL( status, expected_status ); - goto exit; - } - - if( output_data && output_part_length ) - { - memcpy( ( output_data + part_offset ), part_data, - output_part_length ); - } - - part_offset += part_length; - output_length += output_part_length; - } - } - else - { - status = psa_aead_update( &operation, input_data->x, - input_data->len, output_data, - output_size, &output_length ); - - if( status != PSA_SUCCESS ) - { - TEST_EQUAL( status, expected_status ); - goto exit; - } - } - - status = psa_aead_finish( &operation, final_data, - finish_output_size, - &output_part_length, - tag_buffer, tag_length, - &tag_size ); - - if( status != PSA_SUCCESS ) - { - TEST_EQUAL( status, expected_status ); - goto exit; - } - - if( output_data && output_part_length ) - { - memcpy( ( output_data + output_length ), final_data, - output_part_length ); - } - - output_length += output_part_length; - - /* For all currently defined algorithms, PSA_AEAD_ENCRYPT_OUTPUT_SIZE - * should be exact. */ - if( expected_status != PSA_ERROR_INVALID_ARGUMENT ) - { - TEST_EQUAL( ( output_length + tag_length ), - PSA_AEAD_ENCRYPT_OUTPUT_SIZE( key_type, alg, - input_data->len ) ); - } - - TEST_EQUAL( tag_length, tag_size ); - - if( PSA_SUCCESS == expected_status ) - { - output_size2 = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg, - output_length ); - ASSERT_ALLOC( output_data2, output_size2 ); - - /* For all currently defined algorithms, PSA_AEAD_DECRYPT_OUTPUT_SIZE - * should be exact. */ - TEST_EQUAL( input_data->len, - PSA_AEAD_DECRYPT_OUTPUT_SIZE( key_type, alg, - ( output_length + - tag_length ) ) ); - - TEST_ASSERT( input_data->len <= - PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE( output_length + - tag_length ) ); - - operation = psa_aead_operation_init( ); - - status = psa_aead_decrypt_setup( &operation, key, alg ); - - /* If the operation is not supported, just skip and not fail in case the - * encryption involves a common limitation of cryptography hardwares and - * an alternative implementation. */ - if( status == PSA_ERROR_NOT_SUPPORTED ) - { - MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 ); - MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, - nonce->len ); - } - - TEST_EQUAL( status, expected_status ); - - if( nonce->len == 0 ) - { - /* Use previously generated nonce. */ - status = psa_aead_set_nonce( &operation, nonce_buffer, - nonce_length ); - } - else - { - nonce_length = nonce->len; - status = psa_aead_set_nonce( &operation, nonce->x, nonce->len ); - } - - if( status != PSA_SUCCESS ) - { - TEST_EQUAL( status, expected_status); - } - -#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM) - if( operation.alg == PSA_ALG_GCM ) - { - status = psa_aead_set_lengths( &operation, additional_data->len, - output_length ); - - if( status != PSA_SUCCESS ) - { - TEST_EQUAL( status, expected_status ); - } - } -#endif - - if( ad_part_len != -1 ) - { - part_offset = 0; - - while( part_offset < additional_data->len ) - { - if( additional_data->len - part_offset < - ( uint32_t ) ad_part_len ) - { - part_length = additional_data->len - part_offset; - } - else - { - part_length = ad_part_len; - } - - PSA_ASSERT( psa_aead_update_ad( &operation, - additional_data->x + - part_offset, - part_length ) ); - - part_offset += part_length; - } - } - else - { - PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x, - additional_data->len ) ); - } - - if( data_part_len != -1 ) - { - /* Pass data in parts */ - part_data_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg, - ( size_t ) data_part_len ); - - part_data = NULL; - ASSERT_ALLOC( part_data, part_data_size ); - - part_offset = 0; - - while( part_offset < output_length ) - { - if( ( output_length - part_offset ) < - ( uint32_t ) data_part_len ) - { - part_length = ( output_length - part_offset ); - } - else - { - part_length = data_part_len; - } - - PSA_ASSERT( psa_aead_update( &operation, - ( output_data + part_offset ), - part_length, part_data, - part_data_size, - &output_part_length ) ); - - if( output_data2 && output_part_length ) - { - memcpy( ( output_data2 + part_offset ), - part_data, output_part_length ); - } - - part_offset += part_length; - output_length2 += output_part_length; - } - } - else - { - PSA_ASSERT( psa_aead_update( &operation, output_data, - output_length, output_data2, - output_size2, &output_length2 ) ); - } - - PSA_ASSERT( psa_aead_verify( &operation, final_data, - finish_output_size, - &output_part_length, - tag_buffer, tag_length ) ); - - if( output_data2 && output_part_length ) - { - memcpy( ( output_data2 + output_length2 ), final_data, - output_part_length ); - } - - output_length2 += output_part_length; - - ASSERT_COMPARE( input_data->x, input_data->len, - output_data2, output_length2 ); - } - -exit: - psa_destroy_key( key ); - psa_aead_abort( &operation ); - mbedtls_free( output_data ); - mbedtls_free( output_data2 ); - mbedtls_free( part_data ); - mbedtls_free( final_data ); - PSA_DONE( ); -} - /* END_HEADER */ /* BEGIN_DEPENDENCIES @@ -4039,54 +3641,6 @@ exit: } /* END_CASE */ -/* BEGIN_CASE */ -void aead_multipart_encrypt_decrypt( int key_type_arg, data_t *key_data, - int alg_arg, - data_t *nonce, - data_t *additional_data, - int test_ad_mp_arg, - data_t *input_data, - int test_data_mp_arg, - int expected_status_arg ) -{ - size_t ad_part_len = 0; - size_t data_part_len = 0; - - if( test_ad_mp_arg == 1 ) - { - for( ad_part_len = 1; ad_part_len <= additional_data->len; - ad_part_len++ ) - { - mbedtls_test_set_step( ad_part_len ); - - aead_multipart_encrypt_decrypt_internal( key_type_arg, key_data, - alg_arg, nonce, - additional_data, - ad_part_len, - input_data, -1, - expected_status_arg ); - } - } - - if( test_data_mp_arg == 1 ) - { - for( data_part_len = 1; data_part_len <= input_data->len; - data_part_len++ ) - { - aead_multipart_encrypt_decrypt_internal( key_type_arg, key_data, - alg_arg, nonce, - additional_data, -1, - input_data, data_part_len, - expected_status_arg ); - } - } - - goto exit; - -exit: -} -/* END_CASE */ - /* BEGIN_CASE */ void aead_multipart_decrypt( int key_type_arg, data_t *key_data, int alg_arg,