mirror of https://github.com/ARMmbed/mbed-os.git
Refactor trng_get_bytes()
parent
b9ea334f1f
commit
819594477c
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue