Skip to content

Commit cc87cb0

Browse files
committed
nrf_security: Avoid psa_generate_random inside CRACEN driver
Change all the psa_generate_random calls to call the driver directly (cracen_get_random). This makes it more consistent with the rest of the driver. It is also a better practice to stay on the same levels of APIs and avoid calling APIs in higher levels. Signed-off-by: Georgios Vasilakis <[email protected]>
1 parent 9497c45 commit cc87cb0

File tree

5 files changed

+6
-5
lines changed

5 files changed

+6
-5
lines changed

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ psa_status_t rnd_in_range(uint8_t *n, size_t sz, const uint8_t *upperlimit, size
408408
msb_mask = ~msb_mask;
409409

410410
while (retries++ < retry_limit) {
411-
psa_status_t status = psa_generate_random(n, sz);
411+
psa_status_t status = cracen_get_random(NULL, n, sz);
412412

413413
if (status) {
414414
return status;

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ int cracen_signature_get_rsa_key(struct cracen_rsa_key *rsa, bool extract_pubkey
150150
int cracen_signature_asn1_get_operand(uint8_t **p, const uint8_t *end, struct sx_buf *op);
151151

152152
/**
153-
* @brief Use psa_generate_random up to generate a random number in the range [1, upperlimit).
153+
* @brief Use cracen_get_random up to generate a random number in the range [1, upperlimit).
154154
*
155155
* @param[out] n Output number.
156156
* @param[in] sz Size of number in bytes.

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/key_management.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,8 @@ psa_status_t generate_key_for_kmu(const psa_key_attributes_t *attributes, uint8_
11971197
}
11981198
} else if (key_type == PSA_KEY_TYPE_AES || key_type == PSA_KEY_TYPE_HMAC ||
11991199
key_type == PSA_KEY_TYPE_CHACHA20) {
1200-
status = psa_generate_random(key, PSA_BITS_TO_BYTES(psa_get_key_bits(attributes)));
1200+
status = cracen_get_random(NULL, key,
1201+
PSA_BITS_TO_BYTES(psa_get_key_bits(attributes)));
12011202
if (status != PSA_SUCCESS) {
12021203
return status;
12031204
}

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/kmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static psa_status_t cracen_kmu_encrypt(const uint8_t *key, size_t key_length,
159159
psa_set_key_usage_flags(&attr, PSA_KEY_USAGE_ENCRYPT);
160160

161161
if (encrypted_buffer_size > CRACEN_KMU_SLOT_KEY_SIZE) {
162-
psa_status = psa_generate_random(encrypted_buffer, CRACEN_KMU_SLOT_KEY_SIZE);
162+
psa_status = cracen_get_random(NULL, encrypted_buffer, CRACEN_KMU_SLOT_KEY_SIZE);
163163
} else {
164164
return PSA_ERROR_GENERIC_ERROR;
165165
}

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/spake2p.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ static psa_status_t cracen_write_key_share(cracen_spake2p_operation_t *operation
443443
}
444444
}
445445

446-
status = psa_generate_random(xs, sizeof(xs));
446+
status = cracen_get_random(NULL, xs, sizeof(xs));
447447
if (status != PSA_SUCCESS) {
448448
return status;
449449
}

0 commit comments

Comments
 (0)