Skip to content

Commit 71b69fd

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 47b0b9b commit 71b69fd

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
@@ -395,7 +395,7 @@ psa_status_t rnd_in_range(uint8_t *n, size_t sz, const uint8_t *upperlimit, size
395395
msb_mask = ~msb_mask;
396396

397397
while (retries++ < retry_limit) {
398-
psa_status_t status = psa_generate_random(n, sz);
398+
psa_status_t status = cracen_get_random(NULL, n, sz);
399399

400400
if (status) {
401401
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
@@ -1167,7 +1167,8 @@ psa_status_t generate_key_for_kmu(const psa_key_attributes_t *attributes, uint8_
11671167
}
11681168
} else if (key_type == PSA_KEY_TYPE_AES || key_type == PSA_KEY_TYPE_HMAC ||
11691169
key_type == PSA_KEY_TYPE_CHACHA20) {
1170-
status = psa_generate_random(key, PSA_BITS_TO_BYTES(psa_get_key_bits(attributes)));
1170+
status = cracen_get_random(NULL, key,
1171+
PSA_BITS_TO_BYTES(psa_get_key_bits(attributes)));
11711172
if (status != PSA_SUCCESS) {
11721173
return status;
11731174
}

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)