24
24
#include <stddef.h>
25
25
#include <string.h>
26
26
#include <sxsymcrypt/trng.h>
27
+ #include <sxsymcrypt/keyref.h>
27
28
#include <zephyr/sys/__assert.h>
28
29
#include <zephyr/sys/byteorder.h>
29
30
@@ -1174,6 +1175,29 @@ psa_status_t cracen_generate_key(const psa_key_attributes_t *attributes, uint8_t
1174
1175
return PSA_ERROR_NOT_SUPPORTED ;
1175
1176
}
1176
1177
1178
+ static void cracen_set_ikg_key_buffer (psa_key_attributes_t * attributes ,
1179
+ psa_drv_slot_number_t slot_number , uint8_t * key_buffer )
1180
+ {
1181
+ ikg_opaque_key * ikg_key = (ikg_opaque_key * )key_buffer ;
1182
+
1183
+ switch (slot_number ) {
1184
+ case CRACEN_BUILTIN_IDENTITY_KEY_ID :
1185
+ /* The slot_number is not used with the identity key */
1186
+ break ;
1187
+ case CRACEN_BUILTIN_MKEK_ID :
1188
+ ikg_key -> slot_number = CRACEN_INTERNAL_HW_KEY1_ID ;
1189
+ break ;
1190
+ case CRACEN_BUILTIN_MEXT_ID :
1191
+ ikg_key -> slot_number = CRACEN_INTERNAL_HW_KEY2_ID ;
1192
+ break ;
1193
+ }
1194
+
1195
+ #ifdef CONFIG_PSA_NEED_CRACEN_PLATFORM_KEYS
1196
+ ikg_key -> owner_id = cracen_platform_keys_get_owner (attributes );
1197
+ #else
1198
+ ikg_key -> owner_id = MBEDTLS_SVC_KEY_ID_GET_OWNER_ID (psa_get_key_id (attributes ));
1199
+ #endif
1200
+ }
1177
1201
1178
1202
psa_status_t cracen_get_builtin_key (psa_drv_slot_number_t slot_number ,
1179
1203
psa_key_attributes_t * attributes , uint8_t * key_buffer ,
@@ -1187,7 +1211,7 @@ psa_status_t cracen_get_builtin_key(psa_drv_slot_number_t slot_number,
1187
1211
* attributes, and update the `lifetime` field to be more specific.
1188
1212
*/
1189
1213
switch (slot_number ) {
1190
- case CRACEN_IDENTITY_KEY_SLOT_NUMBER :
1214
+ case CRACEN_BUILTIN_IDENTITY_KEY_ID :
1191
1215
psa_set_key_lifetime (attributes , PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION (
1192
1216
PSA_KEY_PERSISTENCE_READ_ONLY ,
1193
1217
PSA_KEY_LOCATION_CRACEN ));
@@ -1210,18 +1234,15 @@ psa_status_t cracen_get_builtin_key(psa_drv_slot_number_t slot_number,
1210
1234
*/
1211
1235
if (key_buffer_size >= opaque_key_size ) {
1212
1236
* key_buffer_length = opaque_key_size ;
1213
- * ((ikg_opaque_key * )key_buffer ) =
1214
- (ikg_opaque_key ){.slot_number = slot_number ,
1215
- .owner_id = MBEDTLS_SVC_KEY_ID_GET_OWNER_ID (
1216
- psa_get_key_id (attributes ))};
1237
+ cracen_set_ikg_key_buffer (attributes , slot_number , key_buffer );
1217
1238
return PSA_SUCCESS ;
1218
1239
} else {
1219
1240
return PSA_ERROR_BUFFER_TOO_SMALL ;
1220
1241
}
1221
1242
break ;
1222
1243
1223
- case CRACEN_MKEK_SLOT_NUMBER :
1224
- case CRACEN_MEXT_SLOT_NUMBER :
1244
+ case CRACEN_BUILTIN_MKEK_ID :
1245
+ case CRACEN_BUILTIN_MEXT_ID :
1225
1246
psa_set_key_lifetime (attributes , PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION (
1226
1247
PSA_KEY_PERSISTENCE_READ_ONLY ,
1227
1248
PSA_KEY_LOCATION_CRACEN ));
@@ -1240,10 +1261,7 @@ psa_status_t cracen_get_builtin_key(psa_drv_slot_number_t slot_number,
1240
1261
*/
1241
1262
if (key_buffer_size >= opaque_key_size ) {
1242
1263
* key_buffer_length = opaque_key_size ;
1243
- * ((ikg_opaque_key * )key_buffer ) =
1244
- (ikg_opaque_key ){.slot_number = slot_number ,
1245
- .owner_id = MBEDTLS_SVC_KEY_ID_GET_OWNER_ID (
1246
- psa_get_key_id (attributes ))};
1264
+ cracen_set_ikg_key_buffer (attributes , slot_number , key_buffer );
1247
1265
return PSA_SUCCESS ;
1248
1266
} else {
1249
1267
return PSA_ERROR_BUFFER_TOO_SMALL ;
@@ -1266,21 +1284,30 @@ psa_status_t mbedtls_psa_platform_get_builtin_key(mbedtls_svc_key_id_t key_id,
1266
1284
psa_key_lifetime_t * lifetime ,
1267
1285
psa_drv_slot_number_t * slot_number )
1268
1286
{
1287
+ /* For nRF54H20 devices all the builtin keys are considered platform keys,
1288
+ * these include the IKG keys. The IKG keys in these devices don't directly
1289
+ * use the CRACEN_BUILTIN_ ids, they use the IDs defined in the file
1290
+ * nrf_platform_key_ids.h.
1291
+ * The function cracen_platform_get_key_slot will do the matching between the
1292
+ * platform key ids and the Cracen bulitin ids.
1293
+ */
1294
+ #if CONFIG_PSA_NEED_CRACEN_PLATFORM_KEYS
1295
+ return cracen_platform_get_key_slot (key_id , lifetime , slot_number );
1296
+ #else
1297
+
1269
1298
switch (MBEDTLS_SVC_KEY_ID_GET_KEY_ID (key_id )) {
1270
1299
case CRACEN_BUILTIN_IDENTITY_KEY_ID :
1271
- * slot_number = CRACEN_IDENTITY_KEY_SLOT_NUMBER ;
1300
+ * slot_number = CRACEN_BUILTIN_IDENTITY_KEY_ID ;
1272
1301
break ;
1273
1302
case CRACEN_BUILTIN_MKEK_ID :
1274
- * slot_number = CRACEN_MKEK_SLOT_NUMBER ;
1303
+ * slot_number = CRACEN_BUILTIN_MKEK_ID ;
1275
1304
break ;
1276
1305
case CRACEN_BUILTIN_MEXT_ID :
1277
- * slot_number = CRACEN_MEXT_SLOT_NUMBER ;
1306
+ * slot_number = CRACEN_BUILTIN_MEXT_ID ;
1278
1307
break ;
1279
1308
default :
1280
1309
#if CONFIG_PSA_NEED_CRACEN_KMU_DRIVER
1281
1310
return cracen_kmu_get_key_slot (key_id , lifetime , slot_number );
1282
- #elif CONFIG_PSA_NEED_CRACEN_PLATFORM_KEYS
1283
- return cracen_platform_get_key_slot (key_id , lifetime , slot_number );
1284
1311
#else
1285
1312
return PSA_ERROR_DOES_NOT_EXIST ;
1286
1313
#endif
@@ -1290,6 +1317,7 @@ psa_status_t mbedtls_psa_platform_get_builtin_key(mbedtls_svc_key_id_t key_id,
1290
1317
PSA_KEY_LOCATION_CRACEN );
1291
1318
1292
1319
return PSA_SUCCESS ;
1320
+ #endif /* CONFIG_PSA_NEED_CRACEN_PLATFORM_KEYS */
1293
1321
}
1294
1322
1295
1323
psa_status_t cracen_export_key (const psa_key_attributes_t * attributes , const uint8_t * key_buffer ,
0 commit comments