From 445e2257453520b3af895b62649415771d3f4bfc Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 20 Nov 2018 21:00:42 +0100 Subject: [PATCH] Test that deinit deactivates random generation and key slots --- tests/suites/test_suite_psa_crypto_init.data | 16 +++++++++----- .../test_suite_psa_crypto_init.function | 22 +++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto_init.data b/tests/suites/test_suite_psa_crypto_init.data index ad90c17cd..61f067d06 100644 --- a/tests/suites/test_suite_psa_crypto_init.data +++ b/tests/suites/test_suite_psa_crypto_init.data @@ -1,8 +1,14 @@ PSA init/deinit -init_deinit: +init_deinit:2 -PSA validate module initialization: random -validate_module_init_generate_random: +No random without init +validate_module_init_generate_random:0 -PSA validate module initialization: key based -validate_module_init_key_based: +No key slot access without init +validate_module_init_key_based:0 + +No random after deinit +validate_module_init_generate_random:1 + +No key slot access after deinit +validate_module_init_key_based:1 diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function index 4ac76a3a5..7fccc13d2 100644 --- a/tests/suites/test_suite_psa_crypto_init.function +++ b/tests/suites/test_suite_psa_crypto_init.function @@ -14,11 +14,11 @@ */ /* BEGIN_CASE */ -void init_deinit( ) +void init_deinit( int count ) { psa_status_t status; int i; - for( i = 0; i <= 1; i++ ) + for( i = 0; i < count; i++ ) { status = psa_crypto_init( ); TEST_ASSERT( status == PSA_SUCCESS ); @@ -30,20 +30,34 @@ void init_deinit( ) /* END_CASE */ /* BEGIN_CASE */ -void validate_module_init_generate_random( ) +void validate_module_init_generate_random( int count ) { psa_status_t status; uint8_t random[10] = { 0 }; + int i; + for( i = 0; i < count; i++ ) + { + status = psa_crypto_init( ); + TEST_ASSERT( status == PSA_SUCCESS ); + mbedtls_psa_crypto_free( ); + } status = psa_generate_random( random, sizeof( random ) ); TEST_ASSERT( status == PSA_ERROR_BAD_STATE ); } /* END_CASE */ /* BEGIN_CASE */ -void validate_module_init_key_based( ) +void validate_module_init_key_based( int count ) { psa_status_t status; uint8_t data[10] = { 0 }; + int i; + for( i = 0; i < count; i++ ) + { + status = psa_crypto_init( ); + TEST_ASSERT( status == PSA_SUCCESS ); + mbedtls_psa_crypto_free( ); + } status = psa_import_key( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) ); TEST_ASSERT( status == PSA_ERROR_BAD_STATE ); }