mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Protect PSA global rng data with mutex.
Reads and writes of rng_state in psa_crypto_init() and psa_crypto_free() were already covered by mutex. Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
@ -7449,12 +7449,25 @@ psa_status_t mbedtls_psa_crypto_configure_entropy_sources(
|
|||||||
void (* entropy_init)(mbedtls_entropy_context *ctx),
|
void (* entropy_init)(mbedtls_entropy_context *ctx),
|
||||||
void (* entropy_free)(mbedtls_entropy_context *ctx))
|
void (* entropy_free)(mbedtls_entropy_context *ctx))
|
||||||
{
|
{
|
||||||
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
|
mbedtls_mutex_lock(&mbedtls_threading_psa_rngdata_mutex);
|
||||||
|
#endif /* defined(MBEDTLS_THREADING_C) */
|
||||||
|
|
||||||
if (global_data.rng_state != RNG_NOT_INITIALIZED) {
|
if (global_data.rng_state != RNG_NOT_INITIALIZED) {
|
||||||
return PSA_ERROR_BAD_STATE;
|
status = PSA_ERROR_BAD_STATE;
|
||||||
|
} else {
|
||||||
|
global_data.rng.entropy_init = entropy_init;
|
||||||
|
global_data.rng.entropy_free = entropy_free;
|
||||||
|
status = PSA_SUCCESS;
|
||||||
}
|
}
|
||||||
global_data.rng.entropy_init = entropy_init;
|
|
||||||
global_data.rng.entropy_free = entropy_free;
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
return PSA_SUCCESS;
|
mbedtls_mutex_unlock(&mbedtls_threading_psa_rngdata_mutex);
|
||||||
|
#endif /* defined(MBEDTLS_THREADING_C) */
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
#endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */
|
#endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user