From c31505c351029652f9b5784d97689094174a57d3 Mon Sep 17 00:00:00 2001 From: gabor-mezei-arm Date: Mon, 12 Apr 2021 17:45:01 +0200 Subject: [PATCH] Test struct initialization Modify tests to test mbedtls_psa_cipher_operation_t, mbedtls_transparent_test_driver_cipher_operation_t and mbedtls_opaque_test_driver_cipher_operation_t struct initialization macros. Signed-off-by: gabor-mezei-arm --- ..._suite_psa_crypto_driver_wrappers.function | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index 7f2ac914b..535d98611 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -600,6 +600,20 @@ void cipher_encrypt_simple_multipart( int alg_arg, PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len, &key ) ); + /* Test operation initialization */ + mbedtls_psa_cipher_operation_t mbedtls_operation = + MBEDTLS_PSA_CIPHER_OPERATION_INIT; + + mbedtls_transparent_test_driver_cipher_operation_t tranparent_operation = + MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT; + + mbedtls_opaque_test_driver_cipher_operation_t opaque_operation = + MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT; + + operation.ctx.mbedtls_ctx = mbedtls_operation; + operation.ctx.transparent_test_driver_ctx = tranparent_operation; + operation.ctx.opaque_test_driver_ctx = opaque_operation; + PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) ); TEST_EQUAL( mbedtls_test_driver_cipher_hooks.hits, 1 ); mbedtls_test_driver_cipher_hooks.hits = 0; @@ -686,6 +700,20 @@ void cipher_encrypt_multipart( int alg_arg, psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); + /* Test operation initialization */ + mbedtls_psa_cipher_operation_t mbedtls_operation = + MBEDTLS_PSA_CIPHER_OPERATION_INIT; + + mbedtls_transparent_test_driver_cipher_operation_t tranparent_operation = + MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT; + + mbedtls_opaque_test_driver_cipher_operation_t opaque_operation = + MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT; + + operation.ctx.mbedtls_ctx = mbedtls_operation; + operation.ctx.transparent_test_driver_ctx = tranparent_operation; + operation.ctx.opaque_test_driver_ctx = opaque_operation; + PSA_ASSERT( psa_crypto_init( ) ); psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT ); @@ -774,6 +802,20 @@ void cipher_decrypt_multipart( int alg_arg, psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); + /* Test operation initialization */ + mbedtls_psa_cipher_operation_t mbedtls_operation = + MBEDTLS_PSA_CIPHER_OPERATION_INIT; + + mbedtls_transparent_test_driver_cipher_operation_t tranparent_operation = + MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT; + + mbedtls_opaque_test_driver_cipher_operation_t opaque_operation = + MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT; + + operation.ctx.mbedtls_ctx = mbedtls_operation; + operation.ctx.transparent_test_driver_ctx = tranparent_operation; + operation.ctx.opaque_test_driver_ctx = opaque_operation; + PSA_ASSERT( psa_crypto_init( ) ); psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT ); @@ -865,6 +907,20 @@ void cipher_decrypt_simple_multipart( int alg_arg, mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init(); mbedtls_test_driver_cipher_hooks.forced_status = force_status; + /* Test operation initialization */ + mbedtls_psa_cipher_operation_t mbedtls_operation = + MBEDTLS_PSA_CIPHER_OPERATION_INIT; + + mbedtls_transparent_test_driver_cipher_operation_t tranparent_operation = + MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT; + + mbedtls_opaque_test_driver_cipher_operation_t opaque_operation = + MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT; + + operation.ctx.mbedtls_ctx = mbedtls_operation; + operation.ctx.transparent_test_driver_ctx = tranparent_operation; + operation.ctx.opaque_test_driver_ctx = opaque_operation; + PSA_ASSERT( psa_crypto_init( ) ); psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_DECRYPT );