From dd835cbea6d8788dcc2f662bf65c30f85f73bcb0 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 15 May 2019 16:14:57 +0200 Subject: [PATCH] Add a few tests for persistent attributes psa_set_key_lifetime and psa_set_key_id aren't pure setters: they also set the other attribute in some conditions. Add dedicated tests for this behavior. --- tests/suites/test_suite_psa_crypto.data | 15 ++++++++++++++ tests/suites/test_suite_psa_crypto.function | 23 +++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data index 4a1a04fc4..1d3e3cfe2 100644 --- a/tests/suites/test_suite_psa_crypto.data +++ b/tests/suites/test_suite_psa_crypto.data @@ -4,6 +4,21 @@ static_checks: PSA key attributes structure attributes_set_get:0x6963:PSA_KEY_LIFETIME_PERSISTENT:PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_CCM:PSA_KEY_TYPE_AES:128 +PSA key attributes: id only +persistence_attributes:0x1234:-1:-1:0x1234:PSA_KEY_LIFETIME_PERSISTENT + +PSA key attributes: lifetime=3 only +persistence_attributes:-1:3:-1:0:3 + +PSA key attributes: id then back to volatile +persistence_attributes:0x1234:PSA_KEY_LIFETIME_VOLATILE:-1:0:PSA_KEY_LIFETIME_VOLATILE + +PSA key attributes: id then lifetime +persistence_attributes:0x1234:3:-1:0x1234:3 + +PSA key attributes: lifetime then id +persistence_attributes:0x1234:3:0x1235:0x1235:3 + PSA import/export raw: 0 bytes import_export:"":PSA_KEY_TYPE_RAW_DATA:0:PSA_KEY_USAGE_EXPORT:0:0:PSA_SUCCESS:1 diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 4ae9deb09..cbe6616fd 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -1204,6 +1204,29 @@ void attributes_set_get( int id_arg, int lifetime_arg, } /* END_CASE */ +/* BEGIN_CASE */ +void persistence_attributes( int id1_arg, int lifetime_arg, int id2_arg, + int expected_id_arg, int expected_lifetime_arg ) +{ + psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; + psa_key_id_t id1 = id1_arg; + psa_key_lifetime_t lifetime = lifetime_arg; + psa_key_id_t id2 = id2_arg; + psa_key_id_t expected_id = expected_id_arg; + psa_key_lifetime_t expected_lifetime = expected_lifetime_arg; + + if( id1_arg != -1 ) + psa_set_key_id( &attributes, id1 ); + if( lifetime_arg != -1 ) + psa_set_key_lifetime( &attributes, lifetime ); + if( id2_arg != -1 ) + psa_set_key_id( &attributes, id2 ); + + TEST_EQUAL( psa_get_key_id( &attributes ), expected_id ); + TEST_EQUAL( psa_get_key_lifetime( &attributes ), expected_lifetime ); +} +/* END_CASE */ + /* BEGIN_CASE */ void import( data_t *data, int type_arg, int attr_bits_arg,