Add utility function to check for drivers init
This will be used in the next commit.
While at it, move driver initialization before RNG init - this will be
handy when the entropy module wants to use drivers for hashes.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index ba204f7..46938ea 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -111,6 +111,7 @@
typedef struct {
unsigned initialized : 1;
unsigned rng_state : 2;
+ unsigned drivers_initialized : 1;
mbedtls_psa_random_context_t rng;
} psa_global_data_t;
@@ -125,6 +126,12 @@
if (global_data.initialized == 0) \
return PSA_ERROR_BAD_STATE;
+int psa_can_do_hash(psa_algorithm_t hash_alg)
+{
+ (void) hash_alg;
+ return global_data.drivers_initialized;
+}
+
psa_status_t mbedtls_to_psa_error(int ret)
{
/* Mbed TLS error codes can combine a high-level error code and a
@@ -7124,6 +7131,13 @@
return PSA_SUCCESS;
}
+ /* Init drivers */
+ status = psa_driver_wrapper_init();
+ if (status != PSA_SUCCESS) {
+ goto exit;
+ }
+ global_data.drivers_initialized = 1;
+
/* Initialize and seed the random generator. */
mbedtls_psa_random_init(&global_data.rng);
global_data.rng_state = RNG_INITIALIZED;
@@ -7138,12 +7152,6 @@
goto exit;
}
- /* Init drivers */
- status = psa_driver_wrapper_init();
- if (status != PSA_SUCCESS) {
- goto exit;
- }
-
#if defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS)
status = psa_crypto_load_transaction();
if (status == PSA_SUCCESS) {