Skip to content

Commit a890043

Browse files
committed
crypto: Add IPC for psa_copy_key()
1 parent 0261934 commit a890043

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

components/TARGET_PSA/services/crypto/COMPONENT_PSA_SRV_IPC/crypto_platform_spe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ typedef enum psa_sec_function_s {
4747
PSA_DESTROY_KEY,
4848
PSA_EXPORT_KEY,
4949
PSA_EXPORT_PUBLIC_KEY,
50+
PSA_COPY_KEY,
5051
PSA_HASH_COMPUTE,
5152
PSA_HASH_COMPARE,
5253
PSA_HASH_SETUP,

components/TARGET_PSA/services/crypto/COMPONENT_PSA_SRV_IPC/psa_crypto_spm.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,22 @@ psa_status_t psa_export_public_key(psa_key_handle_t handle,
253253
return (status);
254254
}
255255

256+
psa_status_t psa_copy_key(psa_key_handle_t source_handle,
257+
const psa_key_attributes_t *attributes,
258+
psa_key_handle_t *target_handle)
259+
{
260+
psa_key_mng_ipc_t psa_key_mng_ipc = {
261+
.func = PSA_COPY_KEY,
262+
.handle = source_handle,
263+
};
264+
265+
psa_invec in_vec = { &psa_key_mng_ipc, sizeof(psa_key_mng_ipc) };
266+
267+
psa_outvec out_vec = { target_handle, sizeof(*target_handle) };
268+
269+
return ipc_oneshot(PSA_KEY_MNG_ID, &in_vec, 1, &out_vec, 1);
270+
}
271+
256272
psa_status_t psa_hash_compute(psa_algorithm_t alg,
257273
const uint8_t *input,
258274
size_t input_length,

components/TARGET_PSA/services/crypto/COMPONENT_SPE/crypto_spe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern "C" {
2121
#define psa_destroy_key psa_sec_destroy_key
2222
#define psa_export_key psa_sec_export_key
2323
#define psa_export_public_key psa_sec_export_public_key
24+
#define psa_copy_key psa_sec_copy_key
2425
#define psa_hash_compute psa_sec_hash_compute
2526
#define psa_hash_compare psa_sec_hash_compare
2627
#define psa_hash_setup psa_sec_hash_setup

components/TARGET_PSA/services/crypto/COMPONENT_SPE/psa_crypto_partition.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,26 @@ static void psa_key_management_operation(void)
19861986
break;
19871987
}
19881988

1989+
case PSA_COPY_KEY: {
1990+
psa_key_handle_t target_handle;
1991+
psa_key_attributes_t attributes;
1992+
1993+
if (!psa_crypto_access_control_is_handle_permitted(psa_key_mng.handle, partition_id)) {
1994+
status = PSA_ERROR_INVALID_HANDLE;
1995+
break;
1996+
}
1997+
1998+
/* Read in attributes. */
1999+
read_attributes(msg.handle, msg.client_id, &attributes);
2000+
2001+
status = psa_copy_key(psa_key_mng.handle, &attributes, &target_handle);
2002+
if (status == PSA_SUCCESS) {
2003+
psa_crypto_access_control_register_handle(target_handle, partition_id);
2004+
psa_write(msg.handle, 0, &target_handle, sizeof(target_handle));
2005+
}
2006+
break;
2007+
}
2008+
19892009
case PSA_GENERATE_KEY: {
19902010
psa_key_attributes_t attributes;
19912011
psa_key_handle_t handle;

0 commit comments

Comments
 (0)