27
27
#define mbedtls_free free
28
28
#endif
29
29
30
+ #include "mbed_assert.h"
31
+
30
32
// -------------------------------- Structures ---------------------------------
31
33
typedef struct psa_spm_hash_clone_s {
32
34
int32_t partition_id ;
@@ -42,6 +44,9 @@ static int psa_spm_init_refence_counter = 0;
42
44
#endif
43
45
static psa_spm_hash_clone_t psa_spm_hash_clones [MAX_CONCURRENT_HASH_CLONES ];
44
46
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
+
45
50
// ------------------------- Internal Helper Functions -------------------------
46
51
static inline psa_status_t reserve_hash_clone (int32_t partition_id , void * source_operation , size_t * index )
47
52
{
@@ -1176,13 +1181,18 @@ static void psa_key_management_operation(void)
1176
1181
}
1177
1182
1178
1183
case PSA_CREATE_KEY : {
1179
- psa_key_id_t id = 0 ;
1184
+ psa_key_id_t id ;
1185
+ id .owner = psa_identity (msg .handle );
1180
1186
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 ]);
1182
1188
if (bytes_read != msg .in_size [1 ]) {
1183
1189
SPM_PANIC ("SPM read length mismatch" );
1184
1190
}
1185
1191
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
+
1186
1196
status = psa_create_key (psa_key_mng .lifetime , id , & psa_key_mng .handle );
1187
1197
if (status == PSA_SUCCESS ) {
1188
1198
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)
1191
1201
}
1192
1202
1193
1203
case PSA_OPEN_KEY : {
1194
- psa_key_id_t id = 0 ;
1204
+ psa_key_id_t id ;
1205
+ id .owner = psa_identity (msg .handle );
1195
1206
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 ]);
1197
1208
if (bytes_read != msg .in_size [1 ]) {
1198
1209
SPM_PANIC ("SPM read length mismatch" );
1199
1210
}
1200
1211
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
+
1201
1216
status = psa_open_key (psa_key_mng .lifetime , id , & psa_key_mng .handle );
1202
1217
if (status == PSA_SUCCESS ) {
1203
1218
psa_write (msg .handle , 0 , & psa_key_mng .handle , sizeof (psa_key_mng .handle ));
0 commit comments