From b309eec4a54dcc171c59d74c54ad3838e3537e61 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 20 Nov 2018 20:56:14 +0100 Subject: [PATCH] Move library initialization tests to a new test suite --- tests/CMakeLists.txt | 1 + tests/suites/test_suite_psa_crypto.data | 9 ---- tests/suites/test_suite_psa_crypto.function | 36 ------------- tests/suites/test_suite_psa_crypto_init.data | 8 +++ .../test_suite_psa_crypto_init.function | 50 +++++++++++++++++++ 5 files changed, 59 insertions(+), 45 deletions(-) create mode 100644 tests/suites/test_suite_psa_crypto_init.data create mode 100644 tests/suites/test_suite_psa_crypto_init.function diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 95d60ff31..56ce9338a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -113,6 +113,7 @@ add_test_suite(poly1305) add_test_suite(psa_crypto) add_test_suite(psa_crypto_entropy) add_test_suite(psa_crypto_hash) +add_test_suite(psa_crypto_init) add_test_suite(psa_crypto_metadata) add_test_suite(psa_crypto_persistent_key) add_test_suite(psa_crypto_storage_file) diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data index e1c1b0545..1ce394e5a 100644 --- a/tests/suites/test_suite_psa_crypto.data +++ b/tests/suites/test_suite_psa_crypto.data @@ -1,9 +1,6 @@ PSA compile-time sanity checks static_checks: -PSA init/deinit -init_deinit: - PSA fill 250 slots fill_slots:250 @@ -1829,12 +1826,6 @@ PSA generate key: ECC, SECP256R1, incorrect bit size depends_on:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECDSA_C generate_key:PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP256R1):128:PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY:PSA_ALG_ECDSA_ANY:PSA_ERROR_INVALID_ARGUMENT -PSA validate module initialization: random -validate_module_init_generate_random: - -PSA validate module initialization: key based -validate_module_init_key_based: - persistent key can be accessed after in-memory deletion: AES, 128 bits, CTR depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_PSA_CRYPTO_STORAGE_C persistent_key_load_key_from_storage:"2b7e151628aed2a6abf7158809cf4f3c":PSA_KEY_TYPE_AES:128:PSA_KEY_USAGE_EXPORT:PSA_ALG_CTR:IMPORT_KEY:PSA_SUCCESS diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 53295befa..2fa060b25 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -871,22 +871,6 @@ void static_checks( ) } /* END_CASE */ -/* BEGIN_CASE */ -void init_deinit( ) -{ - psa_status_t status; - int i; - for( i = 0; i <= 1; i++ ) - { - status = psa_crypto_init( ); - TEST_ASSERT( status == PSA_SUCCESS ); - status = psa_crypto_init( ); - TEST_ASSERT( status == PSA_SUCCESS ); - mbedtls_psa_crypto_free( ); - } -} -/* END_CASE */ - /* BEGIN_CASE */ void fill_slots( int max_arg ) { @@ -4018,26 +4002,6 @@ exit: } /* END_CASE */ -/* BEGIN_CASE */ -void validate_module_init_generate_random( ) -{ - psa_status_t status; - uint8_t random[10] = { 0 }; - status = psa_generate_random( random, sizeof( random ) ); - TEST_ASSERT( status == PSA_ERROR_BAD_STATE ); -} -/* END_CASE */ - -/* BEGIN_CASE */ -void validate_module_init_key_based( ) -{ - psa_status_t status; - uint8_t data[10] = { 0 }; - status = psa_import_key( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) ); - TEST_ASSERT( status == PSA_ERROR_BAD_STATE ); -} -/* END_CASE */ - /* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C */ void persistent_key_load_key_from_storage( data_t *data, int type_arg, int bits, int usage_arg, diff --git a/tests/suites/test_suite_psa_crypto_init.data b/tests/suites/test_suite_psa_crypto_init.data new file mode 100644 index 000000000..ad90c17cd --- /dev/null +++ b/tests/suites/test_suite_psa_crypto_init.data @@ -0,0 +1,8 @@ +PSA init/deinit +init_deinit: + +PSA validate module initialization: random +validate_module_init_generate_random: + +PSA validate module initialization: key based +validate_module_init_key_based: diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function new file mode 100644 index 000000000..4ac76a3a5 --- /dev/null +++ b/tests/suites/test_suite_psa_crypto_init.function @@ -0,0 +1,50 @@ +/* BEGIN_HEADER */ +#include + +#if defined(MBEDTLS_PSA_CRYPTO_SPM) +#include "spm/psa_defs.h" +#endif +#include "psa/crypto.h" + +/* END_HEADER */ + +/* BEGIN_DEPENDENCIES + * depends_on:MBEDTLS_PSA_CRYPTO_C + * END_DEPENDENCIES + */ + +/* BEGIN_CASE */ +void init_deinit( ) +{ + psa_status_t status; + int i; + for( i = 0; i <= 1; i++ ) + { + status = psa_crypto_init( ); + TEST_ASSERT( status == PSA_SUCCESS ); + status = psa_crypto_init( ); + TEST_ASSERT( status == PSA_SUCCESS ); + mbedtls_psa_crypto_free( ); + } +} +/* END_CASE */ + +/* BEGIN_CASE */ +void validate_module_init_generate_random( ) +{ + psa_status_t status; + uint8_t random[10] = { 0 }; + status = psa_generate_random( random, sizeof( random ) ); + TEST_ASSERT( status == PSA_ERROR_BAD_STATE ); +} +/* END_CASE */ + +/* BEGIN_CASE */ +void validate_module_init_key_based( ) +{ + psa_status_t status; + uint8_t data[10] = { 0 }; + status = psa_import_key( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) ); + TEST_ASSERT( status == PSA_ERROR_BAD_STATE ); +} +/* END_CASE */