crypto: Add IPC for psa_copy_key()

pull/11315/head
Jaeden Amero 2019-08-21 15:46:13 +01:00
parent 4eb4b32910
commit 3e53118727
4 changed files with 38 additions and 0 deletions

View File

@ -47,6 +47,7 @@ typedef enum psa_sec_function_s {
PSA_DESTROY_KEY,
PSA_EXPORT_KEY,
PSA_EXPORT_PUBLIC_KEY,
PSA_COPY_KEY,
PSA_HASH_COMPUTE,
PSA_HASH_COMPARE,
PSA_HASH_SETUP,

View File

@ -253,6 +253,22 @@ psa_status_t psa_export_public_key(psa_key_handle_t handle,
return (status);
}
psa_status_t psa_copy_key(psa_key_handle_t source_handle,
const psa_key_attributes_t *attributes,
psa_key_handle_t *target_handle)
{
psa_key_mng_ipc_t psa_key_mng_ipc = {
.func = PSA_COPY_KEY,
.handle = source_handle,
};
psa_invec in_vec = { &psa_key_mng_ipc, sizeof(psa_key_mng_ipc) };
psa_outvec out_vec = { target_handle, sizeof(*target_handle) };
return ipc_oneshot(PSA_KEY_MNG_ID, &in_vec, 1, &out_vec, 1);
}
psa_status_t psa_hash_compute(psa_algorithm_t alg,
const uint8_t *input,
size_t input_length,

View File

@ -21,6 +21,7 @@ extern "C" {
#define psa_destroy_key psa_sec_destroy_key
#define psa_export_key psa_sec_export_key
#define psa_export_public_key psa_sec_export_public_key
#define psa_copy_key psa_sec_copy_key
#define psa_hash_compute psa_sec_hash_compute
#define psa_hash_compare psa_sec_hash_compare
#define psa_hash_setup psa_sec_hash_setup

View File

@ -1986,6 +1986,26 @@ static void psa_key_management_operation(void)
break;
}
case PSA_COPY_KEY: {
psa_key_handle_t target_handle;
psa_key_attributes_t attributes;
if (!psa_crypto_access_control_is_handle_permitted(psa_key_mng.handle, partition_id)) {
status = PSA_ERROR_INVALID_HANDLE;
break;
}
/* Read in attributes. */
read_attributes(msg.handle, msg.client_id, &attributes);
status = psa_copy_key(psa_key_mng.handle, &attributes, &target_handle);
if (status == PSA_SUCCESS) {
psa_crypto_access_control_register_handle(target_handle, partition_id);
psa_write(msg.handle, 0, &target_handle, sizeof(target_handle));
}
break;
}
case PSA_GENERATE_KEY: {
psa_key_attributes_t attributes;
psa_key_handle_t handle;