Ensure the module is initialized in psa_generate_random
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index dfbb680..01dbf3c 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -148,6 +148,10 @@
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_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 ) );
}