27
27
#define mbedtls_free free
28
28
#endif
29
29
30
+ #include "mbed_assert.h"
31
+
30
32
// ---------------------------------- Macros -----------------------------------
31
33
#if !defined(MIN )
32
34
#define MIN ( a , b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
@@ -53,6 +55,9 @@ the data will be read in chunks of size */
53
55
#endif
54
56
static psa_spm_hash_clone_t psa_spm_hash_clones [MAX_CONCURRENT_HASH_CLONES ];
55
57
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
+
56
61
// ------------------------- Internal Helper Functions -------------------------
57
62
static inline psa_status_t reserve_hash_clone (int32_t partition_id , void * source_operation , size_t * index )
58
63
{
@@ -1217,13 +1222,18 @@ static void psa_key_management_operation(void)
1217
1222
}
1218
1223
1219
1224
case PSA_CREATE_KEY : {
1220
- psa_key_id_t id = 0 ;
1225
+ psa_key_id_t id ;
1226
+ id .owner = psa_identity (msg .handle );
1221
1227
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 ]);
1223
1229
if (bytes_read != msg .in_size [1 ]) {
1224
1230
SPM_PANIC ("SPM read length mismatch" );
1225
1231
}
1226
1232
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
+
1227
1237
status = psa_create_key (psa_key_mng .lifetime , id , & psa_key_mng .handle );
1228
1238
if (status == PSA_SUCCESS ) {
1229
1239
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)
1232
1242
}
1233
1243
1234
1244
case PSA_OPEN_KEY : {
1235
- psa_key_id_t id = 0 ;
1245
+ psa_key_id_t id ;
1246
+ id .owner = psa_identity (msg .handle );
1236
1247
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 ]);
1238
1249
if (bytes_read != msg .in_size [1 ]) {
1239
1250
SPM_PANIC ("SPM read length mismatch" );
1240
1251
}
1241
1252
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
+
1242
1257
status = psa_open_key (psa_key_mng .lifetime , id , & psa_key_mng .handle );
1243
1258
if (status == PSA_SUCCESS ) {
1244
1259
psa_write (msg .handle , 0 , & psa_key_mng .handle , sizeof (psa_key_mng .handle ));
0 commit comments