Skip to content

Commit 8195944

Browse files
committed
Refactor trng_get_bytes()
1 parent b9ea334 commit 8195944

File tree

1 file changed

+8
-9
lines changed
  • features/mbedtls/platform/TARGET_PSA/COMPONENT_NSPE/src

1 file changed

+8
-9
lines changed

features/mbedtls/platform/TARGET_PSA/COMPONENT_NSPE/src/psa_hrng.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,23 @@ MBED_WEAK void trng_free(trng_t *obj)
3434

3535
MBED_WEAK int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
3636
{
37-
if (output == NULL){
37+
((void)(obj));
38+
if (output == NULL || output_length == NULL){
3839
return -1;
3940
}
4041

41-
if(psa_crypto_init() != PSA_SUCCESS) {
42+
psa_status_t status = psa_crypto_init();
43+
if(status != PSA_SUCCESS) {
4244
return -1;
4345
}
4446

45-
if (psa_generate_random(output, length) != PSA_SUCCESS) {
47+
status = psa_generate_random(output, length);
48+
mbedtls_psa_crypto_free();
49+
if (status != PSA_SUCCESS) {
4650
return -1;
4751
}
4852

49-
mbedtls_psa_crypto_free();
50-
51-
((void)(obj));
52-
if (output_length != NULL) {
53-
*output_length = length;
54-
}
53+
*output_length = length;
5554

5655
return 0;
5756
}

0 commit comments

Comments
 (0)