mbedtls
mbedtls copied to clipboard
Add a global mutex for global data
See the design document for background and this thread for justification.
Add a new global mutex and make sure that every function accessing or modifying the global_data
static variable in psa_crypto.c
takes that mutex. The functions should take the mutex in a way that the consistency of the whole structure is guaranteed. ~The mutex should protect the PSA Crypto random generator as well.~
The task is complete when the above described mutex and protection is added along with multi-threaded unit tests.
It makes sense to handle MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
consistently with drivers. In the MVP thread safety is the responsibility of the drivers and the core does not make any guarantees.
During the review of https://github.com/Mbed-TLS/mbedtls/pull/8744 I realised that we have forgotten about the psa_crypto_transaction
global variable. It should be protected by a mutex as well, question is which one. The keystore mutex seems convenient, but might not work or might not be very efficient in all cases.