Add tests that checks key management corner cases
- import a key into a non empty key slot.
- export a key from invalid slot number.
diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data
index ecd2149..64cc16c 100644
--- a/tests/suites/test_suite_psa_crypto.data
+++ b/tests/suites/test_suite_psa_crypto.data
@@ -31,6 +31,19 @@
depends_on:MBEDTLS_AES_C
import_export:"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef":PSA_KEY_TYPE_AES:PSA_ALG_CTR:PSA_KEY_USAGE_EXPORT:256:0:PSA_SUCCESS:1
+PSA import to non empty key slot
+depends_on:MBEDTLS_AES_C
+import_key_nonempty_slot
+
+PSA export empty key slot
+export_invalid_slot:1:PSA_ERROR_EMPTY_SLOT
+
+PSA export out of range key slot - lower bound
+export_invalid_slot:0:PSA_ERROR_INVALID_ARGUMENT
+
+PSA export out of range key slot - upper bound
+export_invalid_slot:(psa_key_slot_t)(-1):PSA_ERROR_INVALID_ARGUMENT
+
PSA import AES: bad key size
depends_on:MBEDTLS_AES_C
import:"0123456789abcdef":PSA_KEY_TYPE_AES:PSA_ERROR_INVALID_ARGUMENT
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index c46da96..001869e 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -1004,6 +1004,50 @@
/* END_CASE */
/* BEGIN_CASE */
+void import_key_nonempty_slot( )
+{
+ int slot = 1;
+ psa_key_type_t type = PSA_KEY_TYPE_RAW_DATA;
+ psa_status_t status;
+ const uint8_t data[] = { 0x1, 0x2, 0x3, 0x4, 0x5 };
+ TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
+
+ /* Import the key */
+ TEST_ASSERT( psa_import_key( slot, type,
+ data, sizeof( data ) ) == PSA_SUCCESS );
+
+ /* Import the key again */
+ status = psa_import_key( slot, type, data, sizeof( data ) );
+ TEST_ASSERT( status == PSA_ERROR_OCCUPIED_SLOT );
+
+exit:
+ mbedtls_psa_crypto_free( );
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void export_invalid_slot( int slot, int expected_export_status_arg )
+{
+ psa_status_t status;
+ unsigned char *exported = NULL;
+ size_t export_size = 0;
+ size_t exported_length = INVALID_EXPORT_LENGTH;
+ psa_status_t expected_export_status = expected_export_status_arg;
+
+ TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
+
+ /* Export the key */
+ status = psa_export_key( slot,
+ exported, export_size,
+ &exported_length );
+ TEST_ASSERT( status == expected_export_status );
+
+exit:
+ mbedtls_psa_crypto_free( );
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
void import_export_public_key( data_t *data,
int type_arg,
int alg_arg,