Skip to content

Commit 5a7ed31

Browse files
author
itayzafrir
committed
Add acl test - use other partitions' key - asymmetric sign verify
1 parent db90606 commit 5a7ed31

File tree

1 file changed

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

1 file changed

+35
-0
lines changed

TESTS/psa/crypto_access_control/COMPONENT_NSPE/main.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,39 @@ void test_use_other_partition_key_aead(void)
337337
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(key_handle));
338338
}
339339

340+
void test_use_other_partition_key_asymmetric_sign_verify(void)
341+
{
342+
static const psa_key_id_t key_id = 999;
343+
static const psa_key_type_t key_type = PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP256R1);
344+
static const psa_algorithm_t key_alg = PSA_ALG_ECDSA(PSA_ALG_SHA_256);
345+
static const psa_key_usage_t key_usage = PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY;
346+
static const size_t key_bits = 256;
347+
static const unsigned char input[] = "hello world!";
348+
unsigned char signature[PSA_ECDSA_SIGNATURE_SIZE(key_bits)] = { 0 };
349+
psa_key_handle_t key_handle = 0;
350+
size_t len;
351+
352+
/* via test partition - create a key, set key policy, generate key material and close */
353+
TEST_ASSERT_EQUAL(PSA_SUCCESS, create_and_generate_key_via_test_partition(key_id, key_type, key_alg, key_usage,
354+
key_bits, &key_handle, 1));
355+
356+
/* via test partition - reopen the key created by the test partition */
357+
key_handle = 0;
358+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle));
359+
TEST_ASSERT_NOT_EQUAL(0, key_handle);
360+
361+
/* try to asymmetric sign using the key that was created by the test partition */
362+
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_asymmetric_sign(key_handle, key_alg, input, sizeof(input),
363+
signature, sizeof(signature), &len));
364+
365+
/* try to asymmetric verify using the key that was created by the test partition */
366+
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_asymmetric_verify(key_handle, key_alg, input, sizeof(input),
367+
signature, len));
368+
369+
/* via test partition - close the key created by the test partition */
370+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(key_handle));
371+
}
372+
340373
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
341374
{
342375
psa_status_t status = mbed_psa_reboot_and_request_new_security_state(PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
@@ -382,6 +415,8 @@ Case cases[] = {
382415
case_setup_handler, test_use_other_partition_key_cipher, case_teardown_handler),
383416
Case("use other partitions' key - aead",
384417
case_setup_handler, test_use_other_partition_key_aead, case_teardown_handler),
418+
Case("use other partitions' key - asymmetric sign verify",
419+
case_setup_handler, test_use_other_partition_key_asymmetric_sign_verify, case_teardown_handler),
385420
};
386421

387422
Specification specification(test_setup, cases);

0 commit comments

Comments
 (0)