From 1cf81c3c8065c560c0aa79cc77b6e2c22aa064c5 Mon Sep 17 00:00:00 2001 From: Valerio Setti Date: Tue, 12 Dec 2023 15:34:25 +0100 Subject: [PATCH] test_suite_block_cipher: add new data file for PSA/legacy dispatch test Signed-off-by: Valerio Setti --- tests/suites/test_suite_block_cipher.function | 34 ++++++++++++++++ tests/suites/test_suite_block_cipher.psa.data | 39 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/suites/test_suite_block_cipher.psa.data diff --git a/tests/suites/test_suite_block_cipher.function b/tests/suites/test_suite_block_cipher.function index 239568c34..2b166ba50 100644 --- a/tests/suites/test_suite_block_cipher.function +++ b/tests/suites/test_suite_block_cipher.function @@ -92,3 +92,37 @@ exit: mbedtls_block_cipher_free(&ctx); } /* END_CASE */ + +/* BEGIN_CASE */ +void block_cipher_psa_dynamic_dispatch(int cipher_type, int pre_psa_ret, int post_psa_engine) +{ + mbedtls_block_cipher_context_t ctx; + + /* Intentionally no PSA init here! (Will be done later.) */ + + mbedtls_block_cipher_init(&ctx); + + /* Before PSA crypto init */ + TEST_EQUAL(pre_psa_ret, mbedtls_block_cipher_setup(&ctx, cipher_type)); + +#if defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA) + TEST_EQUAL(ctx.engine, MBEDTLS_BLOCK_CIPHER_ENGINE_LEGACY); +#endif + + mbedtls_block_cipher_free(&ctx); + + /* Now initilize PSA Crypto */ + BLOCK_CIPHER_PSA_INIT(); + + mbedtls_block_cipher_init(&ctx); + /* After PSA Crypto init */ + TEST_EQUAL(0, mbedtls_block_cipher_setup(&ctx, cipher_type)); +#if defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA) + TEST_EQUAL(ctx.engine, post_psa_engine); +#endif + +exit: + mbedtls_block_cipher_free(&ctx); + BLOCK_CIPHER_PSA_DONE(); +} +/* END_CASE */ diff --git a/tests/suites/test_suite_block_cipher.psa.data b/tests/suites/test_suite_block_cipher.psa.data new file mode 100644 index 000000000..e9b48e195 --- /dev/null +++ b/tests/suites/test_suite_block_cipher.psa.data @@ -0,0 +1,39 @@ +# These tests behave differently depending on the presence of +# drivers and/or built-in, so they're isolated here for the benefit of +# analyze_outcomes.py (driver vs reference comparison). + +AES - legacy only +depends_on:MBEDTLS_BLOCK_CIPHER_AES_VIA_LEGACY:!MBEDTLS_BLOCK_CIPHER_AES_VIA_PSA +block_cipher_psa_dynamic_dispatch:MBEDTLS_CIPHER_ID_AES:0:MBEDTLS_BLOCK_CIPHER_ENGINE_LEGACY + +AES - driver only +depends_on:!MBEDTLS_BLOCK_CIPHER_AES_VIA_LEGACY:MBEDTLS_BLOCK_CIPHER_AES_VIA_PSA +block_cipher_psa_dynamic_dispatch:MBEDTLS_CIPHER_ID_AES:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA:MBEDTLS_BLOCK_CIPHER_ENGINE_PSA + +AES - legacy + driver +depends_on:MBEDTLS_BLOCK_CIPHER_AES_VIA_LEGACY:MBEDTLS_BLOCK_CIPHER_AES_VIA_PSA +block_cipher_psa_dynamic_dispatch:MBEDTLS_CIPHER_ID_AES:0:MBEDTLS_BLOCK_CIPHER_ENGINE_PSA + +ARIA - legacy only +depends_on:MBEDTLS_BLOCK_CIPHER_ARIA_VIA_LEGACY:!MBEDTLS_BLOCK_CIPHER_ARIA_VIA_PSA +block_cipher_psa_dynamic_dispatch:MBEDTLS_CIPHER_ID_ARIA:0:MBEDTLS_BLOCK_CIPHER_ENGINE_LEGACY + +ARIA - driver only +depends_on:!MBEDTLS_BLOCK_CIPHER_ARIA_VIA_LEGACY:MBEDTLS_BLOCK_CIPHER_ARIA_VIA_PSA +block_cipher_psa_dynamic_dispatch:MBEDTLS_CIPHER_ID_ARIA:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA:MBEDTLS_BLOCK_CIPHER_ENGINE_PSA + +ARIA - legacy + driver +depends_on:MBEDTLS_BLOCK_CIPHER_ARIA_VIA_LEGACY:MBEDTLS_BLOCK_CIPHER_ARIA_VIA_PSA +block_cipher_psa_dynamic_dispatch:MBEDTLS_CIPHER_ID_ARIA:0:MBEDTLS_BLOCK_CIPHER_ENGINE_PSA + +Camellia - legacy only +depends_on:MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_LEGACY:!MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_PSA +block_cipher_psa_dynamic_dispatch:MBEDTLS_CIPHER_ID_CAMELLIA:0:MBEDTLS_BLOCK_CIPHER_ENGINE_LEGACY + +Camellia - driver only +depends_on:!MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_LEGACY:MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_PSA +block_cipher_psa_dynamic_dispatch:MBEDTLS_CIPHER_ID_CAMELLIA:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA:MBEDTLS_BLOCK_CIPHER_ENGINE_PSA + +Camellia - legacy + driver +depends_on:MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_LEGACY:MBEDTLS_BLOCK_CIPHER_CAMELLIA_VIA_PSA +block_cipher_psa_dynamic_dispatch:MBEDTLS_CIPHER_ID_CAMELLIA:0:MBEDTLS_BLOCK_CIPHER_ENGINE_PSA