Skip to content

Commit

Permalink
nrf_security: cracen_kmu: rename kmu_src_t and make number less magic
Browse files Browse the repository at this point in the history
Rename struct kmu_src_t to kmu_src because its

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
  • Loading branch information
tomi-font committed Oct 16, 2024
1 parent 9c54b18 commit 9a1b4a7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ enum lib_kmu_rev_policy {
/**
* @brief Source struct for KMU slot provisioning.
*/
struct kmu_src_t {
struct kmu_src {
/** Asset contents/value. */
uint32_t value[4];
/** Revocation policy. */
Expand All @@ -81,7 +81,7 @@ struct kmu_src_t {
* @return -LIB_KMU_ERROR If the operation returned an error.
* @return -LIB_KMU_NULL_POINTER If the KMU source is NULL.
*/
int lib_kmu_provision_slot(int slot_id, struct kmu_src_t *kmu_src);
int lib_kmu_provision_slot(int slot_id, struct kmu_src *kmu_src);

/** @brief Push the KMU slot to its destination address.
*
Expand Down
12 changes: 7 additions & 5 deletions subsys/nrf_security/src/drivers/cracen/cracenpsa/src/kmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*/
#define PROVISIONING_SLOT 250

#define SECONDARY_SLOT_METADATA_VALUE UINT32_MAX

extern mbedtls_threading_mutex_t cracen_mutex_symmetric;

/* The section .nrf_kmu_reserved_push_area is placed at the top RAM address
Expand Down Expand Up @@ -238,9 +240,9 @@ int cracen_kmu_clean_key(const uint8_t *user_data)
*/
static bool is_secondary_slot(kmu_metadata *metadata)
{
uint32_t value = UINT32_MAX;
_Static_assert(sizeof(value) == sizeof(*metadata));
const uint32_t value = SECONDARY_SLOT_METADATA_VALUE;

_Static_assert(sizeof(value) == sizeof(*metadata));
return memcmp(&value, metadata, sizeof(value)) == 0;
}

Expand Down Expand Up @@ -306,7 +308,7 @@ static psa_status_t clean_up_unfinished_provisioning(void)
*/
static psa_status_t set_provisioning_in_progress(uint32_t slot_id, uint32_t num_slots)
{
struct kmu_src_t kmu_desc = {};
struct kmu_src kmu_desc = {};

kmu_desc.metadata = slot_id << 8 | num_slots;
kmu_desc.rpolicy = LIB_KMU_REV_POLICY_ROTATING;
Expand Down Expand Up @@ -774,14 +776,14 @@ psa_status_t cracen_kmu_provision(const psa_key_attributes_t *key_attr, int slot
}
}

struct kmu_src_t kmu_desc = {};
struct kmu_src kmu_desc = {};

for (size_t i = 0; i < num_slots; i++) {
kmu_desc.dest = (uint32_t)push_address + (CRACEN_KMU_SLOT_KEY_SIZE * i);
if (i == 0) {
memcpy(&kmu_desc.metadata, &metadata, sizeof(kmu_desc.metadata));
} else {
kmu_desc.metadata = UINT32_MAX;
kmu_desc.metadata = SECONDARY_SLOT_METADATA_VALUE;
}
kmu_desc.rpolicy = metadata.rpolicy;
memcpy(kmu_desc.value, key_buffer + CRACEN_KMU_SLOT_KEY_SIZE * i,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int trigger_task_and_wait_for_event_or_error(volatile uint32_t *task,
return result;
}

int lib_kmu_provision_slot(int slot_id, struct kmu_src_t *kmu_src)
int lib_kmu_provision_slot(int slot_id, struct kmu_src *kmu_src)
{
if (kmu_src == NULL) {
return -LIB_KMU_NULL_PNT;
Expand Down

0 comments on commit 9a1b4a7

Please sign in to comment.