Skip to content

Commit 7deeffa

Browse files
author
itayzafrir
committed
crypto service: Assemble bit crypto key ids
1 parent 19e3ca0 commit 7deeffa

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#define mbedtls_free free
2828
#endif
2929

30+
#include "mbed_assert.h"
31+
3032
// -------------------------------- Structures ---------------------------------
3133
typedef struct psa_spm_hash_clone_s {
3234
int32_t partition_id;
@@ -42,6 +44,9 @@ static int psa_spm_init_refence_counter = 0;
4244
#endif
4345
static psa_spm_hash_clone_t psa_spm_hash_clones[MAX_CONCURRENT_HASH_CLONES];
4446

47+
#define CLIENT_PSA_KEY_ID_SIZE_IN_BYTES 4
48+
MBED_STATIC_ASSERT(sizeof(psa_key_id_t) != CLIENT_PSA_KEY_ID_SIZE_IN_BYTES, "Unexpected psa_key_id_t size");
49+
4550
// ------------------------- Internal Helper Functions -------------------------
4651
static inline psa_status_t reserve_hash_clone(int32_t partition_id, void *source_operation, size_t *index)
4752
{
@@ -1176,13 +1181,18 @@ static void psa_key_management_operation(void)
11761181
}
11771182

11781183
case PSA_CREATE_KEY: {
1179-
psa_key_id_t id = 0;
1184+
psa_key_id_t id;
1185+
id.owner = psa_identity(msg.handle);
11801186

1181-
bytes_read = psa_read(msg.handle, 1, &id, msg.in_size[1]);
1187+
bytes_read = psa_read(msg.handle, 1, &(id.key_id), msg.in_size[1]);
11821188
if (bytes_read != msg.in_size[1]) {
11831189
SPM_PANIC("SPM read length mismatch");
11841190
}
11851191

1192+
if (msg.in_size[1] != CLIENT_PSA_KEY_ID_SIZE_IN_BYTES) {
1193+
SPM_PANIC("Unexpected psa_key_id_t size received from client");
1194+
}
1195+
11861196
status = psa_create_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
11871197
if (status == PSA_SUCCESS) {
11881198
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
@@ -1191,13 +1201,18 @@ static void psa_key_management_operation(void)
11911201
}
11921202

11931203
case PSA_OPEN_KEY: {
1194-
psa_key_id_t id = 0;
1204+
psa_key_id_t id;
1205+
id.owner = psa_identity(msg.handle);
11951206

1196-
bytes_read = psa_read(msg.handle, 1, &id, msg.in_size[1]);
1207+
bytes_read = psa_read(msg.handle, 1, &(id.key_id), msg.in_size[1]);
11971208
if (bytes_read != msg.in_size[1]) {
11981209
SPM_PANIC("SPM read length mismatch");
11991210
}
12001211

1212+
if (msg.in_size[1] != CLIENT_PSA_KEY_ID_SIZE_IN_BYTES) {
1213+
SPM_PANIC("Unexpected psa_key_id_t size received from client");
1214+
}
1215+
12011216
status = psa_open_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
12021217
if (status == PSA_SUCCESS) {
12031218
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));

0 commit comments

Comments
 (0)