Crypto: Init drivers first during psa_crypto_init()

Make sure that the patches for mbedcrypto are uniquely numbered
and add a patch to initialise the drivers as first step during
psa_crypto_init().

Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: I95cca2d553a2a287be791c79ee89a814c24e442c
diff --git a/lib/ext/mbedcrypto/0001-BUILD-Update-IAR-support-in-CMakeLists.txt.patch b/lib/ext/mbedcrypto/0001-BUILD-Update-IAR-support-in-CMakeLists.txt.patch
index 674ab56..7b3bf64 100644
--- a/lib/ext/mbedcrypto/0001-BUILD-Update-IAR-support-in-CMakeLists.txt.patch
+++ b/lib/ext/mbedcrypto/0001-BUILD-Update-IAR-support-in-CMakeLists.txt.patch
@@ -1,7 +1,7 @@
-From c0e88bba61a814023032be4f1fabe8aff3deb00c Mon Sep 17 00:00:00 2001
+From a659b34c01ce475f8c780d434ea7e67d47943ed8 Mon Sep 17 00:00:00 2001
 From: TTornblom <thomas.tornblom@iar.com>
 Date: Thu, 16 Apr 2020 13:53:38 +0200
-Subject: [PATCH 1/6] BUILD: Update IAR support in CMakeLists.txt
+Subject: [PATCH 1/9] BUILD: Update IAR support in CMakeLists.txt
 
 Applied the same change as in mbed-crypto for using this as a sub
 project with the IAR toolchain.
diff --git a/lib/ext/mbedcrypto/0002-Enable-crypto-code-sharing-between-independent-binar.patch b/lib/ext/mbedcrypto/0002-Enable-crypto-code-sharing-between-independent-binar.patch
index f965215..28a3b75 100644
--- a/lib/ext/mbedcrypto/0002-Enable-crypto-code-sharing-between-independent-binar.patch
+++ b/lib/ext/mbedcrypto/0002-Enable-crypto-code-sharing-between-independent-binar.patch
@@ -1,7 +1,7 @@
-From 1d8011d0dbd174ffcda57f9977bca8fdccf5aea0 Mon Sep 17 00:00:00 2001
+From 126cca4be08840f832932f71f8e1b872b727e0f8 Mon Sep 17 00:00:00 2001
 From: Tamas Ban <tamas.ban@arm.com>
 Date: Tue, 27 Oct 2020 08:55:37 +0000
-Subject: [PATCH 2/6] Enable crypto code sharing between independent binaries
+Subject: [PATCH 2/9] Enable crypto code sharing between independent binaries
 
 Signed-off-by: Tamas Ban <tamas.ban@arm.com>
 ---
diff --git a/lib/ext/mbedcrypto/0003-Add-MBEDTLS_CHACHA20_C-and-MBEDTLS_POLY1305_C.patch b/lib/ext/mbedcrypto/0003-Add-MBEDTLS_CHACHA20_C-and-MBEDTLS_POLY1305_C.patch
index 98b0421..93e2073 100644
--- a/lib/ext/mbedcrypto/0003-Add-MBEDTLS_CHACHA20_C-and-MBEDTLS_POLY1305_C.patch
+++ b/lib/ext/mbedcrypto/0003-Add-MBEDTLS_CHACHA20_C-and-MBEDTLS_POLY1305_C.patch
@@ -1,7 +1,7 @@
-From 281356afac7b6217a65c87dde490d1b24f625d65 Mon Sep 17 00:00:00 2001
+From 208c9f963b9b35f2df5781436553a78a6c7d3a96 Mon Sep 17 00:00:00 2001
 From: Summer Qin <summer.qin@arm.com>
 Date: Thu, 30 Jun 2022 14:14:11 +0800
-Subject: [PATCH 3/6] Add MBEDTLS_CHACHA20_C and MBEDTLS_POLY1305_C
+Subject: [PATCH 3/9] Add MBEDTLS_CHACHA20_C and MBEDTLS_POLY1305_C
 
 MBEDTLS_CHACHA20_C and MBEDTLS_POLY1305_C are needed when
 PSA_WANT_ALG_CHACHA20_POLY1305 is defined.
diff --git a/lib/ext/mbedcrypto/0004-Driver-wrapper-entry-points-for-CC3XX.patch b/lib/ext/mbedcrypto/0004-Driver-wrapper-entry-points-for-CC3XX.patch
index bf69e64..0a858c7 100644
--- a/lib/ext/mbedcrypto/0004-Driver-wrapper-entry-points-for-CC3XX.patch
+++ b/lib/ext/mbedcrypto/0004-Driver-wrapper-entry-points-for-CC3XX.patch
@@ -1,7 +1,7 @@
-From 5dc86b266f0372a733f03db6d91003f134e1f51f Mon Sep 17 00:00:00 2001
+From 2f96bf29956d2b65c1416ba5bfc02233a17ee3dc Mon Sep 17 00:00:00 2001
 From: Antonio de Angelis <Antonio.deAngelis@arm.com>
 Date: Fri, 15 Jul 2022 12:41:34 +0100
-Subject: [PATCH 4/6] Driver wrapper entry points for CC3XX
+Subject: [PATCH 4/9] Driver wrapper entry points for CC3XX
 
 Manually hardcode PSA driver entry points for the CC3XX driver
 into psa_crypto_driver_wrappers.c (and provide missing entry point
@@ -1066,5 +1066,5 @@
  
  /* End of automatically generated file. */
 -- 
-2.34.1
+2.25.1
 
diff --git a/lib/ext/mbedcrypto/0005-Add-LMS-implementation.patch b/lib/ext/mbedcrypto/0005-Add-LMS-implementation.patch
index 0ce185f..5cb4d57 100644
--- a/lib/ext/mbedcrypto/0005-Add-LMS-implementation.patch
+++ b/lib/ext/mbedcrypto/0005-Add-LMS-implementation.patch
@@ -1,7 +1,7 @@
-From 37bad45c56543a289be7854a8723d9b29c0b8cb2 Mon Sep 17 00:00:00 2001
+From afc821070e7b7a6c634707f1d847b1445101bdd7 Mon Sep 17 00:00:00 2001
 From: Raef Coles <raef.coles@arm.com>
 Date: Wed, 21 Jul 2021 12:42:15 +0100
-Subject: [PATCH 5/6] Add LMS implementation
+Subject: [PATCH 5/9] Add LMS implementation
 
 Also an LM-OTS implementation as one is required for LMS.
 
diff --git a/lib/ext/mbedcrypto/0006-Add-TF-M-builtin-key-driver.patch b/lib/ext/mbedcrypto/0006-Add-TF-M-builtin-key-driver.patch
index eb1c302..559b7b0 100644
--- a/lib/ext/mbedcrypto/0006-Add-TF-M-builtin-key-driver.patch
+++ b/lib/ext/mbedcrypto/0006-Add-TF-M-builtin-key-driver.patch
@@ -1,7 +1,7 @@
-From 5cd10ccea1accf52336d41357135cd1c60728088 Mon Sep 17 00:00:00 2001
+From 1b35e0dc18f952e6198a04116d92f6392e3ade2e Mon Sep 17 00:00:00 2001
 From: Raef Coles <raef.coles@arm.com>
 Date: Tue, 19 Jul 2022 11:12:30 +0100
-Subject: [PATCH 6/6] Add TF-M builtin key driver
+Subject: [PATCH 6/9] Add TF-M builtin key driver
 
 Signed-off-by: Raef Coles <raef.coles@arm.com>
 ---
@@ -39,7 +39,7 @@
          psa_unlock_key_slot( *p_slot );
          *p_slot = NULL;
 diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c
-index 2097db0cb..127e83d5a 100644
+index af8456f6e..4b1a883a7 100644
 --- a/library/psa_crypto_driver_wrappers.c
 +++ b/library/psa_crypto_driver_wrappers.c
 @@ -55,6 +55,18 @@
@@ -82,7 +82,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -230,6 +249,9 @@ psa_status_t psa_driver_wrapper_verify_message(
+@@ -226,6 +245,9 @@ psa_status_t psa_driver_wrapper_verify_message(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -92,7 +92,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -333,6 +355,9 @@ psa_status_t psa_driver_wrapper_sign_hash(
+@@ -325,6 +347,9 @@ psa_status_t psa_driver_wrapper_sign_hash(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -102,7 +102,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -434,6 +459,9 @@ psa_status_t psa_driver_wrapper_verify_hash(
+@@ -421,6 +446,9 @@ psa_status_t psa_driver_wrapper_verify_hash(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -112,7 +112,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -582,7 +610,11 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size(
+@@ -565,7 +593,11 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size(
              return( ( *key_buffer_size != 0 ) ?
                      PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED );
  #endif /* PSA_CRYPTO_DRIVER_TEST */
@@ -125,7 +125,7 @@
          default:
              (void)key_type;
              (void)key_bits;
-@@ -622,6 +654,9 @@ psa_status_t psa_driver_wrapper_generate_key(
+@@ -605,6 +637,9 @@ psa_status_t psa_driver_wrapper_generate_key(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -135,7 +135,7 @@
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
              /* Transparent drivers are limited to generating asymmetric keys */
              if( PSA_KEY_TYPE_IS_ASYMMETRIC( attributes->core.type ) )
-@@ -715,6 +750,9 @@ psa_status_t psa_driver_wrapper_import_key(
+@@ -696,6 +731,9 @@ psa_status_t psa_driver_wrapper_import_key(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -145,7 +145,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -785,6 +823,9 @@ psa_status_t psa_driver_wrapper_export_key(
+@@ -766,6 +804,9 @@ psa_status_t psa_driver_wrapper_export_key(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -155,7 +155,7 @@
              return( psa_export_key_internal( attributes,
                                               key_buffer,
                                               key_buffer_size,
-@@ -843,6 +884,9 @@ psa_status_t psa_driver_wrapper_export_public_key(
+@@ -824,6 +865,9 @@ psa_status_t psa_driver_wrapper_export_public_key(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -165,7 +165,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -915,6 +959,13 @@ psa_status_t psa_driver_wrapper_get_builtin_key(
+@@ -891,6 +935,13 @@ psa_status_t psa_driver_wrapper_get_builtin_key(
                          attributes,
                          key_buffer, key_buffer_size, key_buffer_length ) );
  #endif /* PSA_CRYPTO_DRIVER_TEST */
@@ -179,7 +179,7 @@
          default:
              (void) slot_number;
              (void) key_buffer;
-@@ -991,6 +1042,9 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
+@@ -967,6 +1018,9 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -189,7 +189,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -1097,6 +1151,9 @@ psa_status_t psa_driver_wrapper_cipher_decrypt(
+@@ -1071,6 +1125,9 @@ psa_status_t psa_driver_wrapper_cipher_decrypt(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -199,7 +199,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -1188,6 +1245,9 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
+@@ -1160,6 +1217,9 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -209,7 +209,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -1276,6 +1336,9 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
+@@ -1243,6 +1303,9 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -219,7 +219,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -1755,6 +1818,9 @@ psa_status_t psa_driver_wrapper_aead_encrypt(
+@@ -1726,6 +1789,9 @@ psa_status_t psa_driver_wrapper_aead_encrypt(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -229,7 +229,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  
-@@ -1822,6 +1888,9 @@ psa_status_t psa_driver_wrapper_aead_decrypt(
+@@ -1789,6 +1855,9 @@ psa_status_t psa_driver_wrapper_aead_decrypt(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -239,7 +239,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  
-@@ -1915,6 +1984,9 @@ psa_status_t psa_driver_wrapper_aead_encrypt_setup(
+@@ -1881,6 +1950,9 @@ psa_status_t psa_driver_wrapper_aead_encrypt_setup(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -249,7 +249,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  
-@@ -1974,6 +2046,9 @@ psa_status_t psa_driver_wrapper_aead_decrypt_setup(
+@@ -1938,6 +2010,9 @@ psa_status_t psa_driver_wrapper_aead_decrypt_setup(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -259,7 +259,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  
-@@ -2366,6 +2441,9 @@ psa_status_t psa_driver_wrapper_mac_compute(
+@@ -2335,6 +2410,9 @@ psa_status_t psa_driver_wrapper_mac_compute(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -269,7 +269,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -2439,6 +2517,9 @@ psa_status_t psa_driver_wrapper_mac_sign_setup(
+@@ -2405,6 +2483,9 @@ psa_status_t psa_driver_wrapper_mac_sign_setup(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -279,7 +279,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -2523,6 +2604,9 @@ psa_status_t psa_driver_wrapper_mac_verify_setup(
+@@ -2486,6 +2567,9 @@ psa_status_t psa_driver_wrapper_mac_verify_setup(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -289,7 +289,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -2748,6 +2832,9 @@ psa_status_t psa_driver_wrapper_key_agreement(
+@@ -2716,6 +2800,9 @@ psa_status_t psa_driver_wrapper_key_agreement(
      switch( location )
      {
      case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -299,7 +299,7 @@
          /* Key is stored in the slot in export representation, so
           * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -2797,6 +2884,9 @@ psa_status_t psa_driver_wrapper_asymmetric_encrypt(
+@@ -2765,6 +2852,9 @@ psa_status_t psa_driver_wrapper_asymmetric_encrypt(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -309,7 +309,7 @@
              /* Key is stored in the slot in export representation, so
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-@@ -2869,6 +2959,9 @@ psa_status_t psa_driver_wrapper_asymmetric_decrypt(
+@@ -2837,6 +2927,9 @@ psa_status_t psa_driver_wrapper_asymmetric_decrypt(
      switch( location )
      {
          case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -320,5 +320,5 @@
               * cycle through all known transparent accelerators */
  #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
 -- 
-2.34.1
+2.25.1
 
diff --git a/lib/ext/mbedcrypto/0006-Build-Remove-encoding-width-suffix-from-Arm-bignum.patch b/lib/ext/mbedcrypto/0007-Build-Remove-encoding-width-suffix-from-Arm-bignum-a.patch
similarity index 87%
rename from lib/ext/mbedcrypto/0006-Build-Remove-encoding-width-suffix-from-Arm-bignum.patch
rename to lib/ext/mbedcrypto/0007-Build-Remove-encoding-width-suffix-from-Arm-bignum-a.patch
index 07c65d1..6b9a0d6 100644
--- a/lib/ext/mbedcrypto/0006-Build-Remove-encoding-width-suffix-from-Arm-bignum.patch
+++ b/lib/ext/mbedcrypto/0007-Build-Remove-encoding-width-suffix-from-Arm-bignum-a.patch
@@ -1,7 +1,11 @@
-From 1698af1aa6a8cbf4ca59dd5dbd756418e58273d5 Mon Sep 17 00:00:00 2001
-From: Dávid Házi <david.hazi@arm.com>
+From 98d7c4bc36ed72190926e3c8c045b5ce7e8c0a6f Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?D=C3=A1vid=20H=C3=A1zi?= <david.hazi@arm.com>
 Date: Tue, 2 Aug 2022 14:38:32 +0200
-Subject: [PATCH 6/6] Build: Remove encoding width suffix from Arm bignum assembly
+Subject: [PATCH 7/9] Build: Remove encoding width suffix from Arm bignum
+ assembly
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
 
 Signed-off-by: Dávid Házi <david.hazi@arm.com>
 ---
@@ -9,7 +13,7 @@
  1 file changed, 9 insertions(+), 9 deletions(-)
 
 diff --git a/library/bn_mul.h b/library/bn_mul.h
-index 962d7a97..9cc84d06 100644
+index 962d7a97b..20e0e53dc 100644
 --- a/library/bn_mul.h
 +++ b/library/bn_mul.h
 @@ -717,10 +717,10 @@
@@ -48,5 +52,5 @@
  #define MULADDC_X2_STOP                                      \
              : [a0]     "=&r" (tmp_a0),                       \
 -- 
-2.34.1
+2.25.1
 
diff --git a/lib/ext/mbedcrypto/0007-CC3XX-Manually-enforce-no-software-builtin-fallback-.patch b/lib/ext/mbedcrypto/0008-CC3XX-Manually-enforce-no-software-builtin-fallback-.patch
similarity index 99%
rename from lib/ext/mbedcrypto/0007-CC3XX-Manually-enforce-no-software-builtin-fallback-.patch
rename to lib/ext/mbedcrypto/0008-CC3XX-Manually-enforce-no-software-builtin-fallback-.patch
index 4a45d45..6dacd1b 100644
--- a/lib/ext/mbedcrypto/0007-CC3XX-Manually-enforce-no-software-builtin-fallback-.patch
+++ b/lib/ext/mbedcrypto/0008-CC3XX-Manually-enforce-no-software-builtin-fallback-.patch
@@ -1,7 +1,7 @@
-From 2a51e75d666d8c3ad3132aeecc1110f58dd7e701 Mon Sep 17 00:00:00 2001
+From b4632fba2ee123e78368792c00dda0fc5ccb245f Mon Sep 17 00:00:00 2001
 From: Antonio de Angelis <Antonio.deAngelis@arm.com>
 Date: Tue, 2 Aug 2022 13:05:05 +0200
-Subject: [PATCH 7/7] CC3XX: Manually enforce no-software builtin fallback when
+Subject: [PATCH 8/9] CC3XX: Manually enforce no-software builtin fallback when
  CC3XX is available
 
 This wil be enforced by the autogen framework eventually, but for the time
diff --git a/lib/ext/mbedcrypto/0009-Initialise-driver-wrappers-as-first-step-in-psa_cryp.patch b/lib/ext/mbedcrypto/0009-Initialise-driver-wrappers-as-first-step-in-psa_cryp.patch
new file mode 100644
index 0000000..1945b71
--- /dev/null
+++ b/lib/ext/mbedcrypto/0009-Initialise-driver-wrappers-as-first-step-in-psa_cryp.patch
@@ -0,0 +1,46 @@
+From c5159e0fba198909e4c322c0b15d11b58223d36e Mon Sep 17 00:00:00 2001
+From: Antonio de Angelis <Antonio.deAngelis@arm.com>
+Date: Tue, 23 Aug 2022 13:06:07 +0100
+Subject: [PATCH 9/9] Initialise driver wrappers as first step in
+ psa_crypto_init()
+
+This patch amends the order of initialisations performed in psa_crypto_init()
+to make sure that the driver wrappers based on the PSA driver API are initialised
+before anything else.
+
+Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
+---
+ library/psa_crypto.c | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/library/psa_crypto.c b/library/psa_crypto.c
+index 8cc5629f9..b0159991c 100644
+--- a/library/psa_crypto.c
++++ b/library/psa_crypto.c
+@@ -6306,6 +6306,11 @@ psa_status_t psa_crypto_init( void )
+     if( global_data.initialized != 0 )
+         return( PSA_SUCCESS );
+ 
++    /* Init drivers */
++    status = psa_driver_wrapper_init( );
++    if( status != PSA_SUCCESS )
++        goto exit;
++
+     /* Initialize and seed the random generator. */
+     mbedtls_psa_random_init( &global_data.rng );
+     global_data.rng_state = RNG_INITIALIZED;
+@@ -6318,11 +6323,6 @@ psa_status_t psa_crypto_init( void )
+     if( status != PSA_SUCCESS )
+         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 )
+-- 
+2.25.1
+