Skip to content

Commit 3992b83

Browse files
author
itayzafrir
committed
crypto service: Assemble bit crypto key ids
1 parent 2b9b294 commit 3992b83

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
// ---------------------------------- Macros -----------------------------------
3133
#if !defined(MIN)
3234
#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
@@ -53,6 +55,9 @@ the data will be read in chunks of size */
5355
#endif
5456
static psa_spm_hash_clone_t psa_spm_hash_clones[MAX_CONCURRENT_HASH_CLONES];
5557

58+
#define CLIENT_PSA_KEY_ID_SIZE_IN_BYTES 4
59+
MBED_STATIC_ASSERT(sizeof(psa_key_id_t) != CLIENT_PSA_KEY_ID_SIZE_IN_BYTES, "Unexpected psa_key_id_t size");
60+
5661
// ------------------------- Internal Helper Functions -------------------------
5762
static inline psa_status_t reserve_hash_clone(int32_t partition_id, void *source_operation, size_t *index)
5863
{
@@ -1217,13 +1222,18 @@ static void psa_key_management_operation(void)
12171222
}
12181223

12191224
case PSA_CREATE_KEY: {
1220-
psa_key_id_t id = 0;
1225+
psa_key_id_t id;
1226+
id.owner = psa_identity(msg.handle);
12211227

1222-
bytes_read = psa_read(msg.handle, 1, &id, msg.in_size[1]);
1228+
bytes_read = psa_read(msg.handle, 1, &(id.key_id), msg.in_size[1]);
12231229
if (bytes_read != msg.in_size[1]) {
12241230
SPM_PANIC("SPM read length mismatch");
12251231
}
12261232

1233+
if (msg.in_size[1] != CLIENT_PSA_KEY_ID_SIZE_IN_BYTES) {
1234+
SPM_PANIC("Unexpected psa_key_id_t size received from client");
1235+
}
1236+
12271237
status = psa_create_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
12281238
if (status == PSA_SUCCESS) {
12291239
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
@@ -1232,13 +1242,18 @@ static void psa_key_management_operation(void)
12321242
}
12331243

12341244
case PSA_OPEN_KEY: {
1235-
psa_key_id_t id = 0;
1245+
psa_key_id_t id;
1246+
id.owner = psa_identity(msg.handle);
12361247

1237-
bytes_read = psa_read(msg.handle, 1, &id, msg.in_size[1]);
1248+
bytes_read = psa_read(msg.handle, 1, &(id.key_id), msg.in_size[1]);
12381249
if (bytes_read != msg.in_size[1]) {
12391250
SPM_PANIC("SPM read length mismatch");
12401251
}
12411252

1253+
if (msg.in_size[1] != CLIENT_PSA_KEY_ID_SIZE_IN_BYTES) {
1254+
SPM_PANIC("Unexpected psa_key_id_t size received from client");
1255+
}
1256+
12421257
status = psa_open_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
12431258
if (status == PSA_SUCCESS) {
12441259
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));

0 commit comments

Comments
 (0)