mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Ensure the module is initialized in psa_generate_random
This commit is contained in:
@ -148,6 +148,10 @@ typedef struct
|
||||
|
||||
static psa_global_data_t global_data;
|
||||
|
||||
#define GUARD_MODULE_INITIALIZED \
|
||||
if( global_data.initialized == 0 ) \
|
||||
return( PSA_ERROR_BAD_STATE );
|
||||
|
||||
static psa_status_t mbedtls_to_psa_error( int ret )
|
||||
{
|
||||
/* If there's both a high-level code and low-level code, dispatch on
|
||||
@ -3360,8 +3364,10 @@ psa_status_t psa_key_derivation( psa_crypto_generator_t *generator,
|
||||
psa_status_t psa_generate_random( uint8_t *output,
|
||||
size_t output_size )
|
||||
{
|
||||
int ret = mbedtls_ctr_drbg_random( &global_data.ctr_drbg,
|
||||
output, output_size );
|
||||
int ret;
|
||||
GUARD_MODULE_INITIALIZED;
|
||||
|
||||
ret = mbedtls_ctr_drbg_random( &global_data.ctr_drbg, output, output_size );
|
||||
return( mbedtls_to_psa_error( ret ) );
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user