Skip to content

Commit b8079c3

Browse files
author
itayzafrir
committed
Add acl test - use other partitions' key - cipher
1 parent d1e61a0 commit b8079c3

File tree

1 file changed

+33
-0
lines changed
  • TESTS/psa/crypto_access_control/COMPONENT_NSPE

1 file changed

+33
-0
lines changed

TESTS/psa/crypto_access_control/COMPONENT_NSPE/main.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,37 @@ void test_use_other_partition_key_mac(void)
270270
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(key_handle));
271271
}
272272

273+
void test_use_other_partition_key_cipher(void)
274+
{
275+
static const psa_key_id_t key_id = 999;
276+
static const psa_key_type_t key_type = PSA_KEY_TYPE_AES;
277+
static const psa_algorithm_t key_alg = PSA_ALG_CBC_NO_PADDING;
278+
static const psa_key_usage_t key_usage = PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY;
279+
static const size_t key_bits = 128;
280+
psa_key_handle_t key_handle = 0;
281+
psa_cipher_operation_t operation;
282+
283+
/* via test partition - create a key, set key policy, generate key material and close */
284+
TEST_ASSERT_EQUAL(PSA_SUCCESS, create_and_generate_key_via_test_partition(key_id, key_type, key_alg, key_usage,
285+
key_bits, &key_handle, 1));
286+
287+
/* via test partition - reopen the key created by the test partition */
288+
key_handle = 0;
289+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle));
290+
TEST_ASSERT_NOT_EQUAL(0, key_handle);
291+
292+
/* try to setup cipher encrypt sign operation using the key that was created by the test partition */
293+
operation = psa_cipher_operation_init();
294+
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_cipher_encrypt_setup(&operation, key_handle, key_alg));
295+
296+
/* try to setup cipher decrypt operation using the key that was created by the test partition */
297+
operation = psa_cipher_operation_init();
298+
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_cipher_decrypt_setup(&operation, key_handle, key_alg));
299+
300+
/* via test partition - close the key created by the test partition */
301+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(key_handle));
302+
}
303+
273304
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
274305
{
275306
psa_status_t status = mbed_psa_reboot_and_request_new_security_state(PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
@@ -311,6 +342,8 @@ Case cases[] = {
311342
case_setup_handler, test_use_other_partition_key_manage_key, case_teardown_handler),
312343
Case("use other partitions' key - mac",
313344
case_setup_handler, test_use_other_partition_key_mac, case_teardown_handler),
345+
Case("use other partitions' key - cipher",
346+
case_setup_handler, test_use_other_partition_key_cipher, case_teardown_handler),
314347
};
315348

316349
Specification specification(test_setup, cases);

0 commit comments

Comments
 (0)