Refactor trng_get_bytes()

pull/8804/head
Mohammad AboMokh 2018-11-27 12:15:52 +02:00
parent b9ea334f1f
commit 819594477c
1 changed files with 9 additions and 10 deletions

View File

@ -34,25 +34,24 @@ MBED_WEAK void trng_free(trng_t *obj)
MBED_WEAK int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length) MBED_WEAK int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
{ {
if (output == NULL){ ((void)(obj));
if (output == NULL || output_length == NULL){
return -1; return -1;
} }
if(psa_crypto_init() != PSA_SUCCESS) { psa_status_t status = psa_crypto_init();
return -1; if(status != PSA_SUCCESS) {
}
if (psa_generate_random(output, length) != PSA_SUCCESS) {
return -1; return -1;
} }
status = psa_generate_random(output, length);
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
if (status != PSA_SUCCESS) {
((void)(obj)); return -1;
if (output_length != NULL) {
*output_length = length;
} }
*output_length = length;
return 0; return 0;
} }