mirror of https://github.com/ARMmbed/mbed-os.git
commit
dcba5ffa3c
|
@ -85,7 +85,7 @@ void test_crypto_random(void)
|
||||||
void test_crypto_asymmetric_encrypt_decrypt(void)
|
void test_crypto_asymmetric_encrypt_decrypt(void)
|
||||||
{
|
{
|
||||||
psa_status_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
psa_key_slot_t slot = 1;
|
psa_key_handle_t key_handle = 0;
|
||||||
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEYPAIR;
|
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEYPAIR;
|
||||||
psa_algorithm_t alg = PSA_ALG_RSA_PKCS1V15_CRYPT;
|
psa_algorithm_t alg = PSA_ALG_RSA_PKCS1V15_CRYPT;
|
||||||
size_t key_bits = 512, got_bits = 0, output_length;
|
size_t key_bits = 512, got_bits = 0, output_length;
|
||||||
|
@ -94,21 +94,23 @@ void test_crypto_asymmetric_encrypt_decrypt(void)
|
||||||
unsigned char encrypted[64];
|
unsigned char encrypted[64];
|
||||||
unsigned char decrypted[sizeof(input)];
|
unsigned char decrypted[sizeof(input)];
|
||||||
|
|
||||||
psa_key_policy_init(&policy);
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
|
||||||
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg);
|
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(slot, &policy));
|
|
||||||
|
|
||||||
status = psa_generate_key(slot, key_type, key_bits, NULL, 0);
|
policy = psa_key_policy_init();
|
||||||
|
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg);
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
|
||||||
|
|
||||||
|
status = psa_generate_key(key_handle, key_type, key_bits, NULL, 0);
|
||||||
TEST_SKIP_UNLESS_MESSAGE(status != PSA_ERROR_NOT_SUPPORTED, "RSA key generation is not supported");
|
TEST_SKIP_UNLESS_MESSAGE(status != PSA_ERROR_NOT_SUPPORTED, "RSA key generation is not supported");
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_information(slot, NULL, &got_bits));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_information(key_handle, NULL, &got_bits));
|
||||||
TEST_ASSERT_EQUAL(key_bits, got_bits);
|
TEST_ASSERT_EQUAL(key_bits, got_bits);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_encrypt(slot, alg, input, sizeof(input), NULL, 0,
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_encrypt(key_handle, alg, input, sizeof(input), NULL, 0,
|
||||||
encrypted, sizeof(encrypted), &output_length));
|
encrypted, sizeof(encrypted), &output_length));
|
||||||
TEST_ASSERT_EQUAL(sizeof(encrypted), output_length);
|
TEST_ASSERT_EQUAL(sizeof(encrypted), output_length);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_decrypt(slot, alg, encrypted, sizeof(encrypted), NULL, 0,
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_decrypt(key_handle, alg, encrypted, sizeof(encrypted), NULL, 0,
|
||||||
decrypted, sizeof(decrypted), &output_length));
|
decrypted, sizeof(decrypted), &output_length));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(slot));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
|
||||||
TEST_ASSERT_EQUAL(sizeof(input), output_length);
|
TEST_ASSERT_EQUAL(sizeof(input), output_length);
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(input, decrypted, output_length);
|
TEST_ASSERT_EQUAL_UINT8_ARRAY(input, decrypted, output_length);
|
||||||
}
|
}
|
||||||
|
@ -124,6 +126,7 @@ void test_crypto_hash_verify(void)
|
||||||
0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
|
0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
|
||||||
};
|
};
|
||||||
|
|
||||||
|
operation = psa_hash_operation_init();
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_setup(&operation, alg));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_setup(&operation, alg));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_verify(&operation, hash, sizeof(hash)));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_verify(&operation, hash, sizeof(hash)));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&operation));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&operation));
|
||||||
|
@ -131,7 +134,7 @@ void test_crypto_hash_verify(void)
|
||||||
|
|
||||||
void test_crypto_symmetric_cipher_encrypt_decrypt(void)
|
void test_crypto_symmetric_cipher_encrypt_decrypt(void)
|
||||||
{
|
{
|
||||||
psa_key_slot_t slot = 1;
|
psa_key_handle_t key_handle = 0;
|
||||||
psa_key_type_t key_type = PSA_KEY_TYPE_AES;
|
psa_key_type_t key_type = PSA_KEY_TYPE_AES;
|
||||||
psa_algorithm_t alg = PSA_ALG_CBC_NO_PADDING;
|
psa_algorithm_t alg = PSA_ALG_CBC_NO_PADDING;
|
||||||
psa_cipher_operation_t operation;
|
psa_cipher_operation_t operation;
|
||||||
|
@ -151,12 +154,16 @@ void test_crypto_symmetric_cipher_encrypt_decrypt(void)
|
||||||
};
|
};
|
||||||
unsigned char encrypted[sizeof(input)], decrypted[sizeof(input)], iv[16];
|
unsigned char encrypted[sizeof(input)], decrypted[sizeof(input)], iv[16];
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
|
||||||
|
|
||||||
memset(iv, 0x2a, sizeof(iv));
|
memset(iv, 0x2a, sizeof(iv));
|
||||||
psa_key_policy_init(&policy);
|
policy = psa_key_policy_init();
|
||||||
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg);
|
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(slot, &policy));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_import_key(slot, key_type, key, sizeof(key)));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_import_key(key_handle, key_type, key, sizeof(key)));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_encrypt_setup(&operation, slot, alg));
|
|
||||||
|
operation = psa_cipher_operation_init();
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_encrypt_setup(&operation, key_handle, alg));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_set_iv(&operation, iv, sizeof(iv)));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_set_iv(&operation, iv, sizeof(iv)));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_update(&operation, input, sizeof(input),
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_update(&operation, input, sizeof(input),
|
||||||
encrypted, sizeof(encrypted), &output_len));
|
encrypted, sizeof(encrypted), &output_len));
|
||||||
|
@ -165,20 +172,21 @@ void test_crypto_symmetric_cipher_encrypt_decrypt(void)
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_abort(&operation));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_abort(&operation));
|
||||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_encryption, encrypted, sizeof(expected_encryption));
|
TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_encryption, encrypted, sizeof(expected_encryption));
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_decrypt_setup(&operation, slot, alg));
|
operation = psa_cipher_operation_init();
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_decrypt_setup(&operation, key_handle, alg));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_set_iv(&operation, iv, sizeof(iv)));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_set_iv(&operation, iv, sizeof(iv)));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_update(&operation, encrypted, sizeof(encrypted),
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_update(&operation, encrypted, sizeof(encrypted),
|
||||||
decrypted, sizeof(decrypted), &output_len));
|
decrypted, sizeof(decrypted), &output_len));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_finish(&operation, decrypted + output_len,
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_finish(&operation, decrypted + output_len,
|
||||||
sizeof(decrypted) - output_len, &output_len));
|
sizeof(decrypted) - output_len, &output_len));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_abort(&operation));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_abort(&operation));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(slot));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
|
||||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(input, decrypted, sizeof(input));
|
TEST_ASSERT_EQUAL_HEX8_ARRAY(input, decrypted, sizeof(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_crypto_asymmetric_sign_verify(void)
|
void test_crypto_asymmetric_sign_verify(void)
|
||||||
{
|
{
|
||||||
psa_key_slot_t slot = 1;
|
psa_key_handle_t key_handle = 0;
|
||||||
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEYPAIR;
|
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEYPAIR;
|
||||||
psa_algorithm_t alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW;
|
psa_algorithm_t alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW;
|
||||||
psa_key_policy_t policy;
|
psa_key_policy_t policy;
|
||||||
|
@ -252,47 +260,162 @@ void test_crypto_asymmetric_sign_verify(void)
|
||||||
unsigned char signature[sizeof(expected_signature)];
|
unsigned char signature[sizeof(expected_signature)];
|
||||||
size_t signature_len;
|
size_t signature_len;
|
||||||
|
|
||||||
psa_key_policy_init(&policy);
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
|
||||||
|
|
||||||
|
policy = psa_key_policy_init();
|
||||||
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, alg);
|
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, alg);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(slot, &policy));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_import_key(slot, key_type, key, sizeof(key)));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_import_key(key_handle, key_type, key, sizeof(key)));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_sign(slot, alg, input, sizeof(input),
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_sign(key_handle, alg, input, sizeof(input),
|
||||||
signature, sizeof(signature), &signature_len));
|
signature, sizeof(signature), &signature_len));
|
||||||
TEST_ASSERT_EQUAL(sizeof(signature), signature_len);
|
TEST_ASSERT_EQUAL(sizeof(signature), signature_len);
|
||||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_signature, signature, signature_len);
|
TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_signature, signature, signature_len);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_verify(slot, alg, input, sizeof(input),
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_verify(key_handle, alg, input, sizeof(input),
|
||||||
signature, signature_len));
|
signature, signature_len));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(slot));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_crypto_key_derivation(void)
|
void test_crypto_key_derivation(void)
|
||||||
{
|
{
|
||||||
psa_key_slot_t slot = 1, derived_slot = 2;
|
psa_key_handle_t key_handle = 0, derived_key_handle = 0;
|
||||||
psa_algorithm_t alg = PSA_ALG_HKDF(PSA_ALG_SHA_256), derived_alg = PSA_ALG_CTR;
|
psa_algorithm_t alg = PSA_ALG_HKDF(PSA_ALG_SHA_256), derived_alg = PSA_ALG_CTR;
|
||||||
psa_key_type_t derived_key_type = PSA_KEY_TYPE_AES, got_type;
|
psa_key_type_t key_type = PSA_KEY_TYPE_DERIVE, derived_key_type = PSA_KEY_TYPE_AES, got_type;
|
||||||
psa_key_policy_t policy;
|
psa_key_policy_t policy;
|
||||||
psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT;
|
psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT;
|
||||||
size_t key_bits = 512, derived_key_bits = 256, got_bits;
|
size_t key_bits = 512, derived_key_bits = 256, got_bits;
|
||||||
|
|
||||||
psa_key_policy_init(&policy);
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
|
||||||
|
|
||||||
|
policy = psa_key_policy_init();
|
||||||
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_DERIVE, alg);
|
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_DERIVE, alg);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(slot, &policy));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(slot, PSA_KEY_TYPE_DERIVE, key_bits, NULL, 0));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(key_handle, key_type, key_bits, NULL, 0));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_key_derivation(&generator, slot, alg, NULL, 0, NULL, 0,
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_key_derivation(&generator, key_handle, alg, NULL, 0, NULL, 0,
|
||||||
PSA_BITS_TO_BYTES(derived_key_bits)));
|
PSA_BITS_TO_BYTES(derived_key_bits)));
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&derived_key_handle));
|
||||||
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_ENCRYPT, derived_alg);
|
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_ENCRYPT, derived_alg);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(derived_slot, &policy));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(derived_key_handle, &policy));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generator_import_key(derived_slot, derived_key_type,
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generator_import_key(derived_key_handle, derived_key_type,
|
||||||
derived_key_bits, &generator));
|
derived_key_bits, &generator));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_information(derived_slot, &got_type, &got_bits));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_information(derived_key_handle, &got_type, &got_bits));
|
||||||
TEST_ASSERT_EQUAL(derived_key_type, got_type);
|
TEST_ASSERT_EQUAL(derived_key_type, got_type);
|
||||||
TEST_ASSERT_EQUAL(derived_key_bits, got_bits);
|
TEST_ASSERT_EQUAL(derived_key_bits, got_bits);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generator_abort(&generator));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generator_abort(&generator));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(slot));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(derived_slot));
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(derived_key_handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_crypto_key_handles(void)
|
||||||
|
{
|
||||||
|
psa_key_id_t id = 999;
|
||||||
|
psa_key_type_t type = PSA_KEY_TYPE_AES;
|
||||||
|
size_t bits = 256;
|
||||||
|
psa_key_usage_t usage = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT;
|
||||||
|
psa_algorithm_t alg = PSA_ALG_CBC_NO_PADDING;
|
||||||
|
psa_key_handle_t key_handle;
|
||||||
|
psa_key_policy_t policy;
|
||||||
|
|
||||||
|
key_handle = 0;
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
|
||||||
|
TEST_ASSERT_NOT_EQUAL(0, key_handle);
|
||||||
|
policy = psa_key_policy_init();
|
||||||
|
psa_key_policy_set_usage(&policy, usage, alg);
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(key_handle, type, bits, NULL, 0));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_close_key(key_handle));
|
||||||
|
|
||||||
|
key_handle = 0;
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
|
||||||
|
TEST_ASSERT_NOT_EQUAL(0, key_handle);
|
||||||
|
policy = psa_key_policy_init();
|
||||||
|
psa_key_policy_set_usage(&policy, usage, alg);
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(key_handle, type, bits, NULL, 0));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
|
||||||
|
|
||||||
|
key_handle = 0;
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_create_key(PSA_KEY_LIFETIME_PERSISTENT, id, &key_handle));
|
||||||
|
TEST_ASSERT_NOT_EQUAL(0, key_handle);
|
||||||
|
policy = psa_key_policy_init();
|
||||||
|
psa_key_policy_set_usage(&policy, usage, alg);
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(key_handle, type, bits, NULL, 0));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_close_key(key_handle));
|
||||||
|
|
||||||
|
key_handle = 0;
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_open_key(PSA_KEY_LIFETIME_PERSISTENT, id, &key_handle));
|
||||||
|
TEST_ASSERT_NOT_EQUAL(0, key_handle);
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
|
||||||
|
|
||||||
|
key_handle = 0;
|
||||||
|
TEST_ASSERT_EQUAL(PSA_ERROR_EMPTY_SLOT, psa_open_key(PSA_KEY_LIFETIME_PERSISTENT, id, &key_handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_crypto_hash_clone(void)
|
||||||
|
{
|
||||||
|
psa_algorithm_t alg = PSA_ALG_SHA_256;
|
||||||
|
unsigned char hash[PSA_HASH_MAX_SIZE];
|
||||||
|
size_t hash_len;
|
||||||
|
psa_hash_operation_t source;
|
||||||
|
psa_hash_operation_t target;
|
||||||
|
/* SHA-256 hash of an empty string */
|
||||||
|
static const unsigned char expected_hash[] = {
|
||||||
|
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8,
|
||||||
|
0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
|
||||||
|
0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
|
||||||
|
};
|
||||||
|
|
||||||
|
source = psa_hash_operation_init();
|
||||||
|
target = psa_hash_operation_init();
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_setup(&source, alg));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_finish(&source, hash, sizeof(hash), &hash_len));
|
||||||
|
/* should fail because psa_hash_finish has been called on source */
|
||||||
|
TEST_ASSERT_EQUAL(PSA_ERROR_BAD_STATE, psa_hash_clone(&source, &target));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&source));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&target));
|
||||||
|
|
||||||
|
source = psa_hash_operation_init();
|
||||||
|
target = psa_hash_operation_init();
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_setup(&source, alg));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_verify(&source, expected_hash, sizeof(expected_hash)));
|
||||||
|
/* should fail because psa_hash_verify has been called on source */
|
||||||
|
TEST_ASSERT_EQUAL(PSA_ERROR_BAD_STATE, psa_hash_clone(&source, &target));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&source));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&target));
|
||||||
|
|
||||||
|
source = psa_hash_operation_init();
|
||||||
|
target = psa_hash_operation_init();
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_setup(&source, alg));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&source));
|
||||||
|
/* should fail because psa_hash_abort has been called on source */
|
||||||
|
TEST_ASSERT_EQUAL(PSA_ERROR_BAD_STATE, psa_hash_clone(&source, &target));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&target));
|
||||||
|
|
||||||
|
source = psa_hash_operation_init();
|
||||||
|
target = psa_hash_operation_init();
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_setup(&source, alg));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_setup(&target, alg));
|
||||||
|
/* should fail because psa_hash_setup has been called on target */
|
||||||
|
TEST_ASSERT_EQUAL(PSA_ERROR_BAD_STATE, psa_hash_clone(&source, &target));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&source));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&target));
|
||||||
|
|
||||||
|
source = psa_hash_operation_init();
|
||||||
|
target = psa_hash_operation_init();
|
||||||
|
/* should fail because psa_hash_setup has not been called on source */
|
||||||
|
TEST_ASSERT_EQUAL(PSA_ERROR_BAD_STATE, psa_hash_clone(&source, &target));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&source));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&target));
|
||||||
|
|
||||||
|
source = psa_hash_operation_init();
|
||||||
|
target = psa_hash_operation_init();
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_setup(&source, alg));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_clone(&source, &target));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&source));
|
||||||
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&target));
|
||||||
|
}
|
||||||
|
|
||||||
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
|
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
|
||||||
{
|
{
|
||||||
|
@ -326,6 +449,8 @@ Case cases[] = {
|
||||||
Case("mbed-crypto symmetric cipher encrypt/decrypt", case_setup_handler, test_crypto_symmetric_cipher_encrypt_decrypt, case_teardown_handler),
|
Case("mbed-crypto symmetric cipher encrypt/decrypt", case_setup_handler, test_crypto_symmetric_cipher_encrypt_decrypt, case_teardown_handler),
|
||||||
Case("mbed-crypto asymmetric sign/verify", case_setup_handler, test_crypto_asymmetric_sign_verify, case_teardown_handler),
|
Case("mbed-crypto asymmetric sign/verify", case_setup_handler, test_crypto_asymmetric_sign_verify, case_teardown_handler),
|
||||||
Case("mbed-crypto key derivation", case_setup_handler, test_crypto_key_derivation, case_teardown_handler),
|
Case("mbed-crypto key derivation", case_setup_handler, test_crypto_key_derivation, case_teardown_handler),
|
||||||
|
Case("mbed-crypto key handles", case_setup_handler, test_crypto_key_handles, case_teardown_handler),
|
||||||
|
Case("mbed-crypto hash clone", case_setup_handler, test_crypto_hash_clone, case_teardown_handler),
|
||||||
};
|
};
|
||||||
|
|
||||||
Specification specification(test_setup, cases);
|
Specification specification(test_setup, cases);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,59 +0,0 @@
|
||||||
/* Copyright (c) 2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "psa_prot_internal_storage.h"
|
|
||||||
#include "test_pits_impl.h"
|
|
||||||
#include "kv_config.h"
|
|
||||||
#include "KVMap.h"
|
|
||||||
#include "KVStore.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace mbed;
|
|
||||||
|
|
||||||
#define STR_EXPAND(tok) #tok
|
|
||||||
|
|
||||||
psa_its_status_t test_psa_its_reset_impl(void)
|
|
||||||
{
|
|
||||||
psa_its_status_t status = PSA_ITS_SUCCESS;
|
|
||||||
|
|
||||||
int kv_status = kv_init_storage_config();
|
|
||||||
if (kv_status != MBED_SUCCESS) {
|
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
KVMap &kv_map = KVMap::get_instance();
|
|
||||||
KVStore *kvstore = kv_map.get_internal_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
|
|
||||||
if (!kvstore) {
|
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kvstore->reset() != MBED_SUCCESS) {
|
|
||||||
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,50 +0,0 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/***********************************************************************************************************************
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* Template Version 1.0
|
|
||||||
* Generated by tools/spm/generate_partition_code.py Version 1.0
|
|
||||||
**********************************************************************************************************************/
|
|
||||||
|
|
||||||
#ifndef PSA_TEST_ITS_RESET_PARTITION_H
|
|
||||||
#define PSA_TEST_ITS_RESET_PARTITION_H
|
|
||||||
|
|
||||||
#define TEST_ITS_RESET_ID 11
|
|
||||||
|
|
||||||
#define TEST_ITS_RESET_ROT_SRV_COUNT (1UL)
|
|
||||||
#define TEST_ITS_RESET_EXT_ROT_SRV_COUNT (0UL)
|
|
||||||
|
|
||||||
/* TEST_ITS_RESET event flags */
|
|
||||||
#define TEST_ITS_RESET_RESERVED1_POS (1UL)
|
|
||||||
#define TEST_ITS_RESET_RESERVED1_MSK (1UL << TEST_ITS_RESET_RESERVED1_POS)
|
|
||||||
|
|
||||||
#define TEST_ITS_RESET_RESERVED2_POS (2UL)
|
|
||||||
#define TEST_ITS_RESET_RESERVED2_MSK (1UL << TEST_ITS_RESET_RESERVED2_POS)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define TEST_PSA_ITS_RESET_MSK_POS (4UL)
|
|
||||||
#define TEST_PSA_ITS_RESET_MSK (1UL << TEST_PSA_ITS_RESET_MSK_POS)
|
|
||||||
|
|
||||||
#define TEST_ITS_RESET_WAIT_ANY_SID_MSK (\
|
|
||||||
TEST_PSA_ITS_RESET_MSK)
|
|
||||||
|
|
||||||
|
|
||||||
#endif // PSA_TEST_ITS_RESET_PARTITION_H
|
|
|
@ -1,59 +0,0 @@
|
||||||
/* Copyright (c) 2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "psa_prot_internal_storage.h"
|
|
||||||
#include "test_pits_impl.h"
|
|
||||||
#include "kv_config.h"
|
|
||||||
#include "KVMap.h"
|
|
||||||
#include "KVStore.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace mbed;
|
|
||||||
|
|
||||||
#define STR_EXPAND(tok) #tok
|
|
||||||
|
|
||||||
psa_its_status_t test_psa_its_reset_impl(void)
|
|
||||||
{
|
|
||||||
psa_its_status_t status = PSA_ITS_SUCCESS;
|
|
||||||
|
|
||||||
int kv_status = kv_init_storage_config();
|
|
||||||
if (kv_status != MBED_SUCCESS) {
|
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
KVMap &kv_map = KVMap::get_instance();
|
|
||||||
KVStore *kvstore = kv_map.get_internal_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
|
|
||||||
if (!kvstore) {
|
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kvstore->reset() != MBED_SUCCESS) {
|
|
||||||
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,65 +0,0 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// -------------------------------------- Includes -----------------------------------
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "cmsis_os2.h"
|
|
||||||
#include "spm_server.h"
|
|
||||||
#include "spm_panic.h"
|
|
||||||
#include "psa_test_its_reset_partition.h"
|
|
||||||
#include "psa_prot_internal_storage.h"
|
|
||||||
#include "test_pits_impl.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void test_pits_entry(void *ptr)
|
|
||||||
{
|
|
||||||
uint32_t signals = 0;
|
|
||||||
psa_msg_t msg = {0};
|
|
||||||
psa_error_t status = PSA_SUCCESS;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
signals = psa_wait_any(PSA_BLOCK);
|
|
||||||
if ((signals & TEST_PSA_ITS_RESET_MSK) != 0) {
|
|
||||||
psa_get(TEST_PSA_ITS_RESET_MSK, &msg);
|
|
||||||
switch (msg.type) {
|
|
||||||
case PSA_IPC_CONNECT: //fallthrough
|
|
||||||
case PSA_IPC_DISCONNECT: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PSA_IPC_CALL: {
|
|
||||||
status = test_psa_its_reset_impl();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
SPM_PANIC("Unexpected message type %d!", (int)(msg.type));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_reply(msg.handle, status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,31 +0,0 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/***********************************************************************************************************************
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* Template Version 1.0
|
|
||||||
* Generated by tools/spm/generate_partition_code.py Version 1.0
|
|
||||||
**********************************************************************************************************************/
|
|
||||||
|
|
||||||
#ifndef PSA_TEST_ITS_RESET_PARTITION_ROT_SERVICES_H
|
|
||||||
#define PSA_TEST_ITS_RESET_PARTITION_ROT_SERVICES_H
|
|
||||||
|
|
||||||
#define TEST_PSA_ITS_RESET 0x00011A04
|
|
||||||
|
|
||||||
#endif // PSA_TEST_ITS_RESET_PARTITION_ROT_SERVICES_H
|
|
|
@ -1,50 +0,0 @@
|
||||||
/* Copyright (c) 2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __TEST_INTERNAL_TRUSTED_STORAGE_H__
|
|
||||||
#define __TEST_INTERNAL_TRUSTED_STORAGE_H__
|
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief This file describes the PSA Internal Trusted Storage API
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "psa_prot_internal_storage.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Remove the provided key and its associated data from the storage
|
|
||||||
*
|
|
||||||
* \param[in] uid The uid value
|
|
||||||
*
|
|
||||||
* \return A status indicating the success/failure of the operation
|
|
||||||
*
|
|
||||||
* \retval PSA_ITS_SUCCESS The operation completed successfully
|
|
||||||
* \retval PSA_ITS_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
|
|
||||||
*/
|
|
||||||
psa_its_status_t test_psa_its_reset(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __TEST_INTERNAL_TRUSTED_STORAGE_H__
|
|
|
@ -1,21 +0,0 @@
|
||||||
{
|
|
||||||
"name": "TEST_ITS_RESET",
|
|
||||||
"type": "APPLICATION-ROT",
|
|
||||||
"priority": "NORMAL",
|
|
||||||
"id": "0x0000000B",
|
|
||||||
"entry_point": "test_pits_entry",
|
|
||||||
"stack_size": "0x400",
|
|
||||||
"heap_size": "0x400",
|
|
||||||
"services": [{
|
|
||||||
"name": "TEST_PSA_ITS_RESET",
|
|
||||||
"identifier": "0x00011A04",
|
|
||||||
"signal": "TEST_PSA_ITS_RESET_MSK",
|
|
||||||
"non_secure_clients": true,
|
|
||||||
"minor_version": 1,
|
|
||||||
"minor_policy": "RELAXED"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source_files": [
|
|
||||||
"COMPONENT_SPE/test_pits_reset_partition.c"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -23,8 +23,8 @@
|
||||||
#include "greentea-client/test_env.h"
|
#include "greentea-client/test_env.h"
|
||||||
#include "unity/unity.h"
|
#include "unity/unity.h"
|
||||||
#include "utest/utest.h"
|
#include "utest/utest.h"
|
||||||
#include "psa_prot_internal_storage.h"
|
#include "psa/internal_trusted_storage.h"
|
||||||
#include "test_pits.h"
|
#include "psa/lifecycle.h"
|
||||||
#include "entropy.h"
|
#include "entropy.h"
|
||||||
#include "entropy_poll.h"
|
#include "entropy_poll.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
@ -134,7 +134,7 @@ static void injection_and_init_deinit()
|
||||||
utest::v1::status_t case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
|
utest::v1::status_t case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
|
||||||
{
|
{
|
||||||
psa_status_t status;
|
psa_status_t status;
|
||||||
status = test_psa_its_reset();
|
status = mbed_psa_reboot_and_request_new_security_state(PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
||||||
mbedtls_psa_crypto_free();
|
mbedtls_psa_crypto_free();
|
||||||
return greentea_case_teardown_handler(source, passed, failed, reason);
|
return greentea_case_teardown_handler(source, passed, failed, reason);
|
||||||
|
@ -143,7 +143,7 @@ utest::v1::status_t case_teardown_handler(const Case *const source, const size_t
|
||||||
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
|
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
|
||||||
{
|
{
|
||||||
psa_status_t status;
|
psa_status_t status;
|
||||||
status = test_psa_its_reset();
|
status = mbed_psa_reboot_and_request_new_security_state(PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
||||||
return greentea_case_setup_handler(source, index_of_case);
|
return greentea_case_setup_handler(source, index_of_case);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
#include "greentea-client/test_env.h"
|
#include "greentea-client/test_env.h"
|
||||||
#include "unity/unity.h"
|
#include "unity/unity.h"
|
||||||
#include "utest/utest.h"
|
#include "utest/utest.h"
|
||||||
#include "psa_prot_internal_storage.h"
|
#include "psa/internal_trusted_storage.h"
|
||||||
#include "test_pits.h"
|
#include "psa/lifecycle.h"
|
||||||
|
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
|
||||||
|
@ -35,14 +35,11 @@ static void pits_test()
|
||||||
psa_its_status_t status = PSA_ITS_SUCCESS;
|
psa_its_status_t status = PSA_ITS_SUCCESS;
|
||||||
uint8_t write_buff[TEST_BUFF_SIZE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
|
uint8_t write_buff[TEST_BUFF_SIZE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
|
||||||
uint8_t read_buff[TEST_BUFF_SIZE] = {0};
|
uint8_t read_buff[TEST_BUFF_SIZE] = {0};
|
||||||
struct psa_its_info_t info = {0, PSA_ITS_WRITE_ONCE_FLAG};
|
struct psa_its_info_t info = {0, PSA_ITS_FLAG_WRITE_ONCE};
|
||||||
memset(read_buff, 0, TEST_BUFF_SIZE);
|
memset(read_buff, 0, TEST_BUFF_SIZE);
|
||||||
|
|
||||||
status = test_psa_its_reset();
|
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
|
||||||
|
|
||||||
status = psa_its_get_info(5, &info);
|
status = psa_its_get_info(5, &info);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_ERROR_KEY_NOT_FOUND, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_ERROR_UID_NOT_FOUND, status);
|
||||||
|
|
||||||
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, 0);
|
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, 0);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
||||||
|
@ -68,7 +65,7 @@ static void pits_test()
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
||||||
|
|
||||||
status = psa_its_get_info(5, &info);
|
status = psa_its_get_info(5, &info);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_ERROR_KEY_NOT_FOUND, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_ERROR_UID_NOT_FOUND, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pits_write_once_test()
|
static void pits_write_once_test()
|
||||||
|
@ -78,27 +75,24 @@ static void pits_write_once_test()
|
||||||
uint8_t read_buff[TEST_BUFF_SIZE] = {0};
|
uint8_t read_buff[TEST_BUFF_SIZE] = {0};
|
||||||
struct psa_its_info_t info = {0, 0};
|
struct psa_its_info_t info = {0, 0};
|
||||||
|
|
||||||
status = test_psa_its_reset();
|
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
|
||||||
|
|
||||||
status = psa_its_get_info(5, &info);
|
status = psa_its_get_info(5, &info);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_ERROR_KEY_NOT_FOUND, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_ERROR_UID_NOT_FOUND, status);
|
||||||
|
|
||||||
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, PSA_ITS_WRITE_ONCE_FLAG);
|
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, PSA_ITS_FLAG_WRITE_ONCE);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
||||||
|
|
||||||
info.size = 0;
|
info.size = 0;
|
||||||
info.flags = 0;
|
info.flags = PSA_ITS_FLAG_NONE;
|
||||||
status = psa_its_get_info(5, &info);
|
status = psa_its_get_info(5, &info);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
||||||
TEST_ASSERT_EQUAL(TEST_BUFF_SIZE, info.size);
|
TEST_ASSERT_EQUAL(TEST_BUFF_SIZE, info.size);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_WRITE_ONCE_FLAG, info.flags);
|
TEST_ASSERT_EQUAL(PSA_ITS_FLAG_WRITE_ONCE, info.flags);
|
||||||
|
|
||||||
status = psa_its_get(5, 0, TEST_BUFF_SIZE, read_buff);
|
status = psa_its_get(5, 0, TEST_BUFF_SIZE, read_buff);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
||||||
TEST_ASSERT_EQUAL_MEMORY(write_buff, read_buff, TEST_BUFF_SIZE);
|
TEST_ASSERT_EQUAL_MEMORY(write_buff, read_buff, TEST_BUFF_SIZE);
|
||||||
|
|
||||||
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, PSA_ITS_WRITE_ONCE_FLAG);
|
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, PSA_ITS_FLAG_WRITE_ONCE);
|
||||||
TEST_ASSERT_NOT_EQUAL(PSA_ITS_SUCCESS, status);
|
TEST_ASSERT_NOT_EQUAL(PSA_ITS_SUCCESS, status);
|
||||||
|
|
||||||
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, 0);
|
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, 0);
|
||||||
|
@ -108,19 +102,32 @@ static void pits_write_once_test()
|
||||||
TEST_ASSERT_NOT_EQUAL(PSA_ITS_SUCCESS, status);
|
TEST_ASSERT_NOT_EQUAL(PSA_ITS_SUCCESS, status);
|
||||||
|
|
||||||
info.size = 0;
|
info.size = 0;
|
||||||
info.flags = 0;
|
info.flags = PSA_ITS_FLAG_NONE;
|
||||||
status = psa_its_get_info(5, &info);
|
status = psa_its_get_info(5, &info);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
||||||
TEST_ASSERT_EQUAL(TEST_BUFF_SIZE, info.size);
|
TEST_ASSERT_EQUAL(TEST_BUFF_SIZE, info.size);
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_WRITE_ONCE_FLAG, info.flags);
|
TEST_ASSERT_EQUAL(PSA_ITS_FLAG_WRITE_ONCE, info.flags);
|
||||||
|
}
|
||||||
|
|
||||||
status = test_psa_its_reset();
|
utest::v1::status_t case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
|
||||||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
|
{
|
||||||
|
psa_status_t status;
|
||||||
|
status = mbed_psa_reboot_and_request_new_security_state(PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
|
||||||
|
TEST_ASSERT_EQUAL(PSA_LIFECYCLE_SUCCESS, status);
|
||||||
|
return greentea_case_teardown_handler(source, passed, failed, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
|
||||||
|
{
|
||||||
|
psa_status_t status;
|
||||||
|
status = mbed_psa_reboot_and_request_new_security_state(PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
|
||||||
|
TEST_ASSERT_EQUAL(PSA_LIFECYCLE_SUCCESS, status);
|
||||||
|
return greentea_case_setup_handler(source, index_of_case);
|
||||||
}
|
}
|
||||||
|
|
||||||
Case cases[] = {
|
Case cases[] = {
|
||||||
Case("PSA prot internal storage - Basic", pits_test),
|
Case("PSA prot internal storage - Basic", case_setup_handler, pits_test, case_teardown_handler),
|
||||||
Case("PSA prot internal storage - Write-once", pits_write_once_test),
|
Case("PSA prot internal storage - Write-once", case_setup_handler, pits_write_once_test, case_teardown_handler)
|
||||||
};
|
};
|
||||||
|
|
||||||
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
|
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
|
|
@ -1,97 +0,0 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/***********************************************************************************************************************
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* Template Version 1.0
|
|
||||||
* Generated by tools/spm/generate_partition_code.py Version 1.0
|
|
||||||
**********************************************************************************************************************/
|
|
||||||
|
|
||||||
#include "spm_panic.h"
|
|
||||||
#include "spm_internal.h"
|
|
||||||
#include "handles_manager.h"
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "psa_test_its_reset_partition.h"
|
|
||||||
#include "psa_crypto_srv_partition.h"
|
|
||||||
#include "psa_its_partition.h"
|
|
||||||
|
|
||||||
extern const uint32_t crypto_srv_external_sids[4];
|
|
||||||
|
|
||||||
spm_partition_t g_partitions[3] = {
|
|
||||||
{
|
|
||||||
.partition_id = TEST_ITS_RESET_ID,
|
|
||||||
.thread_id = 0,
|
|
||||||
.flags_rot_srv = TEST_ITS_RESET_WAIT_ANY_SID_MSK,
|
|
||||||
.flags_interrupts = 0,
|
|
||||||
.rot_services = NULL,
|
|
||||||
.rot_services_count = TEST_ITS_RESET_ROT_SRV_COUNT,
|
|
||||||
.extern_sids = NULL,
|
|
||||||
.extern_sids_count = TEST_ITS_RESET_EXT_ROT_SRV_COUNT,
|
|
||||||
.irq_mapper = NULL,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.partition_id = CRYPTO_SRV_ID,
|
|
||||||
.thread_id = 0,
|
|
||||||
.flags_rot_srv = CRYPTO_SRV_WAIT_ANY_SID_MSK,
|
|
||||||
.flags_interrupts = 0,
|
|
||||||
.rot_services = NULL,
|
|
||||||
.rot_services_count = CRYPTO_SRV_ROT_SRV_COUNT,
|
|
||||||
.extern_sids = crypto_srv_external_sids,
|
|
||||||
.extern_sids_count = CRYPTO_SRV_EXT_ROT_SRV_COUNT,
|
|
||||||
.irq_mapper = NULL,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.partition_id = ITS_ID,
|
|
||||||
.thread_id = 0,
|
|
||||||
.flags_rot_srv = ITS_WAIT_ANY_SID_MSK,
|
|
||||||
.flags_interrupts = 0,
|
|
||||||
.rot_services = NULL,
|
|
||||||
.rot_services_count = ITS_ROT_SRV_COUNT,
|
|
||||||
.extern_sids = NULL,
|
|
||||||
.extern_sids_count = ITS_EXT_ROT_SRV_COUNT,
|
|
||||||
.irq_mapper = NULL,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Check all the defined memory regions for overlapping. */
|
|
||||||
|
|
||||||
/* A list of all the memory regions. */
|
|
||||||
const mem_region_t *mem_regions = NULL;
|
|
||||||
|
|
||||||
const uint32_t mem_region_count = 0;
|
|
||||||
|
|
||||||
// forward declaration of partition initializers
|
|
||||||
void test_its_reset_init(spm_partition_t *partition);
|
|
||||||
void crypto_srv_init(spm_partition_t *partition);
|
|
||||||
void its_init(spm_partition_t *partition);
|
|
||||||
|
|
||||||
uint32_t init_partitions(spm_partition_t **partitions)
|
|
||||||
{
|
|
||||||
if (NULL == partitions) {
|
|
||||||
SPM_PANIC("partitions is NULL!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
test_its_reset_init(&(g_partitions[0]));
|
|
||||||
crypto_srv_init(&(g_partitions[1]));
|
|
||||||
its_init(&(g_partitions[2]));
|
|
||||||
|
|
||||||
*partitions = g_partitions;
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,59 +0,0 @@
|
||||||
/* Copyright (c) 2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "psa_prot_internal_storage.h"
|
|
||||||
#include "test_pits_impl.h"
|
|
||||||
#include "kv_config.h"
|
|
||||||
#include "KVMap.h"
|
|
||||||
#include "KVStore.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace mbed;
|
|
||||||
|
|
||||||
#define STR_EXPAND(tok) #tok
|
|
||||||
|
|
||||||
psa_its_status_t test_psa_its_reset_impl(void)
|
|
||||||
{
|
|
||||||
psa_its_status_t status = PSA_ITS_SUCCESS;
|
|
||||||
|
|
||||||
int kv_status = kv_init_storage_config();
|
|
||||||
if (kv_status != MBED_SUCCESS) {
|
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
KVMap &kv_map = KVMap::get_instance();
|
|
||||||
KVStore *kvstore = kv_map.get_internal_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
|
|
||||||
if (!kvstore) {
|
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kvstore->reset() != MBED_SUCCESS) {
|
|
||||||
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,37 +0,0 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "spm_client.h"
|
|
||||||
#include "psa_prot_internal_storage.h"
|
|
||||||
#include "test_pits.h"
|
|
||||||
#include "psa_test_its_reset_ifs.h"
|
|
||||||
|
|
||||||
psa_its_status_t test_psa_its_reset(void)
|
|
||||||
{
|
|
||||||
psa_handle_t conn = psa_connect(TEST_PSA_ITS_RESET, 1);
|
|
||||||
if (conn <= PSA_NULL_HANDLE) {
|
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_error_t status = psa_call(conn, NULL, 0, NULL, 0);
|
|
||||||
if (status == PSA_DROP_CONNECTION) {
|
|
||||||
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_close(conn);
|
|
||||||
return status;
|
|
||||||
}
|
|
|
@ -1,101 +0,0 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/***********************************************************************************************************************
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* Template Version 1.0
|
|
||||||
* Generated by tools/spm/generate_partition_code.py Version 1.0
|
|
||||||
**********************************************************************************************************************/
|
|
||||||
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "mbed_toolchain.h" /* For using MBED_ALIGN macro */
|
|
||||||
#include "rtx_os.h"
|
|
||||||
#include "spm_panic.h"
|
|
||||||
#include "spm_internal.h"
|
|
||||||
#include "psa_test_its_reset_partition.h"
|
|
||||||
#include "psa_test_its_reset_ifs.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Threads stacks */
|
|
||||||
MBED_ALIGN(8) uint8_t test_its_reset_thread_stack[1024] = {0};
|
|
||||||
|
|
||||||
/* Threads control blocks */
|
|
||||||
osRtxThread_t test_its_reset_thread_cb = {0};
|
|
||||||
|
|
||||||
/* Thread attributes - for thread initialization */
|
|
||||||
osThreadAttr_t test_its_reset_thread_attr = {
|
|
||||||
.name = "test_its_reset",
|
|
||||||
.attr_bits = 0,
|
|
||||||
.cb_mem = &test_its_reset_thread_cb,
|
|
||||||
.cb_size = sizeof(test_its_reset_thread_cb),
|
|
||||||
.stack_mem = test_its_reset_thread_stack,
|
|
||||||
.stack_size = 1024,
|
|
||||||
.priority = osPriorityNormal,
|
|
||||||
.tz_module = 0,
|
|
||||||
.reserved = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
spm_rot_service_t test_its_reset_rot_services[TEST_ITS_RESET_ROT_SRV_COUNT] = {
|
|
||||||
{
|
|
||||||
.sid = TEST_PSA_ITS_RESET,
|
|
||||||
.mask = TEST_PSA_ITS_RESET_MSK,
|
|
||||||
.partition = NULL,
|
|
||||||
.min_version = 1,
|
|
||||||
.min_version_policy = PSA_MINOR_VERSION_POLICY_RELAXED,
|
|
||||||
.allow_nspe = true,
|
|
||||||
.queue = {
|
|
||||||
.head = NULL,
|
|
||||||
.tail = NULL
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static osRtxMutex_t test_its_reset_mutex = {0};
|
|
||||||
static const osMutexAttr_t test_its_reset_mutex_attr = {
|
|
||||||
.name = "test_its_reset_mutex",
|
|
||||||
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
|
|
||||||
.cb_mem = &test_its_reset_mutex,
|
|
||||||
.cb_size = sizeof(test_its_reset_mutex),
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
extern void test_pits_entry(void *ptr);
|
|
||||||
|
|
||||||
void test_its_reset_init(spm_partition_t *partition)
|
|
||||||
{
|
|
||||||
if (NULL == partition) {
|
|
||||||
SPM_PANIC("partition is NULL!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
partition->mutex = osMutexNew(&test_its_reset_mutex_attr);
|
|
||||||
if (NULL == partition->mutex) {
|
|
||||||
SPM_PANIC("Failed to create mutex for secure partition test_its_reset!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < TEST_ITS_RESET_ROT_SRV_COUNT; ++i) {
|
|
||||||
test_its_reset_rot_services[i].partition = partition;
|
|
||||||
}
|
|
||||||
partition->rot_services = test_its_reset_rot_services;
|
|
||||||
|
|
||||||
partition->thread_id = osThreadNew(test_pits_entry, NULL, &test_its_reset_thread_attr);
|
|
||||||
if (NULL == partition->thread_id) {
|
|
||||||
SPM_PANIC("Failed to create start main thread of partition test_its_reset!\n");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
/* Copyright (c) 2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "psa_prot_internal_storage.h"
|
|
||||||
#include "test_pits_impl.h"
|
|
||||||
#include "kv_config.h"
|
|
||||||
#include "KVMap.h"
|
|
||||||
#include "KVStore.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace mbed;
|
|
||||||
|
|
||||||
#define STR_EXPAND(tok) #tok
|
|
||||||
|
|
||||||
psa_its_status_t test_psa_its_reset_impl(void)
|
|
||||||
{
|
|
||||||
psa_its_status_t status = PSA_ITS_SUCCESS;
|
|
||||||
|
|
||||||
int kv_status = kv_init_storage_config();
|
|
||||||
if (kv_status != MBED_SUCCESS) {
|
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
KVMap &kv_map = KVMap::get_instance();
|
|
||||||
KVStore *kvstore = kv_map.get_internal_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
|
|
||||||
if (!kvstore) {
|
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kvstore->reset() != MBED_SUCCESS) {
|
|
||||||
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,65 +0,0 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// -------------------------------------- Includes -----------------------------------
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "cmsis_os2.h"
|
|
||||||
#include "spm_server.h"
|
|
||||||
#include "spm_panic.h"
|
|
||||||
#include "psa_test_its_reset_partition.h"
|
|
||||||
#include "psa_prot_internal_storage.h"
|
|
||||||
#include "test_pits_impl.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void test_pits_entry(void *ptr)
|
|
||||||
{
|
|
||||||
uint32_t signals = 0;
|
|
||||||
psa_msg_t msg = {0};
|
|
||||||
psa_error_t status = PSA_SUCCESS;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
signals = psa_wait_any(PSA_BLOCK);
|
|
||||||
if ((signals & TEST_PSA_ITS_RESET_MSK) != 0) {
|
|
||||||
psa_get(TEST_PSA_ITS_RESET_MSK, &msg);
|
|
||||||
switch (msg.type) {
|
|
||||||
case PSA_IPC_CONNECT: //fallthrough
|
|
||||||
case PSA_IPC_DISCONNECT: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PSA_IPC_CALL: {
|
|
||||||
status = test_psa_its_reset_impl();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
SPM_PANIC("Unexpected message type %d!", (int)(msg.type));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_reply(msg.handle, status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,48 +0,0 @@
|
||||||
/* Copyright (c) 2018 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __TEST_INTERNAL_TRUSTED_STORAGE_H__
|
|
||||||
#define __TEST_INTERNAL_TRUSTED_STORAGE_H__
|
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief This file describes the PSA Internal Trusted Storage API
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "psa_prot_internal_storage.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Remove the provided key and its associated data from the storage
|
|
||||||
*
|
|
||||||
* \return A status indicating the success/failure of the operation
|
|
||||||
*
|
|
||||||
* \retval PSA_ITS_SUCCESS The operation completed successfully
|
|
||||||
* \retval PSA_ITS_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
|
|
||||||
*/
|
|
||||||
psa_its_status_t test_psa_its_reset(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __TEST_INTERNAL_TRUSTED_STORAGE_H__
|
|
|
@ -1,21 +0,0 @@
|
||||||
{
|
|
||||||
"name": "TEST_ITS_RESET",
|
|
||||||
"type": "APPLICATION-ROT",
|
|
||||||
"priority": "NORMAL",
|
|
||||||
"id": "0x0000000B",
|
|
||||||
"entry_point": "test_pits_entry",
|
|
||||||
"stack_size": "0x400",
|
|
||||||
"heap_size": "0x400",
|
|
||||||
"services": [{
|
|
||||||
"name": "TEST_PSA_ITS_RESET",
|
|
||||||
"identifier": "0x00011A04",
|
|
||||||
"signal": "TEST_PSA_ITS_RESET_MSK",
|
|
||||||
"non_secure_clients": true,
|
|
||||||
"minor_version": 1,
|
|
||||||
"minor_policy": "RELAXED"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source_files": [
|
|
||||||
"COMPONENT_SPE/test_pits_reset_partition.c"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "greentea-client/test_env.h"
|
#include "greentea-client/test_env.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "utest.h"
|
#include "utest.h"
|
||||||
#include "spm_client.h"
|
#include "psa/client.h"
|
||||||
#include "psa_client_tests_part1_ifs.h"
|
#include "psa_client_tests_part1_ifs.h"
|
||||||
|
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
@ -37,7 +37,7 @@ using namespace utest::v1;
|
||||||
|
|
||||||
typedef struct th_struct {
|
typedef struct th_struct {
|
||||||
psa_handle_t handle;
|
psa_handle_t handle;
|
||||||
psa_invec_t *iovec_temp;
|
psa_invec *iovec_temp;
|
||||||
uint8_t *expected;
|
uint8_t *expected;
|
||||||
uint8_t expected_size;
|
uint8_t expected_size;
|
||||||
} th_struct_t;
|
} th_struct_t;
|
||||||
|
@ -55,7 +55,7 @@ static psa_handle_t client_ipc_tests_connect(uint32_t sid, uint32_t minor_versio
|
||||||
|
|
||||||
static void client_ipc_tests_call(
|
static void client_ipc_tests_call(
|
||||||
psa_handle_t handle,
|
psa_handle_t handle,
|
||||||
psa_invec_t *iovec_temp,
|
psa_invec *iovec_temp,
|
||||||
size_t tx_len,
|
size_t tx_len,
|
||||||
size_t rx_len,
|
size_t rx_len,
|
||||||
uint8_t *expected,
|
uint8_t *expected,
|
||||||
|
@ -65,7 +65,7 @@ static void client_ipc_tests_call(
|
||||||
error_t status = PSA_SUCCESS;
|
error_t status = PSA_SUCCESS;
|
||||||
uint8_t *response_buf = (uint8_t *)malloc(CLIENT_RSP_BUF_SIZE * sizeof(uint8_t));
|
uint8_t *response_buf = (uint8_t *)malloc(CLIENT_RSP_BUF_SIZE * sizeof(uint8_t));
|
||||||
memset(response_buf, 0, CLIENT_RSP_BUF_SIZE);
|
memset(response_buf, 0, CLIENT_RSP_BUF_SIZE);
|
||||||
psa_outvec_t resp = {NULL, rx_len};
|
psa_outvec resp = {NULL, rx_len};
|
||||||
|
|
||||||
if (rx_len > 0) {
|
if (rx_len > 0) {
|
||||||
resp.base = response_buf;
|
resp.base = response_buf;
|
||||||
|
@ -105,7 +105,7 @@ void iovec_0_NULL()
|
||||||
uint8_t buff1[] = {1, 2, 3, 4, 5};
|
uint8_t buff1[] = {1, 2, 3, 4, 5};
|
||||||
uint8_t expected_buff[] = {1, 2, 3, 4, 5};
|
uint8_t expected_buff[] = {1, 2, 3, 4, 5};
|
||||||
|
|
||||||
psa_invec_t iovec_temp[PSA_MAX_IOVEC - 1] = {
|
psa_invec iovec_temp[PSA_MAX_IOVEC - 1] = {
|
||||||
{NULL, 0},
|
{NULL, 0},
|
||||||
{meta_iovec, sizeof(meta_iovec)},
|
{meta_iovec, sizeof(meta_iovec)},
|
||||||
{buff1, sizeof(buff1)}
|
{buff1, sizeof(buff1)}
|
||||||
|
@ -128,7 +128,7 @@ void iovec_1_NULL()
|
||||||
uint8_t buff1[] = {1, 2, 3, 4, 5};
|
uint8_t buff1[] = {1, 2, 3, 4, 5};
|
||||||
uint8_t expected_buff[] = {2, 3};
|
uint8_t expected_buff[] = {2, 3};
|
||||||
|
|
||||||
psa_invec_t iovec_temp[PSA_MAX_IOVEC - 1] = {{meta_iovec, sizeof(meta_iovec)},
|
psa_invec iovec_temp[PSA_MAX_IOVEC - 1] = {{meta_iovec, sizeof(meta_iovec)},
|
||||||
{NULL, 0},
|
{NULL, 0},
|
||||||
{buff1, sizeof(buff1)}
|
{buff1, sizeof(buff1)}
|
||||||
};
|
};
|
||||||
|
@ -150,7 +150,7 @@ void iovec_2_NULL()
|
||||||
uint8_t buff1[] = {1, 2, 3, 4, 5};
|
uint8_t buff1[] = {1, 2, 3, 4, 5};
|
||||||
uint8_t expected_buff[] = {2, 3};
|
uint8_t expected_buff[] = {2, 3};
|
||||||
|
|
||||||
psa_invec_t iovec_temp[PSA_MAX_IOVEC - 1] = {{meta_iovec, sizeof(meta_iovec)},
|
psa_invec iovec_temp[PSA_MAX_IOVEC - 1] = {{meta_iovec, sizeof(meta_iovec)},
|
||||||
{buff1, sizeof(buff1)},
|
{buff1, sizeof(buff1)},
|
||||||
{NULL, 0}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
@ -164,7 +164,7 @@ void iovec_2_NULL()
|
||||||
void in_vec_base_not_NULL_size_0()
|
void in_vec_base_not_NULL_size_0()
|
||||||
{
|
{
|
||||||
uint8_t dummy_buff[] = {1, 2, 3, 4, 5};
|
uint8_t dummy_buff[] = {1, 2, 3, 4, 5};
|
||||||
psa_invec_t iovec_temp[1] = { {dummy_buff, 0} };
|
psa_invec iovec_temp[1] = { {dummy_buff, 0} };
|
||||||
|
|
||||||
psa_handle_t handle = client_ipc_tests_connect(PART1_ROT_SRV1, MINOR_VER);
|
psa_handle_t handle = client_ipc_tests_connect(PART1_ROT_SRV1, MINOR_VER);
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ void in_vec_base_not_NULL_size_0()
|
||||||
void in_len_0_in_vec_not_NULL()
|
void in_len_0_in_vec_not_NULL()
|
||||||
{
|
{
|
||||||
uint8_t dummy_buff[] = {1, 2, 3, 4, 5};
|
uint8_t dummy_buff[] = {1, 2, 3, 4, 5};
|
||||||
psa_invec_t iovec_temp[1] = { {dummy_buff, sizeof(dummy_buff)} };
|
psa_invec iovec_temp[1] = { {dummy_buff, sizeof(dummy_buff)} };
|
||||||
|
|
||||||
psa_handle_t handle = client_ipc_tests_connect(PART1_ROT_SRV1, MINOR_VER);
|
psa_handle_t handle = client_ipc_tests_connect(PART1_ROT_SRV1, MINOR_VER);
|
||||||
|
|
||||||
|
@ -192,13 +192,13 @@ void out_len_0_outvec_not_NULL()
|
||||||
error_t status = PSA_SUCCESS;
|
error_t status = PSA_SUCCESS;
|
||||||
|
|
||||||
uint8_t dummy_res[10] = {0};
|
uint8_t dummy_res[10] = {0};
|
||||||
psa_outvec_t outvec_temp[1] = {{dummy_res, sizeof(dummy_res)}};
|
psa_outvec outvec_temp[1] = {{dummy_res, sizeof(dummy_res)}};
|
||||||
|
|
||||||
uint8_t dummy_buff[] = {1, 2, 3, 4, 5};
|
uint8_t dummy_buff[] = {1, 2, 3, 4, 5};
|
||||||
|
|
||||||
psa_handle_t handle = client_ipc_tests_connect(PART1_ROT_SRV1, MINOR_VER);
|
psa_handle_t handle = client_ipc_tests_connect(PART1_ROT_SRV1, MINOR_VER);
|
||||||
|
|
||||||
psa_invec_t in_vec_temp[2] = { {dummy_buff, sizeof(dummy_buff)},
|
psa_invec in_vec_temp[2] = { {dummy_buff, sizeof(dummy_buff)},
|
||||||
{dummy_buff, sizeof(dummy_buff)}
|
{dummy_buff, sizeof(dummy_buff)}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ void rx_buff_null()
|
||||||
uint8_t meta_iovec[2] = {expect_size, off};
|
uint8_t meta_iovec[2] = {expect_size, off};
|
||||||
uint8_t buff1[] = {1, 2, 3, 4, 5}, buff2[] = {6};
|
uint8_t buff1[] = {1, 2, 3, 4, 5}, buff2[] = {6};
|
||||||
|
|
||||||
psa_invec_t iovec_temp[PSA_MAX_IOVEC - 1] = {{meta_iovec, sizeof(meta_iovec)},
|
psa_invec iovec_temp[PSA_MAX_IOVEC - 1] = {{meta_iovec, sizeof(meta_iovec)},
|
||||||
{buff1, sizeof(buff1)},
|
{buff1, sizeof(buff1)},
|
||||||
{buff2, sizeof(buff2)}
|
{buff2, sizeof(buff2)}
|
||||||
};
|
};
|
||||||
|
@ -261,7 +261,7 @@ void multiple_call()
|
||||||
uint8_t buff2[] = {4, 5, 6};
|
uint8_t buff2[] = {4, 5, 6};
|
||||||
uint8_t expected_buff[] = {1, 2};
|
uint8_t expected_buff[] = {1, 2};
|
||||||
|
|
||||||
psa_invec_t iovec_temp[PSA_MAX_IOVEC - 1] = {{meta_iovec, sizeof(meta_iovec)},
|
psa_invec iovec_temp[PSA_MAX_IOVEC - 1] = {{meta_iovec, sizeof(meta_iovec)},
|
||||||
{buff1, sizeof(buff1)},
|
{buff1, sizeof(buff1)},
|
||||||
{buff2, sizeof(buff2)}
|
{buff2, sizeof(buff2)}
|
||||||
};
|
};
|
||||||
|
@ -285,7 +285,7 @@ void multiple_call()
|
||||||
client_ipc_tests_close(handle);
|
client_ipc_tests_close(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_struct(th_struct_t *thr_attr, psa_handle_t handle, psa_invec_t *iovec_temp, uint8_t *expect, uint8_t expected_size)
|
static void set_struct(th_struct_t *thr_attr, psa_handle_t handle, psa_invec *iovec_temp, uint8_t *expect, uint8_t expected_size)
|
||||||
{
|
{
|
||||||
thr_attr->handle = handle;
|
thr_attr->handle = handle;
|
||||||
thr_attr->iovec_temp = iovec_temp;
|
thr_attr->iovec_temp = iovec_temp;
|
||||||
|
@ -322,7 +322,7 @@ void multi_thread_diff_handles()
|
||||||
uint8_t buff2[] = {4, 5, 6};
|
uint8_t buff2[] = {4, 5, 6};
|
||||||
uint8_t expected_buff_1[] = {1, 2};
|
uint8_t expected_buff_1[] = {1, 2};
|
||||||
|
|
||||||
psa_invec_t iovec_temp_1[PSA_MAX_IOVEC - 1] = {{meta_iovec_1, sizeof(meta_iovec_1)},
|
psa_invec iovec_temp_1[PSA_MAX_IOVEC - 1] = {{meta_iovec_1, sizeof(meta_iovec_1)},
|
||||||
{buff1, sizeof(buff1)},
|
{buff1, sizeof(buff1)},
|
||||||
{buff2, sizeof(buff2)}
|
{buff2, sizeof(buff2)}
|
||||||
};
|
};
|
||||||
|
@ -338,7 +338,7 @@ void multi_thread_diff_handles()
|
||||||
};
|
};
|
||||||
uint8_t expected_buff_2[] = {2, 3};
|
uint8_t expected_buff_2[] = {2, 3};
|
||||||
|
|
||||||
psa_invec_t iovec_temp_2[PSA_MAX_IOVEC - 1] = {{meta_iovec_2, sizeof(meta_iovec_2)},
|
psa_invec iovec_temp_2[PSA_MAX_IOVEC - 1] = {{meta_iovec_2, sizeof(meta_iovec_2)},
|
||||||
{buff1, sizeof(buff1)},
|
{buff1, sizeof(buff1)},
|
||||||
{buff2, sizeof(buff2)}
|
{buff2, sizeof(buff2)}
|
||||||
};
|
};
|
||||||
|
@ -353,7 +353,7 @@ void multi_thread_diff_handles()
|
||||||
};
|
};
|
||||||
uint8_t expected_buff_3[] = {3, 4};
|
uint8_t expected_buff_3[] = {3, 4};
|
||||||
|
|
||||||
psa_invec_t iovec_temp_3[PSA_MAX_IOVEC - 1] = {{meta_iovec_3, sizeof(meta_iovec_3)},
|
psa_invec iovec_temp_3[PSA_MAX_IOVEC - 1] = {{meta_iovec_3, sizeof(meta_iovec_3)},
|
||||||
{buff1, sizeof(buff1)},
|
{buff1, sizeof(buff1)},
|
||||||
{buff2, sizeof(buff2)}
|
{buff2, sizeof(buff2)}
|
||||||
};
|
};
|
||||||
|
@ -408,7 +408,7 @@ void client_close_null_handle()
|
||||||
void drop_connection()
|
void drop_connection()
|
||||||
{
|
{
|
||||||
psa_handle_t handle = client_ipc_tests_connect(DROP_CONN, DROP_CONN_MINOR_VER);
|
psa_handle_t handle = client_ipc_tests_connect(DROP_CONN, DROP_CONN_MINOR_VER);
|
||||||
psa_error_t status = psa_call(handle, NULL, 0, NULL, 0);
|
psa_status_t status = psa_call(handle, NULL, 0, NULL, 0);
|
||||||
TEST_ASSERT_EQUAL_INT(PSA_DROP_CONNECTION, status);
|
TEST_ASSERT_EQUAL_INT(PSA_DROP_CONNECTION, status);
|
||||||
|
|
||||||
status = PSA_SUCCESS;
|
status = PSA_SUCCESS;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -123,3 +123,4 @@ void client_tests_part1_init(spm_partition_t *partition)
|
||||||
SPM_PANIC("Failed to create start main thread of partition client_tests_part1!\n");
|
SPM_PANIC("Failed to create start main thread of partition client_tests_part1!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -29,11 +29,12 @@
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "psa_client_tests_part1_partition.h"
|
#include "psa_client_tests_part1_partition.h"
|
||||||
#include "psa_crypto_srv_partition.h"
|
#include "psa_crypto_srv_partition.h"
|
||||||
|
#include "psa_platform_partition.h"
|
||||||
#include "psa_its_partition.h"
|
#include "psa_its_partition.h"
|
||||||
|
|
||||||
extern const uint32_t crypto_srv_external_sids[4];
|
extern const uint32_t crypto_srv_external_sids[4];
|
||||||
|
|
||||||
spm_partition_t g_partitions[3] = {
|
spm_partition_t g_partitions[4] = {
|
||||||
{
|
{
|
||||||
.partition_id = CLIENT_TESTS_PART1_ID,
|
.partition_id = CLIENT_TESTS_PART1_ID,
|
||||||
.thread_id = 0,
|
.thread_id = 0,
|
||||||
|
@ -56,6 +57,17 @@ spm_partition_t g_partitions[3] = {
|
||||||
.extern_sids_count = CRYPTO_SRV_EXT_ROT_SRV_COUNT,
|
.extern_sids_count = CRYPTO_SRV_EXT_ROT_SRV_COUNT,
|
||||||
.irq_mapper = NULL,
|
.irq_mapper = NULL,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.partition_id = PLATFORM_ID,
|
||||||
|
.thread_id = 0,
|
||||||
|
.flags_rot_srv = PLATFORM_WAIT_ANY_SID_MSK,
|
||||||
|
.flags_interrupts = 0,
|
||||||
|
.rot_services = NULL,
|
||||||
|
.rot_services_count = PLATFORM_ROT_SRV_COUNT,
|
||||||
|
.extern_sids = NULL,
|
||||||
|
.extern_sids_count = PLATFORM_EXT_ROT_SRV_COUNT,
|
||||||
|
.irq_mapper = NULL,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.partition_id = ITS_ID,
|
.partition_id = ITS_ID,
|
||||||
.thread_id = 0,
|
.thread_id = 0,
|
||||||
|
@ -79,6 +91,7 @@ const uint32_t mem_region_count = 0;
|
||||||
// forward declaration of partition initializers
|
// forward declaration of partition initializers
|
||||||
void client_tests_part1_init(spm_partition_t *partition);
|
void client_tests_part1_init(spm_partition_t *partition);
|
||||||
void crypto_srv_init(spm_partition_t *partition);
|
void crypto_srv_init(spm_partition_t *partition);
|
||||||
|
void platform_init(spm_partition_t *partition);
|
||||||
void its_init(spm_partition_t *partition);
|
void its_init(spm_partition_t *partition);
|
||||||
|
|
||||||
uint32_t init_partitions(spm_partition_t **partitions)
|
uint32_t init_partitions(spm_partition_t **partitions)
|
||||||
|
@ -89,9 +102,10 @@ uint32_t init_partitions(spm_partition_t **partitions)
|
||||||
|
|
||||||
client_tests_part1_init(&(g_partitions[0]));
|
client_tests_part1_init(&(g_partitions[0]));
|
||||||
crypto_srv_init(&(g_partitions[1]));
|
crypto_srv_init(&(g_partitions[1]));
|
||||||
its_init(&(g_partitions[2]));
|
platform_init(&(g_partitions[2]));
|
||||||
|
its_init(&(g_partitions[3]));
|
||||||
|
|
||||||
*partitions = g_partitions;
|
*partitions = g_partitions;
|
||||||
return 3;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "spm_server.h"
|
#include "psa/service.h"
|
||||||
#include "spm_panic.h"
|
#include "spm_panic.h"
|
||||||
#include "psa_client_tests_part1_partition.h"
|
#include "psa_client_tests_part1_partition.h"
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "greentea-client/test_env.h"
|
#include "greentea-client/test_env.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "utest.h"
|
#include "utest.h"
|
||||||
#include "spm_client.h"
|
#include "psa/client.h"
|
||||||
#include "psa_server_test_part1_ifs.h"
|
#include "psa_server_test_part1_ifs.h"
|
||||||
#include "server_tests.h"
|
#include "server_tests.h"
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
@ -57,7 +57,7 @@ PSA_TEST_CLIENT(identity_during_connect)
|
||||||
|
|
||||||
PSA_TEST_CLIENT(identity_during_call)
|
PSA_TEST_CLIENT(identity_during_call)
|
||||||
{
|
{
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
||||||
TEST_ASSERT(test_handle > 0);
|
TEST_ASSERT(test_handle > 0);
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ PSA_TEST_CLIENT(identity_during_call)
|
||||||
|
|
||||||
PSA_TEST_CLIENT(msg_size_assertion)
|
PSA_TEST_CLIENT(msg_size_assertion)
|
||||||
{
|
{
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
psa_invec_t data[PSA_MAX_IOVEC] = {
|
psa_invec data[PSA_MAX_IOVEC] = {
|
||||||
{test_str, 4},
|
{test_str, 4},
|
||||||
{test_str + 5, 6},
|
{test_str + 5, 6},
|
||||||
{test_str + 13, 1},
|
{test_str + 13, 1},
|
||||||
|
@ -93,8 +93,8 @@ PSA_TEST_CLIENT(reject_connection)
|
||||||
|
|
||||||
PSA_TEST_CLIENT(read_at_outofboud_offset)
|
PSA_TEST_CLIENT(read_at_outofboud_offset)
|
||||||
{
|
{
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
psa_invec_t data = { test_str, sizeof(test_str) };
|
psa_invec data = { test_str, sizeof(test_str) };
|
||||||
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
||||||
TEST_ASSERT(test_handle > 0);
|
TEST_ASSERT(test_handle > 0);
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@ PSA_TEST_CLIENT(read_at_outofboud_offset)
|
||||||
|
|
||||||
PSA_TEST_CLIENT(msg_read_truncation)
|
PSA_TEST_CLIENT(msg_read_truncation)
|
||||||
{
|
{
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
psa_invec_t data[3] = {
|
psa_invec data[3] = {
|
||||||
{test_str, 4},
|
{test_str, 4},
|
||||||
{test_str + 5, 6},
|
{test_str + 5, 6},
|
||||||
{test_str + 13, 1}
|
{test_str + 13, 1}
|
||||||
|
@ -123,8 +123,8 @@ PSA_TEST_CLIENT(msg_read_truncation)
|
||||||
|
|
||||||
PSA_TEST_CLIENT(skip_zero)
|
PSA_TEST_CLIENT(skip_zero)
|
||||||
{
|
{
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
psa_invec_t data = { test_str, sizeof(test_str) };
|
psa_invec data = { test_str, sizeof(test_str) };
|
||||||
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
||||||
TEST_ASSERT(test_handle > 0);
|
TEST_ASSERT(test_handle > 0);
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ PSA_TEST_CLIENT(skip_zero)
|
||||||
|
|
||||||
PSA_TEST_CLIENT(skip_some)
|
PSA_TEST_CLIENT(skip_some)
|
||||||
{
|
{
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
psa_invec_t data = { test_str, sizeof(test_str) };
|
psa_invec data = { test_str, sizeof(test_str) };
|
||||||
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
||||||
TEST_ASSERT(test_handle > 0);
|
TEST_ASSERT(test_handle > 0);
|
||||||
|
|
||||||
|
@ -149,8 +149,8 @@ PSA_TEST_CLIENT(skip_some)
|
||||||
|
|
||||||
PSA_TEST_CLIENT(skip_more_than_left)
|
PSA_TEST_CLIENT(skip_more_than_left)
|
||||||
{
|
{
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
psa_invec_t data = { test_str, 8 };
|
psa_invec data = { test_str, 8 };
|
||||||
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
||||||
TEST_ASSERT(test_handle > 0);
|
TEST_ASSERT(test_handle > 0);
|
||||||
|
|
||||||
|
@ -164,8 +164,8 @@ PSA_TEST_CLIENT(rhandle_factorial)
|
||||||
{
|
{
|
||||||
uint32_t secure_value = 0;
|
uint32_t secure_value = 0;
|
||||||
uint32_t value = 1;
|
uint32_t value = 1;
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
psa_outvec_t resp = { &secure_value, sizeof(secure_value) };
|
psa_outvec resp = { &secure_value, sizeof(secure_value) };
|
||||||
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
||||||
TEST_ASSERT(test_handle > 0);
|
TEST_ASSERT(test_handle > 0);
|
||||||
|
|
||||||
|
@ -185,12 +185,12 @@ PSA_TEST_CLIENT(cross_partition_call)
|
||||||
size_t in_len = strlen(cross_part_buf);
|
size_t in_len = strlen(cross_part_buf);
|
||||||
TEST_ASSERT_MESSAGE(test_handle > 0, "psa_connect() failed");
|
TEST_ASSERT_MESSAGE(test_handle > 0, "psa_connect() failed");
|
||||||
|
|
||||||
psa_invec_t iovec = { cross_part_buf, in_len };
|
psa_invec iovec = { cross_part_buf, in_len };
|
||||||
uint8_t *response_buf = (uint8_t *)malloc(sizeof(uint8_t) * OUT_BUFFER_SIZE);
|
uint8_t *response_buf = (uint8_t *)malloc(sizeof(uint8_t) * OUT_BUFFER_SIZE);
|
||||||
memset(response_buf, 0, OUT_BUFFER_SIZE);
|
memset(response_buf, 0, OUT_BUFFER_SIZE);
|
||||||
psa_outvec_t resp = { response_buf, OUT_BUFFER_SIZE };
|
psa_outvec resp = { response_buf, OUT_BUFFER_SIZE };
|
||||||
|
|
||||||
psa_error_t status = psa_call(test_handle, &iovec, 1, &resp, 1);
|
psa_status_t status = psa_call(test_handle, &iovec, 1, &resp, 1);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
|
||||||
TEST_ASSERT_EQUAL_STRING_LEN("MPS emoclew dna olleHMPS emoclew dna olleH", response_buf, in_len * 2);
|
TEST_ASSERT_EQUAL_STRING_LEN("MPS emoclew dna olleHMPS emoclew dna olleH", response_buf, in_len * 2);
|
||||||
free(response_buf);
|
free(response_buf);
|
||||||
|
@ -204,7 +204,7 @@ PSA_TEST_CLIENT(doorbell_test)
|
||||||
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
psa_handle_t test_handle = psa_connect(TEST, TEST_ROT_SRV_MINOR);
|
||||||
TEST_ASSERT_MESSAGE(test_handle > 0, "psa_connect() failed");
|
TEST_ASSERT_MESSAGE(test_handle > 0, "psa_connect() failed");
|
||||||
|
|
||||||
psa_error_t status = psa_call(test_handle, NULL, 0, NULL, 0);
|
psa_status_t status = psa_call(test_handle, NULL, 0, NULL, 0);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
|
||||||
|
|
||||||
psa_close(test_handle);
|
psa_close(test_handle);
|
||||||
|
@ -232,9 +232,9 @@ void spm_teardown(const size_t passed, const size_t failed, const failure_t fail
|
||||||
|
|
||||||
utest::v1::status_t spm_case_setup(const Case *const source, const size_t index_of_case)
|
utest::v1::status_t spm_case_setup(const Case *const source, const size_t index_of_case)
|
||||||
{
|
{
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
test_action_t action = START_TEST;
|
test_action_t action = START_TEST;
|
||||||
psa_invec_t data = {&action, sizeof(action)};
|
psa_invec data = {&action, sizeof(action)};
|
||||||
|
|
||||||
status = psa_call(control_handle, &data, 1, NULL, 0);
|
status = psa_call(control_handle, &data, 1, NULL, 0);
|
||||||
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
|
||||||
|
@ -244,11 +244,11 @@ utest::v1::status_t spm_case_setup(const Case *const source, const size_t index_
|
||||||
|
|
||||||
utest::v1::status_t spm_case_teardown(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
|
utest::v1::status_t spm_case_teardown(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
|
||||||
{
|
{
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
test_action_t action = GET_TEST_RESULT;
|
test_action_t action = GET_TEST_RESULT;
|
||||||
psa_invec_t data = {&action, sizeof(action)};
|
psa_invec data = {&action, sizeof(action)};
|
||||||
psa_outvec_t resp = {&test_status, sizeof(test_status)};
|
psa_outvec resp = {&test_status, sizeof(test_status)};
|
||||||
|
|
||||||
// Wait for psa_close to finish on server side
|
// Wait for psa_close to finish on server side
|
||||||
osDelay(50);
|
osDelay(50);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -117,3 +117,4 @@ void server_test_part1_init(spm_partition_t *partition)
|
||||||
SPM_PANIC("Failed to create start main thread of partition server_test_part1!\n");
|
SPM_PANIC("Failed to create start main thread of partition server_test_part1!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -111,3 +111,4 @@ void server_test_part2_init(spm_partition_t *partition)
|
||||||
SPM_PANIC("Failed to create start main thread of partition server_test_part2!\n");
|
SPM_PANIC("Failed to create start main thread of partition server_test_part2!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "spm_server.h"
|
#include "psa/service.h"
|
||||||
#include "spm_panic.h"
|
#include "spm_panic.h"
|
||||||
#include "psa_server_test_part1_partition.h"
|
#include "psa_server_test_part1_partition.h"
|
||||||
#include "server_tests.h"
|
#include "server_tests.h"
|
||||||
|
@ -37,8 +37,8 @@ static void init_num_of_tests()
|
||||||
void part1_main(void *ptr)
|
void part1_main(void *ptr)
|
||||||
{
|
{
|
||||||
uint32_t signals = 0;
|
uint32_t signals = 0;
|
||||||
psa_error_t test_status = PSA_SUCCESS; // status of the api calls during the test
|
psa_status_t test_status = PSA_SUCCESS; // status of the api calls during the test
|
||||||
psa_error_t test_result = PSA_SUCCESS; // result of the critical section of the test
|
psa_status_t test_result = PSA_SUCCESS; // result of the critical section of the test
|
||||||
test_action_t action;
|
test_action_t action;
|
||||||
uint32_t test_idx = 0;
|
uint32_t test_idx = 0;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "cmsis_os2.h"
|
#include "cmsis_os2.h"
|
||||||
#include "spm_server.h"
|
#include "psa/service.h"
|
||||||
#include "spm_panic.h"
|
#include "spm_panic.h"
|
||||||
#include "psa_server_test_part2_partition.h"
|
#include "psa_server_test_part2_partition.h"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -30,12 +30,13 @@
|
||||||
#include "psa_server_test_part1_partition.h"
|
#include "psa_server_test_part1_partition.h"
|
||||||
#include "psa_server_test_part2_partition.h"
|
#include "psa_server_test_part2_partition.h"
|
||||||
#include "psa_crypto_srv_partition.h"
|
#include "psa_crypto_srv_partition.h"
|
||||||
|
#include "psa_platform_partition.h"
|
||||||
#include "psa_its_partition.h"
|
#include "psa_its_partition.h"
|
||||||
|
|
||||||
extern const uint32_t server_test_part1_external_sids[2];
|
extern const uint32_t server_test_part1_external_sids[2];
|
||||||
extern const uint32_t crypto_srv_external_sids[4];
|
extern const uint32_t crypto_srv_external_sids[4];
|
||||||
|
|
||||||
spm_partition_t g_partitions[4] = {
|
spm_partition_t g_partitions[5] = {
|
||||||
{
|
{
|
||||||
.partition_id = SERVER_TEST_PART1_ID,
|
.partition_id = SERVER_TEST_PART1_ID,
|
||||||
.thread_id = 0,
|
.thread_id = 0,
|
||||||
|
@ -69,6 +70,17 @@ spm_partition_t g_partitions[4] = {
|
||||||
.extern_sids_count = CRYPTO_SRV_EXT_ROT_SRV_COUNT,
|
.extern_sids_count = CRYPTO_SRV_EXT_ROT_SRV_COUNT,
|
||||||
.irq_mapper = NULL,
|
.irq_mapper = NULL,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.partition_id = PLATFORM_ID,
|
||||||
|
.thread_id = 0,
|
||||||
|
.flags_rot_srv = PLATFORM_WAIT_ANY_SID_MSK,
|
||||||
|
.flags_interrupts = 0,
|
||||||
|
.rot_services = NULL,
|
||||||
|
.rot_services_count = PLATFORM_ROT_SRV_COUNT,
|
||||||
|
.extern_sids = NULL,
|
||||||
|
.extern_sids_count = PLATFORM_EXT_ROT_SRV_COUNT,
|
||||||
|
.irq_mapper = NULL,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.partition_id = ITS_ID,
|
.partition_id = ITS_ID,
|
||||||
.thread_id = 0,
|
.thread_id = 0,
|
||||||
|
@ -93,6 +105,7 @@ const uint32_t mem_region_count = 0;
|
||||||
void server_test_part1_init(spm_partition_t *partition);
|
void server_test_part1_init(spm_partition_t *partition);
|
||||||
void server_test_part2_init(spm_partition_t *partition);
|
void server_test_part2_init(spm_partition_t *partition);
|
||||||
void crypto_srv_init(spm_partition_t *partition);
|
void crypto_srv_init(spm_partition_t *partition);
|
||||||
|
void platform_init(spm_partition_t *partition);
|
||||||
void its_init(spm_partition_t *partition);
|
void its_init(spm_partition_t *partition);
|
||||||
|
|
||||||
uint32_t init_partitions(spm_partition_t **partitions)
|
uint32_t init_partitions(spm_partition_t **partitions)
|
||||||
|
@ -104,9 +117,10 @@ uint32_t init_partitions(spm_partition_t **partitions)
|
||||||
server_test_part1_init(&(g_partitions[0]));
|
server_test_part1_init(&(g_partitions[0]));
|
||||||
server_test_part2_init(&(g_partitions[1]));
|
server_test_part2_init(&(g_partitions[1]));
|
||||||
crypto_srv_init(&(g_partitions[2]));
|
crypto_srv_init(&(g_partitions[2]));
|
||||||
its_init(&(g_partitions[3]));
|
platform_init(&(g_partitions[3]));
|
||||||
|
its_init(&(g_partitions[4]));
|
||||||
|
|
||||||
*partitions = g_partitions;
|
*partitions = g_partitions;
|
||||||
return 4;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,13 +28,13 @@ typedef struct factorial_data {
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
} factorial_data_t;
|
} factorial_data_t;
|
||||||
|
|
||||||
typedef psa_error_t (*psa_test_server_side_func)(psa_error_t *);
|
typedef psa_status_t (*psa_test_server_side_func)(psa_status_t *);
|
||||||
#define PSA_TEST_ERROR (-1L)
|
#define PSA_TEST_ERROR (-1L)
|
||||||
#define PSA_TEST_CLIENT_NAME(name) psa_test_client_side_ ## name
|
#define PSA_TEST_CLIENT_NAME(name) psa_test_client_side_ ## name
|
||||||
#define PSA_TEST_SERVER_NAME(name) psa_test_server_side_ ## name
|
#define PSA_TEST_SERVER_NAME(name) psa_test_server_side_ ## name
|
||||||
|
|
||||||
#define PSA_TEST_CLIENT(name) void PSA_TEST_CLIENT_NAME(name) (void)
|
#define PSA_TEST_CLIENT(name) void PSA_TEST_CLIENT_NAME(name) (void)
|
||||||
#define PSA_TEST_SERVER(name) psa_error_t PSA_TEST_SERVER_NAME(name) (psa_error_t* status_ptr)
|
#define PSA_TEST_SERVER(name) psa_status_t PSA_TEST_SERVER_NAME(name) (psa_status_t *status_ptr)
|
||||||
|
|
||||||
#define PSA_TEST(name) \
|
#define PSA_TEST(name) \
|
||||||
PSA_TEST_CLIENT(name); \
|
PSA_TEST_CLIENT(name); \
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "spm_client.h"
|
#include "psa/client.h"
|
||||||
#include "spm_server.h"
|
#include "psa/service.h"
|
||||||
#include "spm_panic.h"
|
#include "spm_panic.h"
|
||||||
#include "psa_server_test_part1_partition.h"
|
#include "psa_server_test_part1_partition.h"
|
||||||
#include "psa_server_test_part2_ifs.h"
|
#include "psa_server_test_part2_ifs.h"
|
||||||
|
@ -27,9 +27,9 @@
|
||||||
* Process a generic connect message to TEST ROT_SRV.
|
* Process a generic connect message to TEST ROT_SRV.
|
||||||
* @return PSA_SUCCESS or negative error code if failed.
|
* @return PSA_SUCCESS or negative error code if failed.
|
||||||
*/
|
*/
|
||||||
static psa_error_t process_connect_request(void)
|
static psa_status_t process_connect_request(void)
|
||||||
{
|
{
|
||||||
psa_error_t res = PSA_SUCCESS;
|
psa_status_t res = PSA_SUCCESS;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
uint32_t signals = psa_wait_any(PSA_BLOCK);
|
uint32_t signals = psa_wait_any(PSA_BLOCK);
|
||||||
if ((signals & TEST_MSK) == 0) {
|
if ((signals & TEST_MSK) == 0) {
|
||||||
|
@ -50,9 +50,9 @@ static psa_error_t process_connect_request(void)
|
||||||
* Process a generic disconnect message to TEST ROT_SRV.
|
* Process a generic disconnect message to TEST ROT_SRV.
|
||||||
* @return PSA_SUCCESS or negative error code if failed.
|
* @return PSA_SUCCESS or negative error code if failed.
|
||||||
*/
|
*/
|
||||||
static psa_error_t process_disconnect_request(void)
|
static psa_status_t process_disconnect_request(void)
|
||||||
{
|
{
|
||||||
psa_error_t res = PSA_SUCCESS;
|
psa_status_t res = PSA_SUCCESS;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
uint32_t signals = psa_wait_any(PSA_BLOCK);
|
uint32_t signals = psa_wait_any(PSA_BLOCK);
|
||||||
if ((signals & TEST_MSK) == 0) {
|
if ((signals & TEST_MSK) == 0) {
|
||||||
|
@ -71,7 +71,7 @@ static psa_error_t process_disconnect_request(void)
|
||||||
|
|
||||||
PSA_TEST_SERVER(wait_timeout)
|
PSA_TEST_SERVER(wait_timeout)
|
||||||
{
|
{
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
uint32_t signals = psa_wait_any(7);
|
uint32_t signals = psa_wait_any(7);
|
||||||
*status_ptr = ((signals & TEST_MSK) == 0) ? PSA_SUCCESS : PSA_TEST_ERROR;;
|
*status_ptr = ((signals & TEST_MSK) == 0) ? PSA_SUCCESS : PSA_TEST_ERROR;;
|
||||||
|
|
||||||
|
@ -89,8 +89,8 @@ PSA_TEST_SERVER(wait_timeout)
|
||||||
|
|
||||||
PSA_TEST_SERVER(identity_during_connect)
|
PSA_TEST_SERVER(identity_during_connect)
|
||||||
{
|
{
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
psa_error_t disconnect_status = PSA_SUCCESS;
|
psa_status_t disconnect_status = PSA_SUCCESS;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
int32_t identity = 0;
|
int32_t identity = 0;
|
||||||
|
|
||||||
|
@ -117,8 +117,8 @@ PSA_TEST_SERVER(identity_during_connect)
|
||||||
|
|
||||||
PSA_TEST_SERVER(identity_during_call)
|
PSA_TEST_SERVER(identity_during_call)
|
||||||
{
|
{
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
psa_error_t disconnect_status = PSA_SUCCESS;
|
psa_status_t disconnect_status = PSA_SUCCESS;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
int32_t identity = 0;
|
int32_t identity = 0;
|
||||||
uint32_t signals = 0;
|
uint32_t signals = 0;
|
||||||
|
@ -151,8 +151,8 @@ PSA_TEST_SERVER(identity_during_call)
|
||||||
|
|
||||||
PSA_TEST_SERVER(msg_size_assertion)
|
PSA_TEST_SERVER(msg_size_assertion)
|
||||||
{
|
{
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
psa_error_t disconnect_status = PSA_SUCCESS;
|
psa_status_t disconnect_status = PSA_SUCCESS;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
uint32_t signals = 0;
|
uint32_t signals = 0;
|
||||||
size_t read_size = 0;
|
size_t read_size = 0;
|
||||||
|
@ -199,7 +199,7 @@ PSA_TEST_SERVER(msg_size_assertion)
|
||||||
|
|
||||||
PSA_TEST_SERVER(reject_connection)
|
PSA_TEST_SERVER(reject_connection)
|
||||||
{
|
{
|
||||||
psa_error_t res = PSA_SUCCESS;
|
psa_status_t res = PSA_SUCCESS;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
uint32_t signals = psa_wait_any(PSA_BLOCK);
|
uint32_t signals = psa_wait_any(PSA_BLOCK);
|
||||||
if ((signals & TEST_MSK) == 0) {
|
if ((signals & TEST_MSK) == 0) {
|
||||||
|
@ -220,8 +220,8 @@ PSA_TEST_SERVER(read_at_outofboud_offset)
|
||||||
{
|
{
|
||||||
uint32_t signals = 0;
|
uint32_t signals = 0;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
psa_error_t disconnect_status = PSA_SUCCESS;
|
psa_status_t disconnect_status = PSA_SUCCESS;
|
||||||
uint32_t buff = 52;
|
uint32_t buff = 52;
|
||||||
|
|
||||||
test_status = process_connect_request();
|
test_status = process_connect_request();
|
||||||
|
@ -255,8 +255,8 @@ PSA_TEST_SERVER(read_at_outofboud_offset)
|
||||||
|
|
||||||
PSA_TEST_SERVER(msg_read_truncation)
|
PSA_TEST_SERVER(msg_read_truncation)
|
||||||
{
|
{
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
psa_error_t disconnect_status = PSA_SUCCESS;
|
psa_status_t disconnect_status = PSA_SUCCESS;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
uint32_t signals = 0;
|
uint32_t signals = 0;
|
||||||
size_t read_size = 0;
|
size_t read_size = 0;
|
||||||
|
@ -301,8 +301,8 @@ PSA_TEST_SERVER(msg_read_truncation)
|
||||||
|
|
||||||
PSA_TEST_SERVER(skip_zero)
|
PSA_TEST_SERVER(skip_zero)
|
||||||
{
|
{
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
psa_error_t disconnect_status = PSA_SUCCESS;
|
psa_status_t disconnect_status = PSA_SUCCESS;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
uint32_t signals = 0;
|
uint32_t signals = 0;
|
||||||
size_t read_size = 0;
|
size_t read_size = 0;
|
||||||
|
@ -347,8 +347,8 @@ PSA_TEST_SERVER(skip_zero)
|
||||||
|
|
||||||
PSA_TEST_SERVER(skip_some)
|
PSA_TEST_SERVER(skip_some)
|
||||||
{
|
{
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
psa_error_t disconnect_status = PSA_SUCCESS;
|
psa_status_t disconnect_status = PSA_SUCCESS;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
uint32_t signals = 0;
|
uint32_t signals = 0;
|
||||||
size_t read_size1 = 0;
|
size_t read_size1 = 0;
|
||||||
|
@ -396,8 +396,8 @@ PSA_TEST_SERVER(skip_some)
|
||||||
|
|
||||||
PSA_TEST_SERVER(skip_more_than_left)
|
PSA_TEST_SERVER(skip_more_than_left)
|
||||||
{
|
{
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
psa_error_t disconnect_status = PSA_SUCCESS;
|
psa_status_t disconnect_status = PSA_SUCCESS;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
uint32_t signals = 0;
|
uint32_t signals = 0;
|
||||||
size_t read_size1 = 0;
|
size_t read_size1 = 0;
|
||||||
|
@ -537,9 +537,9 @@ PSA_TEST_SERVER(cross_partition_call)
|
||||||
{
|
{
|
||||||
uint32_t signals = 0;
|
uint32_t signals = 0;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
psa_error_t disconnect_status = PSA_SUCCESS;
|
psa_status_t disconnect_status = PSA_SUCCESS;
|
||||||
psa_error_t partition_call_status = PSA_SUCCESS;
|
psa_status_t partition_call_status = PSA_SUCCESS;
|
||||||
uint32_t data_read = 0;
|
uint32_t data_read = 0;
|
||||||
uint32_t str_len = 0;
|
uint32_t str_len = 0;
|
||||||
char *buff = malloc(sizeof(char) * 60);
|
char *buff = malloc(sizeof(char) * 60);
|
||||||
|
@ -575,9 +575,9 @@ PSA_TEST_SERVER(cross_partition_call)
|
||||||
memcpy(buff + str_len, buff, str_len);
|
memcpy(buff + str_len, buff, str_len);
|
||||||
data_read *= 2;
|
data_read *= 2;
|
||||||
|
|
||||||
psa_invec_t data = { buff, data_read };
|
psa_invec data = { buff, data_read };
|
||||||
|
|
||||||
psa_outvec_t resp = { buff, data_read };
|
psa_outvec resp = { buff, data_read };
|
||||||
psa_handle_t conn_handle = psa_connect(ROT_SRV_REVERSE, 5);
|
psa_handle_t conn_handle = psa_connect(ROT_SRV_REVERSE, 5);
|
||||||
if (conn_handle <= 0) {
|
if (conn_handle <= 0) {
|
||||||
partition_call_status = PSA_TEST_ERROR;
|
partition_call_status = PSA_TEST_ERROR;
|
||||||
|
@ -608,9 +608,9 @@ PSA_TEST_SERVER(doorbell_test)
|
||||||
{
|
{
|
||||||
uint32_t signals = 0;
|
uint32_t signals = 0;
|
||||||
psa_msg_t msg = {0};
|
psa_msg_t msg = {0};
|
||||||
psa_error_t test_status = PSA_SUCCESS;
|
psa_status_t test_status = PSA_SUCCESS;
|
||||||
psa_error_t disconnect_status = PSA_SUCCESS;
|
psa_status_t disconnect_status = PSA_SUCCESS;
|
||||||
psa_error_t partition_call_status = PSA_SUCCESS;
|
psa_status_t partition_call_status = PSA_SUCCESS;
|
||||||
|
|
||||||
|
|
||||||
test_status = process_connect_request();
|
test_status = process_connect_request();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,13 +28,13 @@ typedef struct factorial_data {
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
} factorial_data_t;
|
} factorial_data_t;
|
||||||
|
|
||||||
typedef psa_error_t (*psa_test_server_side_func)(psa_error_t *);
|
typedef psa_status_t (*psa_test_server_side_func)(psa_status_t *);
|
||||||
#define PSA_TEST_ERROR (-1L)
|
#define PSA_TEST_ERROR (-1L)
|
||||||
#define PSA_TEST_CLIENT_NAME(name) psa_test_client_side_ ## name
|
#define PSA_TEST_CLIENT_NAME(name) psa_test_client_side_ ## name
|
||||||
#define PSA_TEST_SERVER_NAME(name) psa_test_server_side_ ## name
|
#define PSA_TEST_SERVER_NAME(name) psa_test_server_side_ ## name
|
||||||
|
|
||||||
#define PSA_TEST_CLIENT(name) void PSA_TEST_CLIENT_NAME(name) (void)
|
#define PSA_TEST_CLIENT(name) void PSA_TEST_CLIENT_NAME(name) (void)
|
||||||
#define PSA_TEST_SERVER(name) psa_error_t PSA_TEST_SERVER_NAME(name) (psa_error_t* status_ptr)
|
#define PSA_TEST_SERVER(name) psa_status_t PSA_TEST_SERVER_NAME(name) (psa_status_t *status_ptr)
|
||||||
|
|
||||||
#define PSA_TEST(name) \
|
#define PSA_TEST(name) \
|
||||||
PSA_TEST_CLIENT(name); \
|
PSA_TEST_CLIENT(name); \
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "greentea-client/test_env.h"
|
#include "greentea-client/test_env.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "utest.h"
|
#include "utest.h"
|
||||||
#include "spm_client.h"
|
#include "psa/client.h"
|
||||||
#include "psa_smoke_test_part1_ifs.h"
|
#include "psa_smoke_test_part1_ifs.h"
|
||||||
|
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
@ -47,7 +47,7 @@ void example_main(void)
|
||||||
TEST_ASSERT_MESSAGE(conn_handle > 0, "psa_connect() failed");
|
TEST_ASSERT_MESSAGE(conn_handle > 0, "psa_connect() failed");
|
||||||
|
|
||||||
|
|
||||||
psa_invec_t iovec[PSA_MAX_IOVEC - 1] = {
|
psa_invec iovec[PSA_MAX_IOVEC - 1] = {
|
||||||
{ msg_buf, 6 },
|
{ msg_buf, 6 },
|
||||||
{ msg_buf + 6, 12 },
|
{ msg_buf + 6, 12 },
|
||||||
{ msg_buf + 18, 4 }
|
{ msg_buf + 18, 4 }
|
||||||
|
@ -55,9 +55,9 @@ void example_main(void)
|
||||||
|
|
||||||
uint8_t *response_buf = (uint8_t *)malloc(sizeof(uint8_t) * CLIENT_RSP_BUF_SIZE);
|
uint8_t *response_buf = (uint8_t *)malloc(sizeof(uint8_t) * CLIENT_RSP_BUF_SIZE);
|
||||||
memset(response_buf, 0, CLIENT_RSP_BUF_SIZE);
|
memset(response_buf, 0, CLIENT_RSP_BUF_SIZE);
|
||||||
psa_outvec_t outvec = {response_buf, CLIENT_RSP_BUF_SIZE};
|
psa_outvec outvec = {response_buf, CLIENT_RSP_BUF_SIZE};
|
||||||
|
|
||||||
psa_error_t status = psa_call(conn_handle, iovec, PSA_MAX_IOVEC - 1, &outvec, 1);
|
psa_status_t status = psa_call(conn_handle, iovec, PSA_MAX_IOVEC - 1, &outvec, 1);
|
||||||
TEST_ASSERT_MESSAGE(PSA_SUCCESS == status, "psa_call() failed");
|
TEST_ASSERT_MESSAGE(PSA_SUCCESS == status, "psa_call() failed");
|
||||||
TEST_ASSERT_EQUAL_STRING(CLIENT_EXPECTED_RESPONSE, response_buf);
|
TEST_ASSERT_EQUAL_STRING(CLIENT_EXPECTED_RESPONSE, response_buf);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -99,3 +99,4 @@ void smoke_test_part1_init(spm_partition_t *partition)
|
||||||
SPM_PANIC("Failed to create start main thread of partition smoke_test_part1!\n");
|
SPM_PANIC("Failed to create start main thread of partition smoke_test_part1!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "cmsis_os2.h"
|
#include "cmsis_os2.h"
|
||||||
#include "spm_server.h"
|
#include "psa/service.h"
|
||||||
#include "spm_panic.h"
|
#include "spm_panic.h"
|
||||||
#include "psa_smoke_test_part1_partition.h"
|
#include "psa_smoke_test_part1_partition.h"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -29,11 +29,12 @@
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "psa_smoke_test_part1_partition.h"
|
#include "psa_smoke_test_part1_partition.h"
|
||||||
#include "psa_crypto_srv_partition.h"
|
#include "psa_crypto_srv_partition.h"
|
||||||
|
#include "psa_platform_partition.h"
|
||||||
#include "psa_its_partition.h"
|
#include "psa_its_partition.h"
|
||||||
|
|
||||||
extern const uint32_t crypto_srv_external_sids[4];
|
extern const uint32_t crypto_srv_external_sids[4];
|
||||||
|
|
||||||
spm_partition_t g_partitions[3] = {
|
spm_partition_t g_partitions[4] = {
|
||||||
{
|
{
|
||||||
.partition_id = SMOKE_TEST_PART1_ID,
|
.partition_id = SMOKE_TEST_PART1_ID,
|
||||||
.thread_id = 0,
|
.thread_id = 0,
|
||||||
|
@ -56,6 +57,17 @@ spm_partition_t g_partitions[3] = {
|
||||||
.extern_sids_count = CRYPTO_SRV_EXT_ROT_SRV_COUNT,
|
.extern_sids_count = CRYPTO_SRV_EXT_ROT_SRV_COUNT,
|
||||||
.irq_mapper = NULL,
|
.irq_mapper = NULL,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.partition_id = PLATFORM_ID,
|
||||||
|
.thread_id = 0,
|
||||||
|
.flags_rot_srv = PLATFORM_WAIT_ANY_SID_MSK,
|
||||||
|
.flags_interrupts = 0,
|
||||||
|
.rot_services = NULL,
|
||||||
|
.rot_services_count = PLATFORM_ROT_SRV_COUNT,
|
||||||
|
.extern_sids = NULL,
|
||||||
|
.extern_sids_count = PLATFORM_EXT_ROT_SRV_COUNT,
|
||||||
|
.irq_mapper = NULL,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.partition_id = ITS_ID,
|
.partition_id = ITS_ID,
|
||||||
.thread_id = 0,
|
.thread_id = 0,
|
||||||
|
@ -79,6 +91,7 @@ const uint32_t mem_region_count = 0;
|
||||||
// forward declaration of partition initializers
|
// forward declaration of partition initializers
|
||||||
void smoke_test_part1_init(spm_partition_t *partition);
|
void smoke_test_part1_init(spm_partition_t *partition);
|
||||||
void crypto_srv_init(spm_partition_t *partition);
|
void crypto_srv_init(spm_partition_t *partition);
|
||||||
|
void platform_init(spm_partition_t *partition);
|
||||||
void its_init(spm_partition_t *partition);
|
void its_init(spm_partition_t *partition);
|
||||||
|
|
||||||
uint32_t init_partitions(spm_partition_t **partitions)
|
uint32_t init_partitions(spm_partition_t **partitions)
|
||||||
|
@ -89,9 +102,10 @@ uint32_t init_partitions(spm_partition_t **partitions)
|
||||||
|
|
||||||
smoke_test_part1_init(&(g_partitions[0]));
|
smoke_test_part1_init(&(g_partitions[0]));
|
||||||
crypto_srv_init(&(g_partitions[1]));
|
crypto_srv_init(&(g_partitions[1]));
|
||||||
its_init(&(g_partitions[2]));
|
platform_init(&(g_partitions[2]));
|
||||||
|
its_init(&(g_partitions[3]));
|
||||||
|
|
||||||
*partitions = g_partitions;
|
*partitions = g_partitions;
|
||||||
return 3;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -27,24 +27,14 @@
|
||||||
#include "spm_internal.h"
|
#include "spm_internal.h"
|
||||||
#include "handles_manager.h"
|
#include "handles_manager.h"
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "psa_test_its_reset_partition.h"
|
|
||||||
#include "psa_crypto_srv_partition.h"
|
#include "psa_crypto_srv_partition.h"
|
||||||
|
#include "psa_platform_partition.h"
|
||||||
#include "psa_its_partition.h"
|
#include "psa_its_partition.h"
|
||||||
|
|
||||||
extern const uint32_t crypto_srv_external_sids[4];
|
extern const uint32_t crypto_srv_external_sids[4];
|
||||||
|
|
||||||
|
__attribute__((weak))
|
||||||
spm_partition_t g_partitions[3] = {
|
spm_partition_t g_partitions[3] = {
|
||||||
{
|
|
||||||
.partition_id = TEST_ITS_RESET_ID,
|
|
||||||
.thread_id = 0,
|
|
||||||
.flags_rot_srv = TEST_ITS_RESET_WAIT_ANY_SID_MSK,
|
|
||||||
.flags_interrupts = 0,
|
|
||||||
.rot_services = NULL,
|
|
||||||
.rot_services_count = TEST_ITS_RESET_ROT_SRV_COUNT,
|
|
||||||
.extern_sids = NULL,
|
|
||||||
.extern_sids_count = TEST_ITS_RESET_EXT_ROT_SRV_COUNT,
|
|
||||||
.irq_mapper = NULL,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
.partition_id = CRYPTO_SRV_ID,
|
.partition_id = CRYPTO_SRV_ID,
|
||||||
.thread_id = 0,
|
.thread_id = 0,
|
||||||
|
@ -56,6 +46,17 @@ spm_partition_t g_partitions[3] = {
|
||||||
.extern_sids_count = CRYPTO_SRV_EXT_ROT_SRV_COUNT,
|
.extern_sids_count = CRYPTO_SRV_EXT_ROT_SRV_COUNT,
|
||||||
.irq_mapper = NULL,
|
.irq_mapper = NULL,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.partition_id = PLATFORM_ID,
|
||||||
|
.thread_id = 0,
|
||||||
|
.flags_rot_srv = PLATFORM_WAIT_ANY_SID_MSK,
|
||||||
|
.flags_interrupts = 0,
|
||||||
|
.rot_services = NULL,
|
||||||
|
.rot_services_count = PLATFORM_ROT_SRV_COUNT,
|
||||||
|
.extern_sids = NULL,
|
||||||
|
.extern_sids_count = PLATFORM_EXT_ROT_SRV_COUNT,
|
||||||
|
.irq_mapper = NULL,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.partition_id = ITS_ID,
|
.partition_id = ITS_ID,
|
||||||
.thread_id = 0,
|
.thread_id = 0,
|
||||||
|
@ -72,23 +73,26 @@ spm_partition_t g_partitions[3] = {
|
||||||
/* Check all the defined memory regions for overlapping. */
|
/* Check all the defined memory regions for overlapping. */
|
||||||
|
|
||||||
/* A list of all the memory regions. */
|
/* A list of all the memory regions. */
|
||||||
|
__attribute__((weak))
|
||||||
const mem_region_t *mem_regions = NULL;
|
const mem_region_t *mem_regions = NULL;
|
||||||
|
|
||||||
|
__attribute__((weak))
|
||||||
const uint32_t mem_region_count = 0;
|
const uint32_t mem_region_count = 0;
|
||||||
|
|
||||||
// forward declaration of partition initializers
|
// forward declaration of partition initializers
|
||||||
void test_its_reset_init(spm_partition_t *partition);
|
|
||||||
void crypto_srv_init(spm_partition_t *partition);
|
void crypto_srv_init(spm_partition_t *partition);
|
||||||
|
void platform_init(spm_partition_t *partition);
|
||||||
void its_init(spm_partition_t *partition);
|
void its_init(spm_partition_t *partition);
|
||||||
|
|
||||||
|
__attribute__((weak))
|
||||||
uint32_t init_partitions(spm_partition_t **partitions)
|
uint32_t init_partitions(spm_partition_t **partitions)
|
||||||
{
|
{
|
||||||
if (NULL == partitions) {
|
if (NULL == partitions) {
|
||||||
SPM_PANIC("partitions is NULL!\n");
|
SPM_PANIC("partitions is NULL!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
test_its_reset_init(&(g_partitions[0]));
|
crypto_srv_init(&(g_partitions[0]));
|
||||||
crypto_srv_init(&(g_partitions[1]));
|
platform_init(&(g_partitions[1]));
|
||||||
its_init(&(g_partitions[2]));
|
its_init(&(g_partitions[2]));
|
||||||
|
|
||||||
*partitions = g_partitions;
|
*partitions = g_partitions;
|
|
@ -145,7 +145,7 @@ void psa_connect_async(uint32_t sid, spm_pending_connect_msg_t *msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the handle in the user message so we could destroy it in case of failure.
|
// Create the handle in the user message so we could destroy it in case of failure.
|
||||||
msg->rc = (psa_error_t)create_channel_handle(channel, dst_rot_service->partition->partition_id);
|
msg->rc = (psa_status_t)create_channel_handle(channel, dst_rot_service->partition->partition_id);
|
||||||
|
|
||||||
// NOTE: all struct fields must be initialized as the allocated memory is not zeroed.
|
// NOTE: all struct fields must be initialized as the allocated memory is not zeroed.
|
||||||
channel->state = SPM_CHANNEL_STATE_CONNECTING;
|
channel->state = SPM_CHANNEL_STATE_CONNECTING;
|
||||||
|
@ -230,11 +230,11 @@ void psa_call_async(psa_handle_t handle, spm_pending_call_msg_t *msg)
|
||||||
spm_rot_service_queue_enqueue(channel->dst_rot_service, channel);
|
spm_rot_service_queue_enqueue(channel->dst_rot_service, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_error_t psa_call(
|
psa_status_t psa_call(
|
||||||
psa_handle_t handle,
|
psa_handle_t handle,
|
||||||
const psa_invec_t *in_vec,
|
const psa_invec *in_vec,
|
||||||
size_t in_len,
|
size_t in_len,
|
||||||
const psa_outvec_t *out_vec,
|
const psa_outvec *out_vec,
|
||||||
size_t out_len
|
size_t out_len
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -272,7 +272,7 @@ psa_error_t psa_call(
|
||||||
|
|
||||||
PSA_UNUSED(os_status);
|
PSA_UNUSED(os_status);
|
||||||
|
|
||||||
return (psa_error_t)msg.rc;
|
return (psa_status_t)msg.rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void psa_close_async(psa_handle_t handle, spm_pending_close_msg_t *msg)
|
void psa_close_async(psa_handle_t handle, spm_pending_close_msg_t *msg)
|
|
@ -72,8 +72,8 @@ typedef struct mem_region {
|
||||||
} mem_region_t;
|
} mem_region_t;
|
||||||
|
|
||||||
typedef union spm_iovec {
|
typedef union spm_iovec {
|
||||||
psa_invec_t in;
|
psa_invec in;
|
||||||
psa_outvec_t out;
|
psa_outvec out;
|
||||||
} spm_iovec_t;
|
} spm_iovec_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -215,9 +215,9 @@ void psa_close_async(psa_handle_t handle, spm_pending_close_msg_t *msg);
|
||||||
/*
|
/*
|
||||||
* Validates IOvecs.
|
* Validates IOvecs.
|
||||||
*
|
*
|
||||||
* @param[in] in_vec - psa_invec_t array
|
* @param[in] in_vec - psa_invec array
|
||||||
* @param[in] in_len - number of elements in in_vec
|
* @param[in] in_len - number of elements in in_vec
|
||||||
* @param[in] out_vec - psa_outvec_t array
|
* @param[in] out_vec - psa_outvec array
|
||||||
* @param[in] out_len - number of elements in out_vec
|
* @param[in] out_len - number of elements in out_vec
|
||||||
*/
|
*/
|
||||||
void validate_iovec(
|
void validate_iovec(
|
|
@ -94,9 +94,9 @@ static void copy_message_to_spm(spm_ipc_channel_t *channel, psa_msg_t *user_msg)
|
||||||
spm_pending_call_msg_t *call_msg_data = (spm_pending_call_msg_t *)channel->msg_ptr;
|
spm_pending_call_msg_t *call_msg_data = (spm_pending_call_msg_t *)channel->msg_ptr;
|
||||||
|
|
||||||
// Copy pointers and sizes to secure memory to prevent TOCTOU
|
// Copy pointers and sizes to secure memory to prevent TOCTOU
|
||||||
const psa_invec_t *temp_invec = call_msg_data->in_vec;
|
const psa_invec *temp_invec = call_msg_data->in_vec;
|
||||||
const uint32_t temp_invec_size = call_msg_data->in_vec_size;
|
const uint32_t temp_invec_size = call_msg_data->in_vec_size;
|
||||||
const psa_outvec_t *temp_outvec = call_msg_data->out_vec;
|
const psa_outvec *temp_outvec = call_msg_data->out_vec;
|
||||||
const uint32_t temp_outvec_size = call_msg_data->out_vec_size;
|
const uint32_t temp_outvec_size = call_msg_data->out_vec_size;
|
||||||
|
|
||||||
validate_iovec(temp_invec, temp_invec_size, temp_outvec, temp_outvec_size);
|
validate_iovec(temp_invec, temp_invec_size, temp_outvec, temp_outvec_size);
|
||||||
|
@ -320,7 +320,7 @@ static size_t read_or_skip(psa_handle_t msg_handle, uint32_t invec_idx, void *bu
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_invec_t *active_iovec = &active_msg->iovecs[invec_idx].in;
|
psa_invec *active_iovec = &active_msg->iovecs[invec_idx].in;
|
||||||
|
|
||||||
if (num_bytes > active_iovec->len) {
|
if (num_bytes > active_iovec->len) {
|
||||||
num_bytes = active_iovec->len;
|
num_bytes = active_iovec->len;
|
||||||
|
@ -376,7 +376,7 @@ void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx, const void *buffer,
|
||||||
SPM_PANIC("Invalid outvec_idx\n");
|
SPM_PANIC("Invalid outvec_idx\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_outvec_t *active_iovec = &active_msg->iovecs[outvec_idx].out;
|
psa_outvec *active_iovec = &active_msg->iovecs[outvec_idx].out;
|
||||||
if (num_bytes > active_iovec->len) {
|
if (num_bytes > active_iovec->len) {
|
||||||
SPM_PANIC("Invalid write operation (Requested %d, Avialable %d)\n", num_bytes, active_iovec->len);
|
SPM_PANIC("Invalid write operation (Requested %d, Avialable %d)\n", num_bytes, active_iovec->len);
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx, const void *buffer,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void psa_reply(psa_handle_t msg_handle, psa_error_t status)
|
void psa_reply(psa_handle_t msg_handle, psa_status_t status)
|
||||||
{
|
{
|
||||||
spm_active_msg_t *active_msg = get_msg_from_handle(msg_handle);
|
spm_active_msg_t *active_msg = get_msg_from_handle(msg_handle);
|
||||||
spm_ipc_channel_t *active_channel = active_msg->channel;
|
spm_ipc_channel_t *active_channel = active_msg->channel;
|
||||||
|
@ -411,7 +411,7 @@ void psa_reply(psa_handle_t msg_handle, psa_error_t status)
|
||||||
bool nspe_call = (active_channel->src_partition == NULL);
|
bool nspe_call = (active_channel->src_partition == NULL);
|
||||||
switch (active_channel->msg_type) {
|
switch (active_channel->msg_type) {
|
||||||
case PSA_IPC_CONNECT: {
|
case PSA_IPC_CONNECT: {
|
||||||
if ((status != PSA_CONNECTION_ACCEPTED) && (status != PSA_CONNECTION_REFUSED)) {
|
if ((status != PSA_SUCCESS) && (status != PSA_CONNECTION_REFUSED)) {
|
||||||
SPM_PANIC("status (0X%08x) is not allowed for PSA_IPC_CONNECT", status);
|
SPM_PANIC("status (0X%08x) is not allowed for PSA_IPC_CONNECT", status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx, const void *buffer,
|
||||||
* @param[in] msg_handle Handle for the client's message.
|
* @param[in] msg_handle Handle for the client's message.
|
||||||
* @param[in] status Message result value to be reported to the client.
|
* @param[in] status Message result value to be reported to the client.
|
||||||
*/
|
*/
|
||||||
void psa_reply(psa_handle_t msg_handle, psa_error_t status);
|
void psa_reply(psa_handle_t msg_handle, psa_status_t status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a doorbell signal to a specific partition that is listening for that signal type.
|
* Send a doorbell signal to a specific partition that is listening for that signal type.
|
|
@ -121,12 +121,12 @@ psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version)
|
||||||
return (psa_handle_t)(msg.rc);
|
return (psa_handle_t)(msg.rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_error_t psa_call(psa_handle_t handle,
|
psa_status_t psa_call(psa_handle_t handle,
|
||||||
const psa_invec_t *in_vec,
|
const psa_invec *in_vec,
|
||||||
size_t in_len,
|
size_t in_len,
|
||||||
const psa_outvec_t *out_vec,
|
const psa_outvec *out_vec,
|
||||||
size_t out_len
|
size_t out_len
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// - Immediate errors are checked here.
|
// - Immediate errors are checked here.
|
||||||
// - Other errors are checked on the SPM core code
|
// - Other errors are checked on the SPM core code
|
|
@ -50,7 +50,7 @@ extern "C" {
|
||||||
|
|
||||||
#define PSA_NULL_HANDLE ((psa_handle_t)0) /**< Denotes an invalid handle.*/
|
#define PSA_NULL_HANDLE ((psa_handle_t)0) /**< Denotes an invalid handle.*/
|
||||||
|
|
||||||
#define PSA_MAX_IOVEC (4UL) /**< Maximum number of psa_invec_t and psa_outvec_t structures allowed for psa_call().*/
|
#define PSA_MAX_IOVEC (4UL) /**< Maximum number of psa_invec and psa_outvec structures allowed for psa_call().*/
|
||||||
|
|
||||||
#define PSA_POLL (0x00000000UL) /**< Returns immediately even if none of the requested signals is asserted.*/
|
#define PSA_POLL (0x00000000UL) /**< Returns immediately even if none of the requested signals is asserted.*/
|
||||||
#define PSA_BLOCK (0x80000000UL) /**< Block the caller until one of the requested signals is asserted.*/
|
#define PSA_BLOCK (0x80000000UL) /**< Block the caller until one of the requested signals is asserted.*/
|
||||||
|
@ -61,7 +61,6 @@ extern "C" {
|
||||||
#define PSA_DOORBELL (0x00000008UL) /**< Mask for PSA_DOORBELL signal.*/
|
#define PSA_DOORBELL (0x00000008UL) /**< Mask for PSA_DOORBELL signal.*/
|
||||||
|
|
||||||
#define PSA_SUCCESS (0L) /**< A general result code for calls to psa_call() indicating success.*/
|
#define PSA_SUCCESS (0L) /**< A general result code for calls to psa_call() indicating success.*/
|
||||||
#define PSA_CONNECTION_ACCEPTED (0L) /**< The result code for calls to psa_connect() indicating the acceptance of a new connection request.*/
|
|
||||||
#define PSA_IPC_CONNECT (1) /**< The IPC message type that indicates a new connection.*/
|
#define PSA_IPC_CONNECT (1) /**< The IPC message type that indicates a new connection.*/
|
||||||
#define PSA_IPC_CALL (2) /**< The IPC message type that indicates a client request.*/
|
#define PSA_IPC_CALL (2) /**< The IPC message type that indicates a client request.*/
|
||||||
#define PSA_IPC_DISCONNECT (3) /**< The IPC message type that indicates the end of a connection.*/
|
#define PSA_IPC_DISCONNECT (3) /**< The IPC message type that indicates the end of a connection.*/
|
||||||
|
@ -69,16 +68,16 @@ extern "C" {
|
||||||
|
|
||||||
/* Error codes */
|
/* Error codes */
|
||||||
#define PSA_DROP_CONNECTION (INT32_MIN) /**< The result code in a call to psa_reply() to indicate a nonrecoverable error in the client.*/
|
#define PSA_DROP_CONNECTION (INT32_MIN) /**< The result code in a call to psa_reply() to indicate a nonrecoverable error in the client.*/
|
||||||
#define PSA_CONNECTION_REFUSED (INT32_MIN + 1) /**< The return value from psa_connect() if the RoT Service or SPM was unable to establish a connection.*/
|
#define PSA_CONNECTION_REFUSED (INT32_MIN + 1) /**< The return value from psa_connect() if the RoT Service or SPM was unable to establish a connection.*/
|
||||||
|
#define PSA_CONNECTION_BUSY (INT32_MIN + 2) /**< The return value from psa_connect() if the RoT Service rejects the connection for a transient reason.*/
|
||||||
#define PSA_UNUSED(var) ((void)(var))
|
#define PSA_UNUSED(var) ((void)(var))
|
||||||
|
|
||||||
/* -------------------------------------- Typedefs ----------------------------------- */
|
/* -------------------------------------- Typedefs ----------------------------------- */
|
||||||
|
|
||||||
typedef uint32_t psa_signal_t;
|
typedef uint32_t psa_signal_t;
|
||||||
typedef int32_t psa_error_t;
|
typedef int32_t psa_status_t;
|
||||||
typedef int32_t psa_handle_t;
|
typedef int32_t psa_handle_t;
|
||||||
typedef psa_error_t error_t;
|
typedef psa_status_t error_t;
|
||||||
|
|
||||||
/* -------------------------------------- Structs ------------------------------------ */
|
/* -------------------------------------- Structs ------------------------------------ */
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ typedef struct psa_msg {
|
||||||
typedef struct psa_invec {
|
typedef struct psa_invec {
|
||||||
const void *base; /**< Starting address of the buffer.*/
|
const void *base; /**< Starting address of the buffer.*/
|
||||||
size_t len; /**< Length in bytes of the buffer.*/
|
size_t len; /**< Length in bytes of the buffer.*/
|
||||||
} psa_invec_t;
|
} psa_invec;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structure which describes a scatter-gather output buffer.
|
* Structure which describes a scatter-gather output buffer.
|
||||||
|
@ -107,7 +106,7 @@ typedef struct psa_invec {
|
||||||
typedef struct psa_outvec {
|
typedef struct psa_outvec {
|
||||||
void *base; /**< Starting address of the buffer.*/
|
void *base; /**< Starting address of the buffer.*/
|
||||||
size_t len; /**< Length in bytes of the buffer.*/
|
size_t len; /**< Length in bytes of the buffer.*/
|
||||||
} psa_outvec_t;
|
} psa_outvec;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
|
@ -73,23 +73,23 @@ psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call a connected Root of Trust Service.@n
|
* Call a connected Root of Trust Service.@n
|
||||||
* The caller must provide an array of ::psa_invec_t structures as the input payload.
|
* The caller must provide an array of ::psa_invec structures as the input payload.
|
||||||
*
|
*
|
||||||
* @param[in] handle Handle for the connection.
|
* @param[in] handle Handle for the connection.
|
||||||
* @param[in] in_vec Array of ::psa_invec_t structures.
|
* @param[in] in_vec Array of ::psa_invec structures.
|
||||||
* @param[in] in_len Number of ::psa_invec_t structures in in_vec. (At most ::PSA_MAX_IOVEC - out_len)
|
* @param[in] in_len Number of ::psa_invec structures in in_vec. (At most ::PSA_MAX_IOVEC - out_len)
|
||||||
* @param[out] out_vec Array of ::psa_outvec_t structures for optional Root of Trust Service response.
|
* @param[out] out_vec Array of ::psa_outvec structures for optional Root of Trust Service response.
|
||||||
* @param[in] out_len Number of ::psa_outvec_t structures in out_vec. (At most ::PSA_MAX_IOVEC - in_len)
|
* @param[in] out_len Number of ::psa_outvec structures in out_vec. (At most ::PSA_MAX_IOVEC - in_len)
|
||||||
* @return 0 for success or@n
|
* @return 0 for success or@n
|
||||||
* @a positive numbers for application-specific return code.
|
* @a positive numbers for application-specific return code.
|
||||||
* @a negative numbers for application-specific error code.
|
* @a negative numbers for application-specific error code.
|
||||||
* @a PSA_DROP_CONNECTION if the connection has been dropped by the RoT Service.
|
* @a PSA_DROP_CONNECTION if the connection has been dropped by the RoT Service.
|
||||||
*/
|
*/
|
||||||
psa_error_t psa_call(
|
psa_status_t psa_call(
|
||||||
psa_handle_t handle,
|
psa_handle_t handle,
|
||||||
const psa_invec_t *in_vec,
|
const psa_invec *in_vec,
|
||||||
size_t in_len,
|
size_t in_len,
|
||||||
const psa_outvec_t *out_vec,
|
const psa_outvec *out_vec,
|
||||||
size_t out_len
|
size_t out_len
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,11 +29,11 @@
|
||||||
* Structure containing data sent from NSPE for ROT_SRV call.
|
* Structure containing data sent from NSPE for ROT_SRV call.
|
||||||
*/
|
*/
|
||||||
typedef __PACKED_STRUCT spm_pending_call_msg {
|
typedef __PACKED_STRUCT spm_pending_call_msg {
|
||||||
const psa_invec_t *in_vec; /* Invecs sent.*/
|
const psa_invec *in_vec; /* Invecs sent.*/
|
||||||
uint32_t in_vec_size; /* Number of Invecs sent.*/
|
uint32_t in_vec_size; /* Number of Invecs sent.*/
|
||||||
const psa_outvec_t *out_vec; /* Outvecs for response.*/
|
const psa_outvec *out_vec; /* Outvecs for response.*/
|
||||||
uint32_t out_vec_size; /* Number of Outvecs for response.*/
|
uint32_t out_vec_size; /* Number of Outvecs for response.*/
|
||||||
psa_error_t rc; /* Return code to be filled by the Root of Trust Service.*/
|
psa_status_t rc; /* Return code to be filled by the Root of Trust Service.*/
|
||||||
osSemaphoreId_t completion_sem_id; /* Semaphore to be released at the end of execution */
|
osSemaphoreId_t completion_sem_id; /* Semaphore to be released at the end of execution */
|
||||||
} __ALIGNED(4) spm_pending_call_msg_t;
|
} __ALIGNED(4) spm_pending_call_msg_t;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ typedef __PACKED_STRUCT spm_pending_call_msg {
|
||||||
*/
|
*/
|
||||||
typedef __PACKED_STRUCT spm_pending_connect_msg {
|
typedef __PACKED_STRUCT spm_pending_connect_msg {
|
||||||
uint32_t min_version; /* Minor version of the Root of Trust Service interface.*/
|
uint32_t min_version; /* Minor version of the Root of Trust Service interface.*/
|
||||||
psa_error_t rc; /* Return code to be filled by the Root of Trust Service.*/
|
psa_status_t rc; /* Return code to be filled by the Root of Trust Service.*/
|
||||||
osSemaphoreId_t completion_sem_id; /* Semaphore to be released at the end of execution */
|
osSemaphoreId_t completion_sem_id; /* Semaphore to be released at the end of execution */
|
||||||
} __ALIGNED(4) spm_pending_connect_msg_t;
|
} __ALIGNED(4) spm_pending_connect_msg_t;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2018 ARM Limited
|
/* Copyright (c) 2017-2018 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -15,20 +15,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __PITS_IMPL_H__
|
#if defined(TARGET_TFM)
|
||||||
#define __PITS_IMPL_H__
|
#include "interface/include/psa_client.h"
|
||||||
|
#else
|
||||||
#include "psa_prot_internal_storage.h"
|
#include "TARGET_MBED_SPM/psa_defs.h"
|
||||||
|
#include "TARGET_MBED_SPM/spm_client.h"
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
psa_its_status_t test_psa_its_reset_impl(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __PITS_IMPL_H__
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2018 ARM Limited
|
/* Copyright (c) 2017-2018 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -15,20 +15,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __PITS_IMPL_H__
|
#ifndef __MBED_INTERNAL_TRUSTED_STORAGE_H__
|
||||||
#define __PITS_IMPL_H__
|
#define __MBED_INTERNAL_TRUSTED_STORAGE_H__
|
||||||
|
|
||||||
#include "psa_prot_internal_storage.h"
|
#include "psa_prot_internal_storage.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#endif // __MBED_INTERNAL_TRUSTED_STORAGE_H__
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
psa_its_status_t test_psa_its_reset_impl(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __PITS_IMPL_H__
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
/* Copyright (c) 2018 ARM Limited
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LIFECYCLE_H__
|
||||||
|
#define __LIFECYCLE_H__
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
@brief This file describes the PSA RoT Lifecycle API
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int32_t psa_status_t;
|
||||||
|
|
||||||
|
#define PSA_LIFECYCLE_STATE_MASK (0xff00u) /**< A mask value that extracts the main lifecycle state */
|
||||||
|
#define PSA_LIFECYCLE_SUBSTATE_MASK (0x00ffu) /**< A mask value that extracts the IMPLEMENTATION DEFINED lifecycle sub-state */
|
||||||
|
|
||||||
|
#define PSA_LIFECYCLE_UNKNOWN (0x0000u) /**< State is unknown */
|
||||||
|
#define PSA_LIFECYCLE_ASSEMBLY_AND_TEST (0x1000u) /**< Assembly and Test state */
|
||||||
|
#define PSA_LIFECYCLE_PSA_ROT_PROVISIONING (0x2000u) /**< PSA RoT Provisioning state */
|
||||||
|
#define PSA_LIFECYCLE_SECURED (0x3000u) /**< Secured state */
|
||||||
|
#define PSA_LIFECYCLE_NON_PSA_ROT_DEBUG (0x4000u) /**< Non PSA RoT debug state */
|
||||||
|
#define PSA_LIFECYCLE_RECOVERABLE_PSA_ROT_DEBUG (0x5000u) /**< Recoverable PSA RoT Debug state */
|
||||||
|
#define PSA_LIFECYCLE_DECOMMISSIONED (0x6000u) /**< Decommissioned state */
|
||||||
|
|
||||||
|
#define PSA_LIFECYCLE_SUCCESS 0
|
||||||
|
#define PSA_LIFECYCLE_ERROR (INT32_MIN + 1000)
|
||||||
|
|
||||||
|
/** \brief Get PSA RoT lifecycle state
|
||||||
|
*
|
||||||
|
* \retval The main state and sub-state are encoded as follows:@n
|
||||||
|
@a version[15:8] – main lifecycle state
|
||||||
|
@a version[7:0] – IMPLEMENTATION DEFINED sub-state
|
||||||
|
*/
|
||||||
|
uint32_t psa_security_lifecycle_state(void);
|
||||||
|
|
||||||
|
/** \brief Request state change
|
||||||
|
*
|
||||||
|
* State change requested and the system.
|
||||||
|
* TODO when not drunk
|
||||||
|
*/
|
||||||
|
psa_status_t mbed_psa_reboot_and_request_new_security_state(uint32_t new_state);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __LIFECYCLE_H__
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2018 ARM Limited
|
/* Copyright (c) 2017-2018 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -15,14 +15,10 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TARGET_PSA
|
#if defined(TARGET_TFM)
|
||||||
#error [NOT_SUPPORTED] ITS tests can run only on PSA-enabled targets.
|
#include "interface/include/psa_service.h"
|
||||||
#endif // TARGET_PSA
|
#else
|
||||||
|
#include "TARGET_MBED_SPM/psa_defs.h"
|
||||||
#include "test_pits.h"
|
#include "TARGET_MBED_SPM/COMPONENT_SPE/spm_server.h"
|
||||||
#include "test_pits_impl.h"
|
#include "TARGET_MBED_SPM/COMPONENT_SPE/spm_panic.h"
|
||||||
|
#endif
|
||||||
psa_its_status_t test_psa_its_reset(void)
|
|
||||||
{
|
|
||||||
return test_psa_its_reset_impl();
|
|
||||||
}
|
|
|
@ -42,23 +42,24 @@ typedef enum psa_sec_function_s {
|
||||||
PSA_CRYPTO_INVALID,
|
PSA_CRYPTO_INVALID,
|
||||||
PSA_CRYPTO_INIT,
|
PSA_CRYPTO_INIT,
|
||||||
PSA_IMPORT_KEY,
|
PSA_IMPORT_KEY,
|
||||||
|
PSA_ALLOCATE_KEY,
|
||||||
|
PSA_CREATE_KEY,
|
||||||
|
PSA_OPEN_KEY,
|
||||||
|
PSA_CLOSE_KEY,
|
||||||
PSA_DESTROY_KEY,
|
PSA_DESTROY_KEY,
|
||||||
PSA_GET_KEY_INFORMATION,
|
PSA_GET_KEY_INFORMATION,
|
||||||
PSA_EXPORT_KEY,
|
PSA_EXPORT_KEY,
|
||||||
PSA_EXPORT_PUBLIC_KEY,
|
PSA_EXPORT_PUBLIC_KEY,
|
||||||
PSA_KEY_POLICY_INIT,
|
|
||||||
PSA_KEY_POLICY_SET_USAGE,
|
|
||||||
PSA_KEY_POLICY_GET_USAGE,
|
|
||||||
PSA_KEY_POLICY_GET_ALGORITHM,
|
|
||||||
PSA_SET_KEY_POLICY,
|
PSA_SET_KEY_POLICY,
|
||||||
PSA_GET_KEY_POLICY,
|
PSA_GET_KEY_POLICY,
|
||||||
PSA_SET_KEY_LIFETIME,
|
|
||||||
PSA_GET_KEY_LIFETIME,
|
PSA_GET_KEY_LIFETIME,
|
||||||
PSA_HASH_SETUP,
|
PSA_HASH_SETUP,
|
||||||
PSA_HASH_UPDATE,
|
PSA_HASH_UPDATE,
|
||||||
PSA_HASH_FINISH,
|
PSA_HASH_FINISH,
|
||||||
PSA_HASH_VERIFY,
|
PSA_HASH_VERIFY,
|
||||||
PSA_HASH_ABORT,
|
PSA_HASH_ABORT,
|
||||||
|
PSA_HASH_CLONE_BEGIN,
|
||||||
|
PSA_HASH_CLONE_END,
|
||||||
PSA_MAC_SIGN_SETUP,
|
PSA_MAC_SIGN_SETUP,
|
||||||
PSA_MAC_VERIFY_SETUP,
|
PSA_MAC_VERIFY_SETUP,
|
||||||
PSA_MAC_UPDATE,
|
PSA_MAC_UPDATE,
|
||||||
|
@ -95,52 +96,50 @@ typedef enum psa_sec_function_s {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** psa_crypto_ipc_s struct used for some of the
|
/** psa_crypto_ipc_s struct used for some of the
|
||||||
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
|
* PSA Crypto APIs that need psa_key_handle_t and psa_algorithm_t arguments
|
||||||
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
|
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
|
||||||
* pack them together.
|
* pack them together.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct psa_crypto_ipc_s {
|
typedef struct psa_crypto_ipc_s {
|
||||||
psa_sec_function_t func;
|
psa_sec_function_t func;
|
||||||
psa_key_slot_t key;
|
psa_key_handle_t handle;
|
||||||
psa_algorithm_t alg;
|
psa_algorithm_t alg;
|
||||||
} psa_crypto_ipc_t;
|
} psa_crypto_ipc_t;
|
||||||
|
|
||||||
/** psa_crypto_derivation_ipc_s struct used for some of the
|
/** psa_crypto_derivation_ipc_s struct used for some of the
|
||||||
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
|
* PSA Crypto APIs that need psa_key_handle_t and psa_algorithm_t arguments
|
||||||
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
|
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
|
||||||
* pack them together.
|
* pack them together.
|
||||||
*/
|
*/
|
||||||
typedef struct psa_crypto_derivation_ipc_s {
|
typedef struct psa_crypto_derivation_ipc_s {
|
||||||
psa_sec_function_t func;
|
psa_sec_function_t func;
|
||||||
psa_key_slot_t key;
|
psa_key_handle_t handle;
|
||||||
psa_algorithm_t alg;
|
psa_algorithm_t alg;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
} psa_crypto_derivation_ipc_t;
|
} psa_crypto_derivation_ipc_t;
|
||||||
|
|
||||||
/** psa_key_mng_ipc_s struct used for some of the
|
/** psa_key_mng_ipc_s struct used for some of the
|
||||||
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
|
* PSA Crypto APIs that need psa_key_handle_t and psa_algorithm_t arguments
|
||||||
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
|
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
|
||||||
* pack them together.
|
* pack them together.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct psa_key_mng_ipc_s {
|
typedef struct psa_key_mng_ipc_s {
|
||||||
psa_key_slot_t key;
|
psa_key_handle_t handle;
|
||||||
|
psa_key_lifetime_t lifetime;
|
||||||
psa_key_type_t type;
|
psa_key_type_t type;
|
||||||
psa_sec_function_t func;
|
psa_sec_function_t func;
|
||||||
} psa_key_mng_ipc_t;
|
} psa_key_mng_ipc_t;
|
||||||
|
|
||||||
/** psa_crypto_ipc_aead_s struct used for AEAD integrated
|
/** psa_crypto_ipc_aead_s struct used for AEAD integrated
|
||||||
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t and extra arguments
|
* PSA Crypto APIs that need psa_key_handle_t and psa_algorithm_t and extra arguments
|
||||||
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
|
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
|
||||||
* pack them together.
|
* pack them together.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Max length supported for nonce is 16 bytes.
|
// Max length supported for nonce is 16 bytes.
|
||||||
#define PSA_AEAD_MAX_NONCE_SIZE 16
|
#define PSA_AEAD_MAX_NONCE_SIZE 16
|
||||||
typedef struct psa_crypto_ipc_aead_s {
|
typedef struct psa_crypto_ipc_aead_s {
|
||||||
psa_sec_function_t func;
|
psa_sec_function_t func;
|
||||||
psa_key_slot_t key;
|
psa_key_handle_t handle;
|
||||||
psa_algorithm_t alg;
|
psa_algorithm_t alg;
|
||||||
uint16_t nonce_size;
|
uint16_t nonce_size;
|
||||||
size_t additional_data_length;
|
size_t additional_data_length;
|
||||||
|
@ -149,19 +148,18 @@ typedef struct psa_crypto_ipc_aead_s {
|
||||||
} psa_crypto_ipc_aead_t;
|
} psa_crypto_ipc_aead_t;
|
||||||
|
|
||||||
/** psa_crypto_ipc_asymmetric_s struct used for asymmetric
|
/** psa_crypto_ipc_asymmetric_s struct used for asymmetric
|
||||||
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
|
* PSA Crypto APIs that need psa_key_handle_t and psa_algorithm_t arguments
|
||||||
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
|
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
|
||||||
* pack them together.
|
* pack them together.
|
||||||
*/
|
*/
|
||||||
typedef struct psa_crypto_ipc_asymmetric_s {
|
typedef struct psa_crypto_ipc_asymmetric_s {
|
||||||
psa_sec_function_t func;
|
psa_sec_function_t func;
|
||||||
psa_key_slot_t key;
|
psa_key_handle_t handle;
|
||||||
psa_algorithm_t alg;
|
psa_algorithm_t alg;
|
||||||
size_t input_length;
|
size_t input_length;
|
||||||
size_t salt_length;
|
size_t salt_length;
|
||||||
} psa_crypto_ipc_asymmetric_t;
|
} psa_crypto_ipc_asymmetric_t;
|
||||||
|
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_SPE_PLATFORM_H */
|
#endif /* PSA_CRYPTO_SPE_PLATFORM_H */
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#include "spm/psa_defs.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file psa/crypto_struct.h
|
* \file psa/crypto_struct.h
|
||||||
*
|
*
|
||||||
|
@ -27,21 +25,40 @@
|
||||||
#ifndef PSA_CRYPTO_STRUCT_H
|
#ifndef PSA_CRYPTO_STRUCT_H
|
||||||
#define PSA_CRYPTO_STRUCT_H
|
#define PSA_CRYPTO_STRUCT_H
|
||||||
|
|
||||||
|
#include "psa/client.h"
|
||||||
|
|
||||||
struct psa_hash_operation_s {
|
struct psa_hash_operation_s {
|
||||||
psa_handle_t handle;
|
psa_handle_t handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define PSA_HASH_OPERATION_INIT { PSA_NULL_HANDLE }
|
||||||
|
static inline struct psa_hash_operation_s psa_hash_operation_init(void)
|
||||||
|
{
|
||||||
|
const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT;
|
||||||
|
return (v);
|
||||||
|
}
|
||||||
|
|
||||||
struct psa_mac_operation_s {
|
struct psa_mac_operation_s {
|
||||||
psa_handle_t handle;
|
psa_handle_t handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define PSA_MAC_OPERATION_INIT { PSA_NULL_HANDLE }
|
||||||
|
static inline struct psa_mac_operation_s psa_mac_operation_init(void)
|
||||||
|
{
|
||||||
|
const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT;
|
||||||
|
return (v);
|
||||||
|
}
|
||||||
|
|
||||||
struct psa_cipher_operation_s {
|
struct psa_cipher_operation_s {
|
||||||
psa_handle_t handle;
|
psa_handle_t handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct psa_aead_operation_s {
|
#define PSA_CIPHER_OPERATION_INIT { PSA_NULL_HANDLE }
|
||||||
psa_handle_t handle;
|
static inline struct psa_cipher_operation_s psa_cipher_operation_init(void)
|
||||||
};
|
{
|
||||||
|
const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT;
|
||||||
|
return (v);
|
||||||
|
}
|
||||||
|
|
||||||
struct psa_crypto_generator_s {
|
struct psa_crypto_generator_s {
|
||||||
psa_handle_t handle;
|
psa_handle_t handle;
|
||||||
|
@ -59,5 +76,11 @@ struct psa_key_policy_s {
|
||||||
psa_algorithm_t alg;
|
psa_algorithm_t alg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define PSA_KEY_POLICY_INIT {0, 0}
|
||||||
|
static inline struct psa_key_policy_s psa_key_policy_init(void)
|
||||||
|
{
|
||||||
|
const struct psa_key_policy_s v = PSA_KEY_POLICY_INIT;
|
||||||
|
return (v);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_STRUCT_H */
|
#endif /* PSA_CRYPTO_STRUCT_H */
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -227,3 +227,4 @@ void crypto_srv_init(spm_partition_t *partition)
|
||||||
SPM_PANIC("Failed to create start main thread of partition crypto_srv!\n");
|
SPM_PANIC("Failed to create start main thread of partition crypto_srv!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ extern "C" {
|
||||||
#define psa_set_key_policy psa_sec_set_key_policy
|
#define psa_set_key_policy psa_sec_set_key_policy
|
||||||
#define psa_get_key_policy psa_sec_get_key_policy
|
#define psa_get_key_policy psa_sec_get_key_policy
|
||||||
#define psa_get_key_lifetime psa_sec_get_key_lifetime
|
#define psa_get_key_lifetime psa_sec_get_key_lifetime
|
||||||
#define psa_set_key_lifetime psa_sec_set_key_lifetime
|
|
||||||
#define psa_hash_setup psa_sec_hash_setup
|
#define psa_hash_setup psa_sec_hash_setup
|
||||||
#define psa_hash_update psa_sec_hash_update
|
#define psa_hash_update psa_sec_hash_update
|
||||||
#define psa_hash_finish psa_sec_hash_finish
|
#define psa_hash_finish psa_sec_hash_finish
|
||||||
|
@ -60,6 +59,11 @@ extern "C" {
|
||||||
#define psa_key_agreement psa_sec_key_agreement
|
#define psa_key_agreement psa_sec_key_agreement
|
||||||
#define psa_generator_abort psa_sec_generator_abort
|
#define psa_generator_abort psa_sec_generator_abort
|
||||||
#define mbedtls_psa_inject_entropy mbedtls_psa_sec_inject_entropy
|
#define mbedtls_psa_inject_entropy mbedtls_psa_sec_inject_entropy
|
||||||
|
#define psa_allocate_key psa_sec_allocate_key
|
||||||
|
#define psa_open_key psa_sec_open_key
|
||||||
|
#define psa_create_key psa_sec_create_key
|
||||||
|
#define psa_close_key psa_sec_close_key
|
||||||
|
#define psa_hash_clone psa_sec_hash_clone
|
||||||
|
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// ---------------------------------- Includes ---------------------------------
|
// ---------------------------------- Includes ---------------------------------
|
||||||
#include "spm_panic.h"
|
#include "psa/service.h"
|
||||||
#include "spm_server.h"
|
#include "psa/client.h"
|
||||||
#include "spm/psa_defs.h"
|
#include <stdint.h>
|
||||||
#include "spm/spm_client.h"
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
#define PSA_CRYPTO_SECURE 1
|
#define PSA_CRYPTO_SECURE 1
|
||||||
#include "crypto_spe.h"
|
#include "crypto_spe.h"
|
||||||
|
@ -16,9 +17,86 @@
|
||||||
#define mbedtls_calloc calloc
|
#define mbedtls_calloc calloc
|
||||||
#define mbedtls_free free
|
#define mbedtls_free free
|
||||||
#endif
|
#endif
|
||||||
// ------------------------- Globals ---------------------------
|
|
||||||
|
// -------------------------------- Structures ---------------------------------
|
||||||
|
typedef struct psa_spm_hash_clone_s {
|
||||||
|
int32_t partition_id;
|
||||||
|
void *source_operation;
|
||||||
|
uint8_t ref_count;
|
||||||
|
} psa_spm_hash_clone_t;
|
||||||
|
|
||||||
|
// ---------------------------------- Globals ----------------------------------
|
||||||
static int psa_spm_init_refence_counter = 0;
|
static int psa_spm_init_refence_counter = 0;
|
||||||
|
|
||||||
|
#ifndef MAX_CONCURRENT_HASH_CLONES
|
||||||
|
#define MAX_CONCURRENT_HASH_CLONES 2
|
||||||
|
#endif
|
||||||
|
static psa_spm_hash_clone_t psa_spm_hash_clones[MAX_CONCURRENT_HASH_CLONES];
|
||||||
|
|
||||||
|
// ------------------------- Internal Helper Functions -------------------------
|
||||||
|
static inline psa_status_t reserve_hash_clone(int32_t partition_id, void *source_operation, size_t *index)
|
||||||
|
{
|
||||||
|
/* check if the the clone request source operation is already part of another active clone operation,
|
||||||
|
* for the same source, if so then reuse it and increment its ref_count by 1. A scenario as such may happen
|
||||||
|
* in case there was a context switch between calls of PSA_HASH_CLONE_BEGIN and PSA_HASH_CLONE_END (on the
|
||||||
|
* client side) leading to PSA_HASH_CLONE_BEGIN being executed more than one time without a call to
|
||||||
|
* PSA_HASH_CLONE_END */
|
||||||
|
for (*index = 0; *index < MAX_CONCURRENT_HASH_CLONES; (*index)++) {
|
||||||
|
if (psa_spm_hash_clones[*index].partition_id == partition_id &&
|
||||||
|
psa_spm_hash_clones[*index].source_operation == source_operation) {
|
||||||
|
psa_spm_hash_clones[*index].ref_count++;
|
||||||
|
return PSA_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* find an available empty entry in the array */
|
||||||
|
for (*index = 0; *index < MAX_CONCURRENT_HASH_CLONES; (*index)++) {
|
||||||
|
if (psa_spm_hash_clones[*index].partition_id == 0 &&
|
||||||
|
psa_spm_hash_clones[*index].source_operation == NULL) {
|
||||||
|
psa_spm_hash_clones[*index].partition_id = partition_id;
|
||||||
|
psa_spm_hash_clones[*index].source_operation = source_operation;
|
||||||
|
psa_spm_hash_clones[*index].ref_count++;
|
||||||
|
return PSA_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return PSA_ERROR_BAD_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void release_hash_clone(psa_spm_hash_clone_t *hash_clone)
|
||||||
|
{
|
||||||
|
hash_clone->ref_count--;
|
||||||
|
if (hash_clone->ref_count == 0) {
|
||||||
|
hash_clone->partition_id = 0;
|
||||||
|
hash_clone->source_operation = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void destroy_hash_clone(void *source_operation)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < MAX_CONCURRENT_HASH_CLONES; i++) {
|
||||||
|
if (psa_spm_hash_clones[i].source_operation == source_operation) {
|
||||||
|
psa_spm_hash_clones[i].partition_id = 0;
|
||||||
|
psa_spm_hash_clones[i].source_operation = NULL;
|
||||||
|
psa_spm_hash_clones[i].ref_count = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline psa_status_t get_hash_clone(size_t index, int32_t partition_id,
|
||||||
|
psa_spm_hash_clone_t **hash_clone)
|
||||||
|
{
|
||||||
|
if (index >= MAX_CONCURRENT_HASH_CLONES ||
|
||||||
|
psa_spm_hash_clones[index].partition_id != partition_id ||
|
||||||
|
psa_spm_hash_clones[index].source_operation == NULL) {
|
||||||
|
return PSA_ERROR_BAD_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*hash_clone = &psa_spm_hash_clones[index];
|
||||||
|
return PSA_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------- Partition's Main Thread ---------------------------
|
// ------------------------- Partition's Main Thread ---------------------------
|
||||||
static void psa_crypto_init_operation(void)
|
static void psa_crypto_init_operation(void)
|
||||||
{
|
{
|
||||||
|
@ -36,6 +114,9 @@ static void psa_crypto_init_operation(void)
|
||||||
status = psa_crypto_init();
|
status = psa_crypto_init();
|
||||||
if (status == PSA_SUCCESS) {
|
if (status == PSA_SUCCESS) {
|
||||||
++psa_spm_init_refence_counter;
|
++psa_spm_init_refence_counter;
|
||||||
|
if (psa_spm_init_refence_counter == 1) {
|
||||||
|
memset(psa_spm_hash_clones, 0, sizeof(psa_spm_hash_clones));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -47,7 +128,7 @@ static void psa_crypto_init_operation(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_reply(msg.handle, (psa_error_t) status);
|
psa_reply(msg.handle, (psa_status_t) status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void psa_crypto_free_operation(void)
|
static void psa_crypto_free_operation(void)
|
||||||
|
@ -71,6 +152,7 @@ static void psa_crypto_free_operation(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (psa_spm_init_refence_counter == 0) {
|
if (psa_spm_init_refence_counter == 0) {
|
||||||
|
memset(psa_spm_hash_clones, 0, sizeof(psa_spm_hash_clones));
|
||||||
mbedtls_psa_crypto_free();
|
mbedtls_psa_crypto_free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +165,7 @@ static void psa_crypto_free_operation(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_reply(msg.handle, (psa_error_t) status);
|
psa_reply(msg.handle, (psa_status_t) status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void psa_mac_operation(void)
|
static void psa_mac_operation(void)
|
||||||
|
@ -121,14 +203,14 @@ static void psa_mac_operation(void)
|
||||||
switch (psa_crypto.func) {
|
switch (psa_crypto.func) {
|
||||||
case PSA_MAC_SIGN_SETUP: {
|
case PSA_MAC_SIGN_SETUP: {
|
||||||
status = psa_mac_sign_setup(msg.rhandle,
|
status = psa_mac_sign_setup(msg.rhandle,
|
||||||
psa_crypto.key,
|
psa_crypto.handle,
|
||||||
psa_crypto.alg);
|
psa_crypto.alg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PSA_MAC_VERIFY_SETUP: {
|
case PSA_MAC_VERIFY_SETUP: {
|
||||||
status = psa_mac_verify_setup(msg.rhandle,
|
status = psa_mac_verify_setup(msg.rhandle,
|
||||||
psa_crypto.key,
|
psa_crypto.handle,
|
||||||
psa_crypto.alg);
|
psa_crypto.alg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +320,7 @@ static void psa_mac_operation(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_reply(msg.handle, (psa_error_t) status);
|
psa_reply(msg.handle, (psa_status_t) status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void psa_hash_operation(void)
|
static void psa_hash_operation(void)
|
||||||
|
@ -325,6 +407,7 @@ static void psa_hash_operation(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_free(hash);
|
mbedtls_free(hash);
|
||||||
|
destroy_hash_clone(msg.rhandle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,11 +433,40 @@ static void psa_hash_operation(void)
|
||||||
|
|
||||||
status = psa_hash_verify(msg.rhandle, hash, hash_length);
|
status = psa_hash_verify(msg.rhandle, hash, hash_length);
|
||||||
mbedtls_free(hash);
|
mbedtls_free(hash);
|
||||||
|
destroy_hash_clone(msg.rhandle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PSA_HASH_ABORT: {
|
case PSA_HASH_ABORT: {
|
||||||
status = psa_hash_abort(msg.rhandle);
|
status = psa_hash_abort(msg.rhandle);
|
||||||
|
destroy_hash_clone(msg.rhandle);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case PSA_HASH_CLONE_BEGIN: {
|
||||||
|
size_t index = 0;
|
||||||
|
|
||||||
|
status = reserve_hash_clone(psa_identity(msg.handle), msg.rhandle, &index);
|
||||||
|
if (status == PSA_SUCCESS) {
|
||||||
|
psa_write(msg.handle, 0, &index, sizeof(index));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case PSA_HASH_CLONE_END: {
|
||||||
|
psa_spm_hash_clone_t *hash_clone = NULL;
|
||||||
|
size_t index;
|
||||||
|
|
||||||
|
bytes_read = psa_read(msg.handle, 1, &index, msg.in_size[1]);
|
||||||
|
if (bytes_read != msg.in_size[1]) {
|
||||||
|
SPM_PANIC("SPM read length mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
status = get_hash_clone(index, psa_identity(msg.handle), &hash_clone);
|
||||||
|
if (status == PSA_SUCCESS) {
|
||||||
|
status = psa_hash_clone(hash_clone->source_operation, msg.rhandle);
|
||||||
|
release_hash_clone(hash_clone);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,6 +482,7 @@ static void psa_hash_operation(void)
|
||||||
case PSA_IPC_DISCONNECT: {
|
case PSA_IPC_DISCONNECT: {
|
||||||
psa_hash_abort(msg.rhandle);
|
psa_hash_abort(msg.rhandle);
|
||||||
if (msg.rhandle != NULL) {
|
if (msg.rhandle != NULL) {
|
||||||
|
destroy_hash_clone(msg.rhandle);
|
||||||
mbedtls_free(msg.rhandle);
|
mbedtls_free(msg.rhandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +549,7 @@ static void psa_asymmetric_operation(void)
|
||||||
SPM_PANIC("SPM read length mismatch");
|
SPM_PANIC("SPM read length mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_asymmetric_sign(psa_crypto.key,
|
status = psa_asymmetric_sign(psa_crypto.handle,
|
||||||
psa_crypto.alg,
|
psa_crypto.alg,
|
||||||
hash,
|
hash,
|
||||||
msg.in_size[1],
|
msg.in_size[1],
|
||||||
|
@ -481,7 +594,7 @@ static void psa_asymmetric_operation(void)
|
||||||
SPM_PANIC("SPM read length mismatch");
|
SPM_PANIC("SPM read length mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_asymmetric_verify(psa_crypto.key,
|
status = psa_asymmetric_verify(psa_crypto.handle,
|
||||||
psa_crypto.alg,
|
psa_crypto.alg,
|
||||||
hash,
|
hash,
|
||||||
msg.in_size[2],
|
msg.in_size[2],
|
||||||
|
@ -521,7 +634,7 @@ static void psa_asymmetric_operation(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (psa_crypto.func == PSA_ASYMMETRIC_ENCRYPT)
|
if (psa_crypto.func == PSA_ASYMMETRIC_ENCRYPT)
|
||||||
status = psa_asymmetric_encrypt(psa_crypto.key,
|
status = psa_asymmetric_encrypt(psa_crypto.handle,
|
||||||
psa_crypto.alg,
|
psa_crypto.alg,
|
||||||
input,
|
input,
|
||||||
psa_crypto.input_length,
|
psa_crypto.input_length,
|
||||||
|
@ -531,7 +644,7 @@ static void psa_asymmetric_operation(void)
|
||||||
msg.out_size[0],
|
msg.out_size[0],
|
||||||
&output_length);
|
&output_length);
|
||||||
else
|
else
|
||||||
status = psa_asymmetric_decrypt(psa_crypto.key,
|
status = psa_asymmetric_decrypt(psa_crypto.handle,
|
||||||
psa_crypto.alg,
|
psa_crypto.alg,
|
||||||
input,
|
input,
|
||||||
psa_crypto.input_length,
|
psa_crypto.input_length,
|
||||||
|
@ -568,7 +681,7 @@ static void psa_asymmetric_operation(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_reply(msg.handle, (psa_error_t) status);
|
psa_reply(msg.handle, (psa_status_t) status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void psa_aead_operation()
|
static void psa_aead_operation()
|
||||||
|
@ -628,7 +741,7 @@ static void psa_aead_operation()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (psa_crypto.func == PSA_AEAD_ENCRYPT)
|
if (psa_crypto.func == PSA_AEAD_ENCRYPT)
|
||||||
status = psa_aead_encrypt(psa_crypto.key,
|
status = psa_aead_encrypt(psa_crypto.handle,
|
||||||
psa_crypto.alg,
|
psa_crypto.alg,
|
||||||
psa_crypto.nonce,
|
psa_crypto.nonce,
|
||||||
(size_t)psa_crypto.nonce_size,
|
(size_t)psa_crypto.nonce_size,
|
||||||
|
@ -640,7 +753,7 @@ static void psa_aead_operation()
|
||||||
msg.out_size[0],
|
msg.out_size[0],
|
||||||
&output_length);
|
&output_length);
|
||||||
else
|
else
|
||||||
status = psa_aead_decrypt(psa_crypto.key,
|
status = psa_aead_decrypt(psa_crypto.handle,
|
||||||
psa_crypto.alg,
|
psa_crypto.alg,
|
||||||
psa_crypto.nonce,
|
psa_crypto.nonce,
|
||||||
(size_t)psa_crypto.nonce_size,
|
(size_t)psa_crypto.nonce_size,
|
||||||
|
@ -677,7 +790,7 @@ static void psa_aead_operation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_reply(msg.handle, (psa_error_t) status);
|
psa_reply(msg.handle, (psa_status_t) status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void psa_symmetric_operation(void)
|
static void psa_symmetric_operation(void)
|
||||||
|
@ -717,14 +830,14 @@ static void psa_symmetric_operation(void)
|
||||||
switch (psa_crypto_ipc.func) {
|
switch (psa_crypto_ipc.func) {
|
||||||
case PSA_CIPHER_ENCRYPT_SETUP: {
|
case PSA_CIPHER_ENCRYPT_SETUP: {
|
||||||
status = psa_cipher_encrypt_setup(msg.rhandle,
|
status = psa_cipher_encrypt_setup(msg.rhandle,
|
||||||
psa_crypto_ipc.key,
|
psa_crypto_ipc.handle,
|
||||||
psa_crypto_ipc.alg);
|
psa_crypto_ipc.alg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PSA_CIPHER_DECRYPT_SETUP: {
|
case PSA_CIPHER_DECRYPT_SETUP: {
|
||||||
status = psa_cipher_decrypt_setup(msg.rhandle,
|
status = psa_cipher_decrypt_setup(msg.rhandle,
|
||||||
psa_crypto_ipc.key,
|
psa_crypto_ipc.handle,
|
||||||
psa_crypto_ipc.alg);
|
psa_crypto_ipc.alg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -847,7 +960,7 @@ static void psa_symmetric_operation(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_reply(msg.handle, (psa_error_t) status);
|
psa_reply(msg.handle, (psa_status_t) status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -884,7 +997,7 @@ static void psa_key_management_operation(void)
|
||||||
size_t lifetime_length = msg.out_size[0];
|
size_t lifetime_length = msg.out_size[0];
|
||||||
psa_key_lifetime_t lifetime;
|
psa_key_lifetime_t lifetime;
|
||||||
|
|
||||||
status = psa_get_key_lifetime(psa_key_mng.key,
|
status = psa_get_key_lifetime(psa_key_mng.handle,
|
||||||
&lifetime);
|
&lifetime);
|
||||||
if (status == PSA_SUCCESS) {
|
if (status == PSA_SUCCESS) {
|
||||||
psa_write(msg.handle, 0,
|
psa_write(msg.handle, 0,
|
||||||
|
@ -894,20 +1007,6 @@ static void psa_key_management_operation(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PSA_SET_KEY_LIFETIME: {
|
|
||||||
size_t lifetime_length = msg.in_size[1];
|
|
||||||
psa_key_lifetime_t lifetime;
|
|
||||||
|
|
||||||
bytes_read = psa_read(msg.handle, 1,
|
|
||||||
&lifetime, lifetime_length);
|
|
||||||
if (bytes_read != lifetime_length) {
|
|
||||||
SPM_PANIC("SPM read length mismatch");
|
|
||||||
}
|
|
||||||
|
|
||||||
status = psa_set_key_lifetime(psa_key_mng.key, lifetime);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case PSA_SET_KEY_POLICY: {
|
case PSA_SET_KEY_POLICY: {
|
||||||
size_t policy_length = msg.in_size[1];
|
size_t policy_length = msg.in_size[1];
|
||||||
psa_key_policy_t policy;
|
psa_key_policy_t policy;
|
||||||
|
@ -918,7 +1017,7 @@ static void psa_key_management_operation(void)
|
||||||
SPM_PANIC("SPM read length mismatch");
|
SPM_PANIC("SPM read length mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_set_key_policy(psa_key_mng.key, &policy);
|
status = psa_set_key_policy(psa_key_mng.handle, &policy);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -926,7 +1025,7 @@ static void psa_key_management_operation(void)
|
||||||
size_t policy_size = msg.out_size[0];
|
size_t policy_size = msg.out_size[0];
|
||||||
psa_key_policy_t policy;
|
psa_key_policy_t policy;
|
||||||
|
|
||||||
status = psa_get_key_policy(psa_key_mng.key, &policy);
|
status = psa_get_key_policy(psa_key_mng.handle, &policy);
|
||||||
if (status == PSA_SUCCESS) {
|
if (status == PSA_SUCCESS) {
|
||||||
psa_write(msg.handle, 0, &policy, policy_size);
|
psa_write(msg.handle, 0, &policy, policy_size);
|
||||||
}
|
}
|
||||||
|
@ -947,7 +1046,7 @@ static void psa_key_management_operation(void)
|
||||||
SPM_PANIC("SPM read length mismatch");
|
SPM_PANIC("SPM read length mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_import_key(psa_key_mng.key,
|
status = psa_import_key(psa_key_mng.handle,
|
||||||
psa_key_mng.type,
|
psa_key_mng.type,
|
||||||
key, key_length);
|
key, key_length);
|
||||||
mbedtls_free(key);
|
mbedtls_free(key);
|
||||||
|
@ -955,14 +1054,14 @@ static void psa_key_management_operation(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
case PSA_DESTROY_KEY: {
|
case PSA_DESTROY_KEY: {
|
||||||
status = psa_destroy_key(psa_key_mng.key);
|
status = psa_destroy_key(psa_key_mng.handle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PSA_GET_KEY_INFORMATION: {
|
case PSA_GET_KEY_INFORMATION: {
|
||||||
psa_key_type_t type;
|
psa_key_type_t type;
|
||||||
size_t bits;
|
size_t bits;
|
||||||
status = psa_get_key_information(psa_key_mng.key,
|
status = psa_get_key_information(psa_key_mng.handle,
|
||||||
&type, &bits);
|
&type, &bits);
|
||||||
if (status == PSA_SUCCESS) {
|
if (status == PSA_SUCCESS) {
|
||||||
if (msg.out_size[0] >= sizeof(psa_key_type_t))
|
if (msg.out_size[0] >= sizeof(psa_key_type_t))
|
||||||
|
@ -985,7 +1084,7 @@ static void psa_key_management_operation(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_export_key(psa_key_mng.key, key,
|
status = psa_export_key(psa_key_mng.handle, key,
|
||||||
key_length, &data_length);
|
key_length, &data_length);
|
||||||
if (status == PSA_SUCCESS) {
|
if (status == PSA_SUCCESS) {
|
||||||
psa_write(msg.handle, 0, key, data_length);
|
psa_write(msg.handle, 0, key, data_length);
|
||||||
|
@ -1006,7 +1105,7 @@ static void psa_key_management_operation(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_export_public_key(psa_key_mng.key, key,
|
status = psa_export_public_key(psa_key_mng.handle, key,
|
||||||
key_length, &data_length);
|
key_length, &data_length);
|
||||||
if (status == PSA_SUCCESS) {
|
if (status == PSA_SUCCESS) {
|
||||||
psa_write(msg.handle, 0, key, data_length);
|
psa_write(msg.handle, 0, key, data_length);
|
||||||
|
@ -1043,7 +1142,7 @@ static void psa_key_management_operation(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_generate_key(psa_key_mng.key,
|
status = psa_generate_key(psa_key_mng.handle,
|
||||||
psa_key_mng.type,
|
psa_key_mng.type,
|
||||||
bits,
|
bits,
|
||||||
parameter, parameter_size);
|
parameter, parameter_size);
|
||||||
|
@ -1051,6 +1150,54 @@ static void psa_key_management_operation(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case PSA_ALLOCATE_KEY: {
|
||||||
|
status = psa_allocate_key(&psa_key_mng.handle);
|
||||||
|
if (status == PSA_SUCCESS) {
|
||||||
|
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case PSA_CREATE_KEY: {
|
||||||
|
psa_key_id_t id = 0;
|
||||||
|
size_t max_bits = 0;
|
||||||
|
|
||||||
|
bytes_read = psa_read(msg.handle, 1, &id, msg.in_size[1]);
|
||||||
|
if (bytes_read != msg.in_size[1]) {
|
||||||
|
SPM_PANIC("SPM read length mismatch");
|
||||||
|
}
|
||||||
|
bytes_read = psa_read(msg.handle, 2, &max_bits, msg.in_size[2]);
|
||||||
|
if (bytes_read != msg.in_size[2]) {
|
||||||
|
SPM_PANIC("SPM read length mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
status = psa_create_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
|
||||||
|
if (status == PSA_SUCCESS) {
|
||||||
|
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case PSA_OPEN_KEY: {
|
||||||
|
psa_key_id_t id = 0;
|
||||||
|
|
||||||
|
bytes_read = psa_read(msg.handle, 1, &id, msg.in_size[1]);
|
||||||
|
if (bytes_read != msg.in_size[1]) {
|
||||||
|
SPM_PANIC("SPM read length mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
status = psa_open_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
|
||||||
|
if (status == PSA_SUCCESS) {
|
||||||
|
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case PSA_CLOSE_KEY: {
|
||||||
|
status = psa_close_key(psa_key_mng.handle);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
status = PSA_ERROR_NOT_SUPPORTED;
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
break;
|
break;
|
||||||
|
@ -1242,7 +1389,7 @@ void psa_crypto_generator_operations(void)
|
||||||
SPM_PANIC("SPM read length mismatch");
|
SPM_PANIC("SPM read length mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_generator_import_key(psa_crypto_ipc.key, type,
|
status = psa_generator_import_key(psa_crypto_ipc.handle, type,
|
||||||
bits, msg.rhandle);
|
bits, msg.rhandle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1278,7 +1425,7 @@ void psa_crypto_generator_operations(void)
|
||||||
SPM_PANIC("SPM read length mismatch");
|
SPM_PANIC("SPM read length mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_key_derivation(msg.rhandle, psa_crypto_ipc.key,
|
status = psa_key_derivation(msg.rhandle, psa_crypto_ipc.handle,
|
||||||
psa_crypto_ipc.alg,
|
psa_crypto_ipc.alg,
|
||||||
salt,
|
salt,
|
||||||
msg.in_size[1],//salt length
|
msg.in_size[1],//salt length
|
||||||
|
@ -1303,7 +1450,7 @@ void psa_crypto_generator_operations(void)
|
||||||
SPM_PANIC("SPM read length mismatch");
|
SPM_PANIC("SPM read length mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_key_agreement(msg.rhandle, psa_crypto_ipc.key,
|
status = psa_key_agreement(msg.rhandle, psa_crypto_ipc.handle,
|
||||||
private_key,
|
private_key,
|
||||||
msg.in_size[1],//private_key length
|
msg.in_size[1],//private_key length
|
||||||
psa_crypto_ipc.alg);
|
psa_crypto_ipc.alg);
|
||||||
|
@ -1334,7 +1481,7 @@ void psa_crypto_generator_operations(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_reply(msg.handle, (psa_error_t) status);
|
psa_reply(msg.handle, (psa_status_t) status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* Copyright (c) 2019 ARM Limited
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "psa/lifecycle.h"
|
||||||
|
#include "platform_srv_impl.h"
|
||||||
|
|
||||||
|
uint32_t psa_security_lifecycle_state(void)
|
||||||
|
{
|
||||||
|
uint32_t lc_state = 0;
|
||||||
|
return psa_platfrom_lifecycle_get_impl(&lc_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t mbed_psa_reboot_and_request_new_security_state(uint32_t new_state)
|
||||||
|
{
|
||||||
|
return psa_platfrom_lifecycle_change_request_impl(new_state);
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -15,23 +15,26 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "spm_client.h"
|
#include "psa/lifecycle.h"
|
||||||
#include "psa_prot_internal_storage.h"
|
#include "psa/internal_trusted_storage.h"
|
||||||
#include "test_pits.h"
|
#include "platform_srv_impl.h"
|
||||||
#include "psa_test_its_reset_ifs.h"
|
|
||||||
|
|
||||||
psa_its_status_t test_psa_its_reset(void)
|
#ifndef MBED_CONF_LIFECYCLE_STATE
|
||||||
|
#define MBED_CONF_LIFECYCLE_STATE PSA_LIFECYCLE_ASSEMBLY_AND_TEST
|
||||||
|
#endif
|
||||||
|
|
||||||
|
psa_status_t psa_platfrom_lifecycle_get_impl(uint32_t *lc_state)
|
||||||
{
|
{
|
||||||
psa_handle_t conn = psa_connect(TEST_PSA_ITS_RESET, 1);
|
*lc_state = MBED_CONF_LIFECYCLE_STATE;
|
||||||
if (conn <= PSA_NULL_HANDLE) {
|
return PSA_LIFECYCLE_SUCCESS;
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
}
|
||||||
}
|
|
||||||
|
psa_its_status_t psa_its_reset();
|
||||||
psa_error_t status = psa_call(conn, NULL, 0, NULL, 0);
|
|
||||||
if (status == PSA_DROP_CONNECTION) {
|
psa_status_t psa_platfrom_lifecycle_change_request_impl(uint32_t state)
|
||||||
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
{
|
||||||
}
|
if (PSA_LIFECYCLE_ASSEMBLY_AND_TEST == state) {
|
||||||
|
return psa_its_reset();
|
||||||
psa_close(conn);
|
}
|
||||||
return status;
|
return PSA_LIFECYCLE_ERROR;
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2018 ARM Limited
|
/* Copyright (c) 2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -15,14 +15,12 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TARGET_PSA
|
#ifndef __PLATFROM_SRV_IMPL_H__
|
||||||
#error [NOT_SUPPORTED] ITS tests can run only on PSA-enabled targets.
|
#define __PLATFROM_SRV_IMPL_H__
|
||||||
#endif // TARGET_PSA
|
|
||||||
|
|
||||||
#include "test_pits.h"
|
#include "psa/client.h"
|
||||||
#include "test_pits_impl.h"
|
|
||||||
|
|
||||||
psa_its_status_t test_psa_its_reset(void)
|
psa_status_t psa_platfrom_lifecycle_get_impl(uint32_t *lc_state);
|
||||||
{
|
psa_status_t psa_platfrom_lifecycle_change_request_impl(uint32_t lc_state);
|
||||||
return test_psa_its_reset_impl();
|
|
||||||
}
|
#endif // __PLATFROM_SRV_IMPL_H__
|
|
@ -0,0 +1,58 @@
|
||||||
|
/* Copyright (c) 2019 ARM Limited
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "psa_platform_ifs.h"
|
||||||
|
#include "psa/lifecycle.h"
|
||||||
|
#include "psa/client.h"
|
||||||
|
|
||||||
|
uint32_t psa_security_lifecycle_state(void)
|
||||||
|
{
|
||||||
|
psa_handle_t conn = psa_connect(PSA_PLATFORM_LC_GET, 1);
|
||||||
|
if (conn <= PSA_NULL_HANDLE) {
|
||||||
|
return PSA_LIFECYCLE_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t lc_state = 0;
|
||||||
|
psa_outvec resp[1] = { &lc_state, sizeof(lc_state) };
|
||||||
|
|
||||||
|
psa_status_t status = psa_call(conn, NULL, 0, resp, 1);
|
||||||
|
if (status == PSA_DROP_CONNECTION) {
|
||||||
|
lc_state = PSA_LIFECYCLE_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_close(conn);
|
||||||
|
|
||||||
|
return lc_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t mbed_psa_reboot_and_request_new_security_state(uint32_t new_state)
|
||||||
|
{
|
||||||
|
psa_handle_t conn = psa_connect(PSA_PLATFORM_LC_SET, 1);
|
||||||
|
if (conn <= PSA_NULL_HANDLE) {
|
||||||
|
return (psa_status_t) conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_invec msg[1] = {
|
||||||
|
{ &new_state, sizeof(new_state) }
|
||||||
|
};
|
||||||
|
|
||||||
|
psa_status_t status = psa_call(conn, msg, 1, NULL, 0);
|
||||||
|
|
||||||
|
psa_close(conn);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -28,33 +28,45 @@
|
||||||
#include "rtx_os.h"
|
#include "rtx_os.h"
|
||||||
#include "spm_panic.h"
|
#include "spm_panic.h"
|
||||||
#include "spm_internal.h"
|
#include "spm_internal.h"
|
||||||
#include "psa_test_its_reset_partition.h"
|
#include "psa_platform_partition.h"
|
||||||
#include "psa_test_its_reset_ifs.h"
|
#include "psa_platform_ifs.h"
|
||||||
|
|
||||||
|
|
||||||
/* Threads stacks */
|
/* Threads stacks */
|
||||||
MBED_ALIGN(8) uint8_t test_its_reset_thread_stack[1024] = {0};
|
MBED_ALIGN(8) uint8_t platform_thread_stack[1024] = {0};
|
||||||
|
|
||||||
/* Threads control blocks */
|
/* Threads control blocks */
|
||||||
osRtxThread_t test_its_reset_thread_cb = {0};
|
osRtxThread_t platform_thread_cb = {0};
|
||||||
|
|
||||||
/* Thread attributes - for thread initialization */
|
/* Thread attributes - for thread initialization */
|
||||||
osThreadAttr_t test_its_reset_thread_attr = {
|
osThreadAttr_t platform_thread_attr = {
|
||||||
.name = "test_its_reset",
|
.name = "platform",
|
||||||
.attr_bits = 0,
|
.attr_bits = 0,
|
||||||
.cb_mem = &test_its_reset_thread_cb,
|
.cb_mem = &platform_thread_cb,
|
||||||
.cb_size = sizeof(test_its_reset_thread_cb),
|
.cb_size = sizeof(platform_thread_cb),
|
||||||
.stack_mem = test_its_reset_thread_stack,
|
.stack_mem = platform_thread_stack,
|
||||||
.stack_size = 1024,
|
.stack_size = 1024,
|
||||||
.priority = osPriorityNormal,
|
.priority = osPriorityNormal,
|
||||||
.tz_module = 0,
|
.tz_module = 0,
|
||||||
.reserved = 0
|
.reserved = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
spm_rot_service_t test_its_reset_rot_services[TEST_ITS_RESET_ROT_SRV_COUNT] = {
|
spm_rot_service_t platform_rot_services[PLATFORM_ROT_SRV_COUNT] = {
|
||||||
{
|
{
|
||||||
.sid = TEST_PSA_ITS_RESET,
|
.sid = PSA_PLATFORM_LC_GET,
|
||||||
.mask = TEST_PSA_ITS_RESET_MSK,
|
.mask = PSA_PLATFORM_LC_GET_MSK,
|
||||||
|
.partition = NULL,
|
||||||
|
.min_version = 1,
|
||||||
|
.min_version_policy = PSA_MINOR_VERSION_POLICY_RELAXED,
|
||||||
|
.allow_nspe = true,
|
||||||
|
.queue = {
|
||||||
|
.head = NULL,
|
||||||
|
.tail = NULL
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.sid = PSA_PLATFORM_LC_SET,
|
||||||
|
.mask = PSA_PLATFORM_LC_SET_MSK,
|
||||||
.partition = NULL,
|
.partition = NULL,
|
||||||
.min_version = 1,
|
.min_version = 1,
|
||||||
.min_version_policy = PSA_MINOR_VERSION_POLICY_RELAXED,
|
.min_version_policy = PSA_MINOR_VERSION_POLICY_RELAXED,
|
||||||
|
@ -67,35 +79,36 @@ spm_rot_service_t test_its_reset_rot_services[TEST_ITS_RESET_ROT_SRV_COUNT] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static osRtxMutex_t test_its_reset_mutex = {0};
|
static osRtxMutex_t platform_mutex = {0};
|
||||||
static const osMutexAttr_t test_its_reset_mutex_attr = {
|
static const osMutexAttr_t platform_mutex_attr = {
|
||||||
.name = "test_its_reset_mutex",
|
.name = "platform_mutex",
|
||||||
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
|
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
|
||||||
.cb_mem = &test_its_reset_mutex,
|
.cb_mem = &platform_mutex,
|
||||||
.cb_size = sizeof(test_its_reset_mutex),
|
.cb_size = sizeof(platform_mutex),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
extern void test_pits_entry(void *ptr);
|
extern void platform_partition_entry(void *ptr);
|
||||||
|
|
||||||
void test_its_reset_init(spm_partition_t *partition)
|
void platform_init(spm_partition_t *partition)
|
||||||
{
|
{
|
||||||
if (NULL == partition) {
|
if (NULL == partition) {
|
||||||
SPM_PANIC("partition is NULL!\n");
|
SPM_PANIC("partition is NULL!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
partition->mutex = osMutexNew(&test_its_reset_mutex_attr);
|
partition->mutex = osMutexNew(&platform_mutex_attr);
|
||||||
if (NULL == partition->mutex) {
|
if (NULL == partition->mutex) {
|
||||||
SPM_PANIC("Failed to create mutex for secure partition test_its_reset!\n");
|
SPM_PANIC("Failed to create mutex for secure partition platform!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < TEST_ITS_RESET_ROT_SRV_COUNT; ++i) {
|
for (uint32_t i = 0; i < PLATFORM_ROT_SRV_COUNT; ++i) {
|
||||||
test_its_reset_rot_services[i].partition = partition;
|
platform_rot_services[i].partition = partition;
|
||||||
}
|
}
|
||||||
partition->rot_services = test_its_reset_rot_services;
|
partition->rot_services = platform_rot_services;
|
||||||
|
|
||||||
partition->thread_id = osThreadNew(test_pits_entry, NULL, &test_its_reset_thread_attr);
|
partition->thread_id = osThreadNew(platform_partition_entry, NULL, &platform_thread_attr);
|
||||||
if (NULL == partition->thread_id) {
|
if (NULL == partition->thread_id) {
|
||||||
SPM_PANIC("Failed to create start main thread of partition test_its_reset!\n");
|
SPM_PANIC("Failed to create start main thread of partition platform!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
/* Copyright (c) 2019 ARM Limited
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "psa_platform_partition.h"
|
||||||
|
#include "platform_srv_impl.h"
|
||||||
|
#include "psa/internal_trusted_storage.h"
|
||||||
|
#include "psa/service.h"
|
||||||
|
|
||||||
|
typedef psa_status_t (*SignalHandler)(psa_msg_t *);
|
||||||
|
|
||||||
|
static psa_status_t lifecycle_get(psa_msg_t *msg)
|
||||||
|
{
|
||||||
|
uint32_t lc_state;
|
||||||
|
|
||||||
|
if (msg->out_size[0] != sizeof(lc_state)) {
|
||||||
|
return PSA_DROP_CONNECTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_its_status_t status = psa_platfrom_lifecycle_get_impl(&lc_state);
|
||||||
|
if (status == PSA_SUCCESS) {
|
||||||
|
psa_write(msg->handle, 0, &lc_state, sizeof(lc_state));
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static psa_status_t lifecycle_change_request(psa_msg_t *msg)
|
||||||
|
{
|
||||||
|
uint32_t lc_state;
|
||||||
|
|
||||||
|
if (msg->in_size[0] != sizeof(lc_state)) {
|
||||||
|
return PSA_DROP_CONNECTION;
|
||||||
|
}
|
||||||
|
if (psa_read(msg->handle, 0, &lc_state, sizeof(lc_state)) != sizeof(lc_state)) {
|
||||||
|
return PSA_DROP_CONNECTION;
|
||||||
|
}
|
||||||
|
return psa_platfrom_lifecycle_change_request_impl(lc_state);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void message_handler(psa_msg_t *msg, SignalHandler handler)
|
||||||
|
{
|
||||||
|
psa_status_t status = PSA_SUCCESS;
|
||||||
|
switch (msg->type) {
|
||||||
|
case PSA_IPC_CONNECT: //fallthrough
|
||||||
|
case PSA_IPC_DISCONNECT: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PSA_IPC_CALL: {
|
||||||
|
status = handler(msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
SPM_PANIC("Unexpected message type %d!", (int)(msg->type));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
psa_reply(msg->handle, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void platform_partition_entry(void *ptr)
|
||||||
|
{
|
||||||
|
uint32_t signals = 0;
|
||||||
|
psa_msg_t msg = {0};
|
||||||
|
while (1) {
|
||||||
|
signals = psa_wait_any(PSA_BLOCK);
|
||||||
|
if ((signals & PSA_PLATFORM_LC_GET_MSK) != 0) {
|
||||||
|
psa_get(PSA_PLATFORM_LC_GET_MSK, &msg);
|
||||||
|
message_handler(&msg, lifecycle_get);
|
||||||
|
}
|
||||||
|
if ((signals & PSA_PLATFORM_LC_SET_MSK) != 0) {
|
||||||
|
psa_get(PSA_PLATFORM_LC_SET_MSK, &msg);
|
||||||
|
message_handler(&msg, lifecycle_change_request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -23,28 +23,31 @@
|
||||||
* Generated by tools/spm/generate_partition_code.py Version 1.0
|
* Generated by tools/spm/generate_partition_code.py Version 1.0
|
||||||
**********************************************************************************************************************/
|
**********************************************************************************************************************/
|
||||||
|
|
||||||
#ifndef PSA_TEST_ITS_RESET_PARTITION_H
|
#ifndef PSA_PLATFORM_PARTITION_H
|
||||||
#define PSA_TEST_ITS_RESET_PARTITION_H
|
#define PSA_PLATFORM_PARTITION_H
|
||||||
|
|
||||||
#define TEST_ITS_RESET_ID 11
|
#define PLATFORM_ID 8
|
||||||
|
|
||||||
#define TEST_ITS_RESET_ROT_SRV_COUNT (1UL)
|
#define PLATFORM_ROT_SRV_COUNT (2UL)
|
||||||
#define TEST_ITS_RESET_EXT_ROT_SRV_COUNT (0UL)
|
#define PLATFORM_EXT_ROT_SRV_COUNT (0UL)
|
||||||
|
|
||||||
/* TEST_ITS_RESET event flags */
|
/* PLATFORM event flags */
|
||||||
#define TEST_ITS_RESET_RESERVED1_POS (1UL)
|
#define PLATFORM_RESERVED1_POS (1UL)
|
||||||
#define TEST_ITS_RESET_RESERVED1_MSK (1UL << TEST_ITS_RESET_RESERVED1_POS)
|
#define PLATFORM_RESERVED1_MSK (1UL << PLATFORM_RESERVED1_POS)
|
||||||
|
|
||||||
#define TEST_ITS_RESET_RESERVED2_POS (2UL)
|
#define PLATFORM_RESERVED2_POS (2UL)
|
||||||
#define TEST_ITS_RESET_RESERVED2_MSK (1UL << TEST_ITS_RESET_RESERVED2_POS)
|
#define PLATFORM_RESERVED2_MSK (1UL << PLATFORM_RESERVED2_POS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define TEST_PSA_ITS_RESET_MSK_POS (4UL)
|
#define PSA_PLATFORM_LC_GET_MSK_POS (4UL)
|
||||||
#define TEST_PSA_ITS_RESET_MSK (1UL << TEST_PSA_ITS_RESET_MSK_POS)
|
#define PSA_PLATFORM_LC_GET_MSK (1UL << PSA_PLATFORM_LC_GET_MSK_POS)
|
||||||
|
#define PSA_PLATFORM_LC_SET_MSK_POS (5UL)
|
||||||
|
#define PSA_PLATFORM_LC_SET_MSK (1UL << PSA_PLATFORM_LC_SET_MSK_POS)
|
||||||
|
|
||||||
#define TEST_ITS_RESET_WAIT_ANY_SID_MSK (\
|
#define PLATFORM_WAIT_ANY_SID_MSK (\
|
||||||
TEST_PSA_ITS_RESET_MSK)
|
PSA_PLATFORM_LC_GET_MSK | \
|
||||||
|
PSA_PLATFORM_LC_SET_MSK)
|
||||||
|
|
||||||
|
|
||||||
#endif // PSA_TEST_ITS_RESET_PARTITION_H
|
#endif // PSA_PLATFORM_PARTITION_H
|
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"name": "PLATFORM",
|
||||||
|
"type": "APPLICATION-ROT",
|
||||||
|
"priority": "NORMAL",
|
||||||
|
"id": "0x00000008",
|
||||||
|
"entry_point": "platform_partition_entry",
|
||||||
|
"stack_size": "0x400",
|
||||||
|
"heap_size": "0x400",
|
||||||
|
"services": [{
|
||||||
|
"name": "PSA_PLATFORM_LC_GET",
|
||||||
|
"identifier": "0x00011000",
|
||||||
|
"signal": "PSA_PLATFORM_LC_GET_MSK",
|
||||||
|
"non_secure_clients": true,
|
||||||
|
"minor_version": 1,
|
||||||
|
"minor_policy": "RELAXED"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "PSA_PLATFORM_LC_SET",
|
||||||
|
"identifier": "0x00011001",
|
||||||
|
"signal": "PSA_PLATFORM_LC_SET_MSK",
|
||||||
|
"non_secure_clients": true,
|
||||||
|
"minor_version": 1,
|
||||||
|
"minor_policy": "RELAXED"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source_files": [
|
||||||
|
"COMPONENT_SPE/platform_partition.c"
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -23,9 +23,10 @@
|
||||||
* Generated by tools/spm/generate_partition_code.py Version 1.0
|
* Generated by tools/spm/generate_partition_code.py Version 1.0
|
||||||
**********************************************************************************************************************/
|
**********************************************************************************************************************/
|
||||||
|
|
||||||
#ifndef PSA_TEST_ITS_RESET_PARTITION_ROT_SERVICES_H
|
#ifndef PSA_PLATFORM_PARTITION_ROT_SERVICES_H
|
||||||
#define PSA_TEST_ITS_RESET_PARTITION_ROT_SERVICES_H
|
#define PSA_PLATFORM_PARTITION_ROT_SERVICES_H
|
||||||
|
|
||||||
#define TEST_PSA_ITS_RESET 0x00011A04
|
#define PSA_PLATFORM_LC_GET 0x00011000
|
||||||
|
#define PSA_PLATFORM_LC_SET 0x00011001
|
||||||
|
|
||||||
#endif // PSA_TEST_ITS_RESET_PARTITION_ROT_SERVICES_H
|
#endif // PSA_PLATFORM_PARTITION_ROT_SERVICES_H
|
|
@ -18,7 +18,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "psa_prot_internal_storage.h"
|
#include "psa/internal_trusted_storage.h"
|
||||||
#include "pits_impl.h"
|
#include "pits_impl.h"
|
||||||
#include "kv_config.h"
|
#include "kv_config.h"
|
||||||
#include "mbed_error.h"
|
#include "mbed_error.h"
|
||||||
|
@ -27,10 +27,10 @@
|
||||||
// So here we set a global pid value to be used for when calling IMPL functions
|
// So here we set a global pid value to be used for when calling IMPL functions
|
||||||
#define PSA_ITS_EMUL_PID 1
|
#define PSA_ITS_EMUL_PID 1
|
||||||
|
|
||||||
psa_its_status_t psa_its_set(uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
|
psa_its_status_t psa_its_set(psa_its_uid_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
|
||||||
{
|
{
|
||||||
if (!p_data && data_length) {
|
if (!p_data && data_length) {
|
||||||
return PSA_ITS_ERROR_BAD_POINTER;
|
return PSA_ITS_ERROR_INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// KVStore initiation:
|
// KVStore initiation:
|
||||||
|
@ -46,10 +46,10 @@ psa_its_status_t psa_its_set(uint32_t uid, uint32_t data_length, const void *p_d
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_its_status_t psa_its_get(uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
|
psa_its_status_t psa_its_get(psa_its_uid_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
|
||||||
{
|
{
|
||||||
if (!p_data && data_length) {
|
if (!p_data && data_length) {
|
||||||
return PSA_ITS_ERROR_BAD_POINTER;
|
return PSA_ITS_ERROR_INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// KVStore initiation:
|
// KVStore initiation:
|
||||||
|
@ -63,10 +63,10 @@ psa_its_status_t psa_its_get(uint32_t uid, uint32_t data_offset, uint32_t data_l
|
||||||
return psa_its_get_impl(PSA_ITS_EMUL_PID, uid, data_offset, data_length, p_data);
|
return psa_its_get_impl(PSA_ITS_EMUL_PID, uid, data_offset, data_length, p_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_its_status_t psa_its_get_info(uint32_t uid, struct psa_its_info_t *p_info)
|
psa_its_status_t psa_its_get_info(psa_its_uid_t uid, struct psa_its_info_t *p_info)
|
||||||
{
|
{
|
||||||
if (!p_info) {
|
if (!p_info) {
|
||||||
return PSA_ITS_ERROR_BAD_POINTER;
|
return PSA_ITS_ERROR_INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// KVStore initiation:
|
// KVStore initiation:
|
||||||
|
@ -80,7 +80,7 @@ psa_its_status_t psa_its_get_info(uint32_t uid, struct psa_its_info_t *p_info)
|
||||||
return psa_its_get_info_impl(PSA_ITS_EMUL_PID, uid, p_info);
|
return psa_its_get_info_impl(PSA_ITS_EMUL_PID, uid, p_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_its_status_t psa_its_remove(uint32_t uid)
|
psa_its_status_t psa_its_remove(psa_its_uid_t uid)
|
||||||
{
|
{
|
||||||
// KVStore initiation:
|
// KVStore initiation:
|
||||||
// - In EMUL (non-secure single core) we do it here since we don't have another context to do it inside.
|
// - In EMUL (non-secure single core) we do it here since we don't have another context to do it inside.
|
||||||
|
@ -92,3 +92,16 @@ psa_its_status_t psa_its_remove(uint32_t uid)
|
||||||
|
|
||||||
return psa_its_remove_impl(PSA_ITS_EMUL_PID, uid);
|
return psa_its_remove_impl(PSA_ITS_EMUL_PID, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" psa_its_status_t psa_its_reset()
|
||||||
|
{
|
||||||
|
// KVStore initiation:
|
||||||
|
// - In EMUL (non-secure single core) we do it here since we don't have another context to do it inside.
|
||||||
|
// - Repeating calls has no effect
|
||||||
|
int kv_status = kv_init_storage_config();
|
||||||
|
if (kv_status != MBED_SUCCESS) {
|
||||||
|
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return psa_its_reset_impl();
|
||||||
|
}
|
||||||
|
|
|
@ -19,23 +19,22 @@
|
||||||
#include "KVMap.h"
|
#include "KVMap.h"
|
||||||
#include "KVStore.h"
|
#include "KVStore.h"
|
||||||
#include "TDBStore.h"
|
#include "TDBStore.h"
|
||||||
#include "psa_prot_internal_storage.h"
|
#include "psa/internal_trusted_storage.h"
|
||||||
#include "pits_impl.h"
|
#include "pits_impl.h"
|
||||||
|
#include "pits_version_impl.h"
|
||||||
#include "mbed_error.h"
|
#include "mbed_error.h"
|
||||||
#include "mbed_toolchain.h"
|
#include "mbed_toolchain.h"
|
||||||
|
|
||||||
|
using namespace mbed;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace mbed;
|
|
||||||
|
|
||||||
#define STR_EXPAND(tok) #tok
|
|
||||||
|
|
||||||
// Maximum length of filename we use for kvstore API.
|
// Maximum length of filename we use for kvstore API.
|
||||||
// uid: 6; delimiter: 1; pid: 6; str terminator: 1
|
// pid: 6; delimiter: 1; uid: 11; str terminator: 1
|
||||||
#define PSA_ITS_FILENAME_MAX_LEN 14
|
#define PSA_ITS_FILENAME_MAX_LEN 19
|
||||||
|
|
||||||
|
|
||||||
const uint8_t base64_coding_table[] = {
|
const uint8_t base64_coding_table[] = {
|
||||||
|
@ -49,22 +48,74 @@ const uint8_t base64_coding_table[] = {
|
||||||
'4', '5', '6', '7', '8', '9', '+', '-'
|
'4', '5', '6', '7', '8', '9', '+', '-'
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
static KVStore *kvstore = NULL;
|
||||||
* \brief Get default KVStore instance for internal flesh storage
|
|
||||||
*
|
static void its_init(void)
|
||||||
* \return valid pointer to KVStore
|
|
||||||
*/
|
|
||||||
static KVStore *get_kvstore_instance(void)
|
|
||||||
{
|
{
|
||||||
KVMap &kv_map = KVMap::get_instance();
|
KVMap &kv_map = KVMap::get_instance();
|
||||||
|
kvstore = kv_map.get_internal_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
|
||||||
KVStore *kvstore = kv_map.get_internal_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
|
|
||||||
if (!kvstore) {
|
if (!kvstore) {
|
||||||
// Can only happen due to system misconfiguration.
|
// Can only happen due to system misconfiguration.
|
||||||
// Thus considered as unrecoverable error for runtime.
|
// Thus considered as unrecoverable error for runtime.
|
||||||
error("Failed getting kvstore instance\n");
|
error("Failed getting kvstore instance\n");
|
||||||
}
|
}
|
||||||
return kvstore;
|
|
||||||
|
its_version_t version = { 0, 0 };
|
||||||
|
size_t actual_size = 0;
|
||||||
|
KVStore::info_t kv_info;
|
||||||
|
bool write_version = false;
|
||||||
|
int status = kvstore->get_info(ITS_VERSION_KEY, &kv_info);
|
||||||
|
if (status != MBED_SUCCESS) {
|
||||||
|
version.major = PSA_ITS_API_VERSION_MAJOR;
|
||||||
|
version.minor = PSA_ITS_API_VERSION_MINOR;
|
||||||
|
write_version = true;
|
||||||
|
} else {
|
||||||
|
if (kv_info.size != sizeof(version)) {
|
||||||
|
error("ITS version data is corrupt");
|
||||||
|
}
|
||||||
|
|
||||||
|
status = kvstore->get(ITS_VERSION_KEY, &version, sizeof(version), &actual_size, 0);
|
||||||
|
if ((status != MBED_SUCCESS) ||
|
||||||
|
((status == MBED_SUCCESS) && (actual_size != sizeof(version)))) {
|
||||||
|
error("Could not read ITS version data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((version.major > PSA_ITS_API_VERSION_MAJOR) ||
|
||||||
|
((version.major == PSA_ITS_API_VERSION_MAJOR) && (version.minor > PSA_ITS_API_VERSION_MINOR))) {
|
||||||
|
error("Downgrading ITS version is not allowed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((version.major < PSA_ITS_API_VERSION_MAJOR) ||
|
||||||
|
((version.major == PSA_ITS_API_VERSION_MAJOR) && (version.minor < PSA_ITS_API_VERSION_MINOR))) {
|
||||||
|
psa_its_status_t migration_status = its_version_migrate(kvstore, &version);
|
||||||
|
if (migration_status != PSA_ITS_SUCCESS) {
|
||||||
|
error("ITS migration failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
version.major = PSA_ITS_API_VERSION_MAJOR;
|
||||||
|
version.minor = PSA_ITS_API_VERSION_MINOR;
|
||||||
|
write_version = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (write_version) {
|
||||||
|
if (kvstore->set(ITS_VERSION_KEY, &version, sizeof(version), 0) != MBED_SUCCESS) {
|
||||||
|
error("Could not write PSA ITS version");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// used from test only
|
||||||
|
void its_deinit(void)
|
||||||
|
{
|
||||||
|
kvstore = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
MBED_WEAK psa_its_status_t its_version_migrate(void *storage, const its_version_t *version)
|
||||||
|
{
|
||||||
|
(void)storage;
|
||||||
|
(void)version;
|
||||||
|
return PSA_ITS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -83,7 +134,7 @@ static psa_its_status_t convert_status(int status)
|
||||||
case MBED_ERROR_MEDIA_FULL:
|
case MBED_ERROR_MEDIA_FULL:
|
||||||
return PSA_ITS_ERROR_INSUFFICIENT_SPACE;
|
return PSA_ITS_ERROR_INSUFFICIENT_SPACE;
|
||||||
case MBED_ERROR_ITEM_NOT_FOUND:
|
case MBED_ERROR_ITEM_NOT_FOUND:
|
||||||
return PSA_ITS_ERROR_KEY_NOT_FOUND;
|
return PSA_ITS_ERROR_UID_NOT_FOUND;
|
||||||
default:
|
default:
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +148,20 @@ static psa_its_status_t convert_status(int status)
|
||||||
* \param n[in] number of bits to shift right
|
* \param n[in] number of bits to shift right
|
||||||
* \return the result
|
* \return the result
|
||||||
*/
|
*/
|
||||||
MBED_FORCEINLINE uint32_t lsr(uint32_t x, uint32_t n)
|
MBED_FORCEINLINE uint32_t lsr32(uint32_t x, uint32_t n)
|
||||||
|
{
|
||||||
|
return x >> n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Logic shift right
|
||||||
|
*
|
||||||
|
* \note must operate on unsinged integers to prevent negative carry
|
||||||
|
* \param x[in] input number for shifting
|
||||||
|
* \param n[in] number of bits to shift right
|
||||||
|
* \return the result
|
||||||
|
*/
|
||||||
|
MBED_FORCEINLINE uint64_t lsr64(uint64_t x, uint32_t n)
|
||||||
{
|
{
|
||||||
return x >> n;
|
return x >> n;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +177,7 @@ MBED_FORCEINLINE uint32_t lsr(uint32_t x, uint32_t n)
|
||||||
* \param[in] uid - PSA internal storage unique ID
|
* \param[in] uid - PSA internal storage unique ID
|
||||||
* \param[in] pid - owner PSA partition ID
|
* \param[in] pid - owner PSA partition ID
|
||||||
*/
|
*/
|
||||||
static void generate_fn(char *tdb_filename, uint32_t tdb_filename_size, uint32_t uid, int32_t pid)
|
static void generate_fn(char *tdb_filename, uint32_t tdb_filename_size, psa_its_uid_t uid, int32_t pid)
|
||||||
{
|
{
|
||||||
MBED_ASSERT(tdb_filename != NULL);
|
MBED_ASSERT(tdb_filename != NULL);
|
||||||
MBED_ASSERT(tdb_filename_size == PSA_ITS_FILENAME_MAX_LEN);
|
MBED_ASSERT(tdb_filename_size == PSA_ITS_FILENAME_MAX_LEN);
|
||||||
|
@ -124,7 +188,7 @@ static void generate_fn(char *tdb_filename, uint32_t tdb_filename_size, uint32_t
|
||||||
// Iterate on PID; each time convert 6 bits of PID into a character; first iteration must be done
|
// Iterate on PID; each time convert 6 bits of PID into a character; first iteration must be done
|
||||||
do {
|
do {
|
||||||
tdb_filename[filename_idx++] = base64_coding_table[unsigned_pid & 0x3F];
|
tdb_filename[filename_idx++] = base64_coding_table[unsigned_pid & 0x3F];
|
||||||
unsigned_pid = lsr(unsigned_pid, 6);
|
unsigned_pid = lsr32(unsigned_pid, 6);
|
||||||
} while (unsigned_pid != 0);
|
} while (unsigned_pid != 0);
|
||||||
|
|
||||||
// Write delimiter
|
// Write delimiter
|
||||||
|
@ -133,19 +197,20 @@ static void generate_fn(char *tdb_filename, uint32_t tdb_filename_size, uint32_t
|
||||||
// Iterate on UID; each time convert 6 bits of UID into a character; first iteration must be done
|
// Iterate on UID; each time convert 6 bits of UID into a character; first iteration must be done
|
||||||
do {
|
do {
|
||||||
tdb_filename[filename_idx++] = base64_coding_table[uid & 0x3F];
|
tdb_filename[filename_idx++] = base64_coding_table[uid & 0x3F];
|
||||||
uid = lsr(uid, 6);
|
uid = lsr64(uid, 6);
|
||||||
} while (uid != 0);
|
} while (uid != 0);
|
||||||
|
|
||||||
tdb_filename[filename_idx++] = '\0';
|
tdb_filename[filename_idx++] = '\0';
|
||||||
MBED_ASSERT(filename_idx <= PSA_ITS_FILENAME_MAX_LEN);
|
MBED_ASSERT(filename_idx <= PSA_ITS_FILENAME_MAX_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_its_status_t psa_its_set_impl(int32_t pid, uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
|
psa_its_status_t psa_its_set_impl(int32_t pid, psa_its_uid_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
|
||||||
{
|
{
|
||||||
KVStore *kvstore = get_kvstore_instance();
|
if (!kvstore) {
|
||||||
MBED_ASSERT(kvstore);
|
its_init();
|
||||||
|
}
|
||||||
|
|
||||||
if ((create_flags != 0) && (create_flags != PSA_ITS_WRITE_ONCE_FLAG)) {
|
if ((create_flags & (~PSA_ITS_FLAGS_MSK)) != 0) {
|
||||||
return PSA_ITS_ERROR_FLAGS_NOT_SUPPORTED;
|
return PSA_ITS_ERROR_FLAGS_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +219,7 @@ psa_its_status_t psa_its_set_impl(int32_t pid, uint32_t uid, uint32_t data_lengt
|
||||||
generate_fn(kv_key, PSA_ITS_FILENAME_MAX_LEN, uid, pid);
|
generate_fn(kv_key, PSA_ITS_FILENAME_MAX_LEN, uid, pid);
|
||||||
|
|
||||||
uint32_t kv_create_flags = 0;
|
uint32_t kv_create_flags = 0;
|
||||||
if (create_flags & PSA_ITS_WRITE_ONCE_FLAG) {
|
if (create_flags & PSA_ITS_FLAG_WRITE_ONCE) {
|
||||||
kv_create_flags = KVStore::WRITE_ONCE_FLAG;
|
kv_create_flags = KVStore::WRITE_ONCE_FLAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,10 +228,11 @@ psa_its_status_t psa_its_set_impl(int32_t pid, uint32_t uid, uint32_t data_lengt
|
||||||
return convert_status(status);
|
return convert_status(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_its_status_t psa_its_get_impl(int32_t pid, uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
|
psa_its_status_t psa_its_get_impl(int32_t pid, psa_its_uid_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
|
||||||
{
|
{
|
||||||
KVStore *kvstore = get_kvstore_instance();
|
if (!kvstore) {
|
||||||
MBED_ASSERT(kvstore);
|
its_init();
|
||||||
|
}
|
||||||
|
|
||||||
// Generate KVStore key
|
// Generate KVStore key
|
||||||
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
|
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
|
||||||
|
@ -202,10 +268,11 @@ psa_its_status_t psa_its_get_impl(int32_t pid, uint32_t uid, uint32_t data_offse
|
||||||
return convert_status(status);
|
return convert_status(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_its_status_t psa_its_get_info_impl(int32_t pid, uint32_t uid, struct psa_its_info_t *p_info)
|
psa_its_status_t psa_its_get_info_impl(int32_t pid, psa_its_uid_t uid, struct psa_its_info_t *p_info)
|
||||||
{
|
{
|
||||||
KVStore *kvstore = get_kvstore_instance();
|
if (!kvstore) {
|
||||||
MBED_ASSERT(kvstore);
|
its_init();
|
||||||
|
}
|
||||||
|
|
||||||
// Generate KVStore key
|
// Generate KVStore key
|
||||||
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
|
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
|
||||||
|
@ -217,7 +284,7 @@ psa_its_status_t psa_its_get_info_impl(int32_t pid, uint32_t uid, struct psa_its
|
||||||
if (status == MBED_SUCCESS) {
|
if (status == MBED_SUCCESS) {
|
||||||
p_info->flags = 0;
|
p_info->flags = 0;
|
||||||
if (kv_info.flags & KVStore::WRITE_ONCE_FLAG) {
|
if (kv_info.flags & KVStore::WRITE_ONCE_FLAG) {
|
||||||
p_info->flags |= PSA_ITS_WRITE_ONCE_FLAG;
|
p_info->flags |= PSA_ITS_FLAG_WRITE_ONCE;
|
||||||
}
|
}
|
||||||
p_info->size = (uint32_t)(kv_info.size); // kv_info.size is of type size_t
|
p_info->size = (uint32_t)(kv_info.size); // kv_info.size is of type size_t
|
||||||
}
|
}
|
||||||
|
@ -225,10 +292,11 @@ psa_its_status_t psa_its_get_info_impl(int32_t pid, uint32_t uid, struct psa_its
|
||||||
return convert_status(status);
|
return convert_status(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_its_status_t psa_its_remove_impl(int32_t pid, uint32_t uid)
|
psa_its_status_t psa_its_remove_impl(int32_t pid, psa_its_uid_t uid)
|
||||||
{
|
{
|
||||||
KVStore *kvstore = get_kvstore_instance();
|
if (!kvstore) {
|
||||||
MBED_ASSERT(kvstore);
|
its_init();
|
||||||
|
}
|
||||||
|
|
||||||
// Generate KVStore key
|
// Generate KVStore key
|
||||||
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
|
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
|
||||||
|
@ -239,6 +307,16 @@ psa_its_status_t psa_its_remove_impl(int32_t pid, uint32_t uid)
|
||||||
return convert_status(status);
|
return convert_status(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
psa_its_status_t psa_its_reset_impl()
|
||||||
|
{
|
||||||
|
if (!kvstore) {
|
||||||
|
its_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
int status = kvstore->reset();
|
||||||
|
return convert_status(status);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,20 +18,21 @@
|
||||||
#ifndef __PITS_IMPL_H__
|
#ifndef __PITS_IMPL_H__
|
||||||
#define __PITS_IMPL_H__
|
#define __PITS_IMPL_H__
|
||||||
|
|
||||||
#include "psa_prot_internal_storage.h"
|
#include "psa/internal_trusted_storage.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define PITS_DATA_PTR_AT_OFFSET(ptr, offset) ((void *)(((uintptr_t)ptr) + ((uintptr_t)offset)))
|
#define PITS_DATA_PTR_AT_OFFSET(ptr, offset) ((void *)(((uintptr_t)ptr) + ((uintptr_t)offset)))
|
||||||
|
#define STR_EXPAND(tok) #tok
|
||||||
|
|
||||||
psa_its_status_t psa_its_set_impl(int32_t pid, uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags);
|
psa_its_status_t psa_its_set_impl(int32_t pid, psa_its_uid_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags);
|
||||||
psa_its_status_t psa_its_get_impl(int32_t pid, uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data);
|
psa_its_status_t psa_its_get_impl(int32_t pid, psa_its_uid_t uid, uint32_t data_offset, uint32_t data_length, void *p_data);
|
||||||
psa_its_status_t psa_its_get_info_impl(int32_t pid, uint32_t uid, struct psa_its_info_t *p_info);
|
psa_its_status_t psa_its_get_info_impl(int32_t pid, psa_its_uid_t uid, struct psa_its_info_t *p_info);
|
||||||
psa_its_status_t psa_its_remove_impl(int32_t pid, uint32_t uid);
|
psa_its_status_t psa_its_remove_impl(int32_t pid, psa_its_uid_t uid);
|
||||||
|
psa_its_status_t psa_its_reset_impl();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* Copyright (c) 2019 ARM Limited
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PITS_VER_IMPL_H__
|
||||||
|
#define __PITS_VER_IMPL_H__
|
||||||
|
|
||||||
|
#include "psa/internal_trusted_storage.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ITS_VERSION_KEY "PSA_ITS_VERSION" // ITS version entry identifier in TDBStore
|
||||||
|
|
||||||
|
typedef struct its_version {
|
||||||
|
uint32_t major;
|
||||||
|
uint32_t minor;
|
||||||
|
} its_version_t;
|
||||||
|
|
||||||
|
psa_its_status_t its_version_migrate(void *storage, const its_version_t *version);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __PITS_VER_IMPL_H__
|
|
@ -15,17 +15,17 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "spm_client.h"
|
#include "psa/client.h"
|
||||||
#include "psa_prot_internal_storage.h"
|
#include "psa/internal_trusted_storage.h"
|
||||||
#include "psa_its_ifs.h"
|
#include "psa_its_ifs.h"
|
||||||
|
|
||||||
psa_its_status_t psa_its_set(uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
|
psa_its_status_t psa_its_set(psa_its_uid_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
|
||||||
{
|
{
|
||||||
if (!p_data && data_length) {
|
if (!p_data && data_length) {
|
||||||
return PSA_ITS_ERROR_BAD_POINTER;
|
return PSA_ITS_ERROR_INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_invec_t msg[3] = {
|
psa_invec msg[3] = {
|
||||||
{ &uid, sizeof(uid) },
|
{ &uid, sizeof(uid) },
|
||||||
{ p_data, data_length },
|
{ p_data, data_length },
|
||||||
{ &create_flags, sizeof(create_flags) }
|
{ &create_flags, sizeof(create_flags) }
|
||||||
|
@ -36,7 +36,7 @@ psa_its_status_t psa_its_set(uint32_t uid, uint32_t data_length, const void *p_d
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_error_t status = psa_call(conn, msg, 3, NULL, 0);
|
psa_status_t status = psa_call(conn, msg, 3, NULL, 0);
|
||||||
if (status == PSA_DROP_CONNECTION) {
|
if (status == PSA_DROP_CONNECTION) {
|
||||||
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -45,24 +45,24 @@ psa_its_status_t psa_its_set(uint32_t uid, uint32_t data_length, const void *p_d
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_its_status_t psa_its_get(uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
|
psa_its_status_t psa_its_get(psa_its_uid_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
|
||||||
{
|
{
|
||||||
if (!p_data && data_length) {
|
if (!p_data && data_length) {
|
||||||
return PSA_ITS_ERROR_BAD_POINTER;
|
return PSA_ITS_ERROR_INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_invec_t msg[2] = {
|
psa_invec msg[2] = {
|
||||||
{ &uid, sizeof(uid) },
|
{ &uid, sizeof(uid) },
|
||||||
{ &data_offset, sizeof(data_offset) }
|
{ &data_offset, sizeof(data_offset) }
|
||||||
};
|
};
|
||||||
psa_outvec_t resp = { p_data, data_length };
|
psa_outvec resp = { p_data, data_length };
|
||||||
|
|
||||||
psa_handle_t conn = psa_connect(PSA_ITS_GET, 1);
|
psa_handle_t conn = psa_connect(PSA_ITS_GET, 1);
|
||||||
if (conn <= PSA_NULL_HANDLE) {
|
if (conn <= PSA_NULL_HANDLE) {
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_error_t status = psa_call(conn, msg, 2, &resp, 1);
|
psa_status_t status = psa_call(conn, msg, 2, &resp, 1);
|
||||||
|
|
||||||
if (status == PSA_DROP_CONNECTION) {
|
if (status == PSA_DROP_CONNECTION) {
|
||||||
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
|
@ -72,21 +72,21 @@ psa_its_status_t psa_its_get(uint32_t uid, uint32_t data_offset, uint32_t data_l
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_its_status_t psa_its_get_info(uint32_t uid, struct psa_its_info_t *p_info)
|
psa_its_status_t psa_its_get_info(psa_its_uid_t uid, struct psa_its_info_t *p_info)
|
||||||
{
|
{
|
||||||
if (!p_info) {
|
if (!p_info) {
|
||||||
return PSA_ITS_ERROR_BAD_POINTER;
|
return PSA_ITS_ERROR_INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct psa_its_info_t info = { 0 };
|
struct psa_its_info_t info = { 0, PSA_ITS_FLAG_NONE };
|
||||||
psa_invec_t msg = { &uid, sizeof(uid) };
|
psa_invec msg = { &uid, sizeof(uid) };
|
||||||
psa_outvec_t resp = { &info, sizeof(info) };
|
psa_outvec resp = { &info, sizeof(info) };
|
||||||
psa_handle_t conn = psa_connect(PSA_ITS_INFO, 1);
|
psa_handle_t conn = psa_connect(PSA_ITS_INFO, 1);
|
||||||
if (conn <= PSA_NULL_HANDLE) {
|
if (conn <= PSA_NULL_HANDLE) {
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_error_t status = psa_call(conn, &msg, 1, &resp, 1);
|
psa_status_t status = psa_call(conn, &msg, 1, &resp, 1);
|
||||||
|
|
||||||
*p_info = info;
|
*p_info = info;
|
||||||
|
|
||||||
|
@ -98,15 +98,31 @@ psa_its_status_t psa_its_get_info(uint32_t uid, struct psa_its_info_t *p_info)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_its_status_t psa_its_remove(uint32_t uid)
|
psa_its_status_t psa_its_remove(psa_its_uid_t uid)
|
||||||
{
|
{
|
||||||
psa_invec_t msg = { &uid, sizeof(uid) };
|
psa_invec msg = { &uid, sizeof(uid) };
|
||||||
psa_handle_t conn = psa_connect(PSA_ITS_REMOVE, 1);
|
psa_handle_t conn = psa_connect(PSA_ITS_REMOVE, 1);
|
||||||
if (conn <= PSA_NULL_HANDLE) {
|
if (conn <= PSA_NULL_HANDLE) {
|
||||||
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_error_t status = psa_call(conn, &msg, 1, NULL, 0);
|
psa_status_t status = psa_call(conn, &msg, 1, NULL, 0);
|
||||||
|
if (status == PSA_DROP_CONNECTION) {
|
||||||
|
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_close(conn);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_its_status_t psa_its_reset()
|
||||||
|
{
|
||||||
|
psa_handle_t conn = psa_connect(PSA_ITS_RESET, 1);
|
||||||
|
if (conn <= PSA_NULL_HANDLE) {
|
||||||
|
return PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t status = psa_call(conn, NULL, 0, NULL, 0);
|
||||||
if (status == PSA_DROP_CONNECTION) {
|
if (status == PSA_DROP_CONNECTION) {
|
||||||
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
status = PSA_ITS_ERROR_STORAGE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -100,6 +100,18 @@ spm_rot_service_t its_rot_services[ITS_ROT_SRV_COUNT] = {
|
||||||
.tail = NULL
|
.tail = NULL
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.sid = PSA_ITS_RESET,
|
||||||
|
.mask = PSA_ITS_RESET_MSK,
|
||||||
|
.partition = NULL,
|
||||||
|
.min_version = 1,
|
||||||
|
.min_version_policy = PSA_MINOR_VERSION_POLICY_RELAXED,
|
||||||
|
.allow_nspe = false,
|
||||||
|
.queue = {
|
||||||
|
.head = NULL,
|
||||||
|
.tail = NULL
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,3 +147,4 @@ void its_init(spm_partition_t *partition)
|
||||||
SPM_PANIC("Failed to create start main thread of partition its!\n");
|
SPM_PANIC("Failed to create start main thread of partition its!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "cmsis_os2.h"
|
#include "psa/client.h"
|
||||||
#include "spm_server.h"
|
#include "psa/service.h"
|
||||||
#include "spm_panic.h"
|
|
||||||
#include "psa_its_partition.h"
|
#include "psa_its_partition.h"
|
||||||
#include "psa_prot_internal_storage.h"
|
#include "psa/internal_trusted_storage.h"
|
||||||
#include "pits_impl.h"
|
#include "pits_impl.h"
|
||||||
#include "kv_config.h"
|
#include "kv_config.h"
|
||||||
#include "mbed_error.h"
|
#include "mbed_error.h"
|
||||||
|
@ -30,11 +29,11 @@ extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef psa_error_t (*SignalHandler)(psa_msg_t *);
|
typedef psa_status_t (*SignalHandler)(psa_msg_t *);
|
||||||
|
|
||||||
static psa_error_t storage_set(psa_msg_t *msg)
|
static psa_status_t storage_set(psa_msg_t *msg)
|
||||||
{
|
{
|
||||||
uint32_t key = 0;
|
psa_its_uid_t key = 0;
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
uint32_t alloc_size = msg->in_size[1];
|
uint32_t alloc_size = msg->in_size[1];
|
||||||
psa_its_create_flags_t flags = 0;
|
psa_its_create_flags_t flags = 0;
|
||||||
|
@ -68,9 +67,9 @@ static psa_error_t storage_set(psa_msg_t *msg)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_error_t storage_get(psa_msg_t *msg)
|
static psa_status_t storage_get(psa_msg_t *msg)
|
||||||
{
|
{
|
||||||
uint32_t key = 0;
|
psa_its_uid_t key = 0;
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
|
|
||||||
if ((msg->in_size[0] != sizeof(key)) || (msg->in_size[1] != sizeof(offset))) {
|
if ((msg->in_size[0] != sizeof(key)) || (msg->in_size[1] != sizeof(offset))) {
|
||||||
|
@ -100,10 +99,10 @@ static psa_error_t storage_get(psa_msg_t *msg)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_error_t storage_info(psa_msg_t *msg)
|
static psa_status_t storage_info(psa_msg_t *msg)
|
||||||
{
|
{
|
||||||
struct psa_its_info_t info = { 0 };
|
struct psa_its_info_t info = { 0 };
|
||||||
uint32_t key = 0;
|
psa_its_uid_t key = 0;
|
||||||
|
|
||||||
if ((msg->in_size[0] != sizeof(key)) || (msg->out_size[0] != sizeof(info))) {
|
if ((msg->in_size[0] != sizeof(key)) || (msg->out_size[0] != sizeof(info))) {
|
||||||
return PSA_DROP_CONNECTION;
|
return PSA_DROP_CONNECTION;
|
||||||
|
@ -121,9 +120,9 @@ static psa_error_t storage_info(psa_msg_t *msg)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_error_t storage_remove(psa_msg_t *msg)
|
static psa_status_t storage_remove(psa_msg_t *msg)
|
||||||
{
|
{
|
||||||
uint32_t key = 0;
|
psa_its_uid_t key = 0;
|
||||||
|
|
||||||
if (msg->in_size[0] != sizeof(key)) {
|
if (msg->in_size[0] != sizeof(key)) {
|
||||||
return PSA_DROP_CONNECTION;
|
return PSA_DROP_CONNECTION;
|
||||||
|
@ -136,9 +135,15 @@ static psa_error_t storage_remove(psa_msg_t *msg)
|
||||||
return psa_its_remove_impl(psa_identity(msg->handle), key);
|
return psa_its_remove_impl(psa_identity(msg->handle), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static psa_status_t storage_reset(psa_msg_t *msg)
|
||||||
|
{
|
||||||
|
(void)msg;
|
||||||
|
return psa_its_reset_impl();
|
||||||
|
}
|
||||||
|
|
||||||
static void message_handler(psa_msg_t *msg, SignalHandler handler)
|
static void message_handler(psa_msg_t *msg, SignalHandler handler)
|
||||||
{
|
{
|
||||||
psa_error_t status = PSA_SUCCESS;
|
psa_status_t status = PSA_SUCCESS;
|
||||||
switch (msg->type) {
|
switch (msg->type) {
|
||||||
case PSA_IPC_CONNECT: //fallthrough
|
case PSA_IPC_CONNECT: //fallthrough
|
||||||
case PSA_IPC_DISCONNECT: {
|
case PSA_IPC_DISCONNECT: {
|
||||||
|
@ -188,6 +193,10 @@ void pits_entry(void *ptr)
|
||||||
psa_get(PSA_ITS_REMOVE_MSK, &msg);
|
psa_get(PSA_ITS_REMOVE_MSK, &msg);
|
||||||
message_handler(&msg, storage_remove);
|
message_handler(&msg, storage_remove);
|
||||||
}
|
}
|
||||||
|
if ((signals & PSA_ITS_RESET_MSK) != 0) {
|
||||||
|
psa_get(PSA_ITS_RESET_MSK, &msg);
|
||||||
|
message_handler(&msg, storage_reset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2018 ARM Limited
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#define ITS_ID 10
|
#define ITS_ID 10
|
||||||
|
|
||||||
#define ITS_ROT_SRV_COUNT (4UL)
|
#define ITS_ROT_SRV_COUNT (5UL)
|
||||||
#define ITS_EXT_ROT_SRV_COUNT (0UL)
|
#define ITS_EXT_ROT_SRV_COUNT (0UL)
|
||||||
|
|
||||||
/* ITS event flags */
|
/* ITS event flags */
|
||||||
|
@ -48,12 +48,15 @@
|
||||||
#define PSA_ITS_INFO_MSK (1UL << PSA_ITS_INFO_MSK_POS)
|
#define PSA_ITS_INFO_MSK (1UL << PSA_ITS_INFO_MSK_POS)
|
||||||
#define PSA_ITS_REMOVE_MSK_POS (7UL)
|
#define PSA_ITS_REMOVE_MSK_POS (7UL)
|
||||||
#define PSA_ITS_REMOVE_MSK (1UL << PSA_ITS_REMOVE_MSK_POS)
|
#define PSA_ITS_REMOVE_MSK (1UL << PSA_ITS_REMOVE_MSK_POS)
|
||||||
|
#define PSA_ITS_RESET_MSK_POS (8UL)
|
||||||
|
#define PSA_ITS_RESET_MSK (1UL << PSA_ITS_RESET_MSK_POS)
|
||||||
|
|
||||||
#define ITS_WAIT_ANY_SID_MSK (\
|
#define ITS_WAIT_ANY_SID_MSK (\
|
||||||
PSA_ITS_GET_MSK | \
|
PSA_ITS_GET_MSK | \
|
||||||
PSA_ITS_SET_MSK | \
|
PSA_ITS_SET_MSK | \
|
||||||
PSA_ITS_INFO_MSK | \
|
PSA_ITS_INFO_MSK | \
|
||||||
PSA_ITS_REMOVE_MSK)
|
PSA_ITS_REMOVE_MSK | \
|
||||||
|
PSA_ITS_RESET_MSK)
|
||||||
|
|
||||||
|
|
||||||
#endif // PSA_ITS_PARTITION_H
|
#endif // PSA_ITS_PARTITION_H
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue