Skip to content

Commit d2947e0

Browse files
author
itayzafrir
committed
crypto service: Assemble 64 bit key ids
1 parent ffc3aa6 commit d2947e0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ static inline psa_status_t get_hash_clone(size_t index, int32_t partition_id,
9797
return PSA_SUCCESS;
9898
}
9999

100+
static inline void assemble_psa_key_id(psa_key_id_t *id, size_t bytes_read, int32_t partition_id)
101+
{
102+
/* move the 32 bit client representation of psa_key_id_t to the upper 32 bits of the 64 bit
103+
* server representation of psa_key_id_t.
104+
* bytes_read is expected to be 4 bytes, as this is the size of psa_key_id_t on the client side. */
105+
*id <<= bytes_read * 8;
106+
/* the lower 32 bits of the server representation of psa_key_id_t represent the calling partition id. */
107+
*id |= (uint32_t)partition_id;
108+
}
109+
100110
// ------------------------- Partition's Main Thread ---------------------------
101111
static void psa_crypto_init_operation(void)
102112
{
@@ -1166,6 +1176,13 @@ static void psa_key_management_operation(void)
11661176
SPM_PANIC("SPM read length mismatch");
11671177
}
11681178

1179+
if (id == 0) {
1180+
status = PSA_ERROR_INVALID_ARGUMENT;
1181+
break;
1182+
}
1183+
1184+
assemble_psa_key_id(&id, msg.in_size[1], psa_identity(msg.handle));
1185+
11691186
status = psa_create_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
11701187
if (status == PSA_SUCCESS) {
11711188
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
@@ -1181,6 +1198,13 @@ static void psa_key_management_operation(void)
11811198
SPM_PANIC("SPM read length mismatch");
11821199
}
11831200

1201+
if (id == 0) {
1202+
status = PSA_ERROR_INVALID_ARGUMENT;
1203+
break;
1204+
}
1205+
1206+
assemble_psa_key_id(&id, msg.in_size[1], psa_identity(msg.handle));
1207+
11841208
status = psa_open_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
11851209
if (status == PSA_SUCCESS) {
11861210
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));

0 commit comments

Comments
 (0)