0.2.0-dev Download ZIP
75 lines ·2.6 KB Raw
| 1 | /** |
| 2 | * \file threading_internal.h |
| 3 | * |
| 4 | * \brief Threading interfaces used internally in the library and |
| 5 | * by the test framework. |
| 6 | */ |
| 7 | /* |
| 8 | * Copyright The Mbed TLS Contributors |
| 9 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 10 | */ |
| 11 | |
| 12 | #ifndef TF_PSA_CRYPTO_THREADING_INTERNAL_H |
| 13 | #define TF_PSA_CRYPTO_THREADING_INTERNAL_H |
| 14 | |
| 15 | #include "tf_psa_crypto_common.h" |
| 16 | |
| 17 | #include <mbedtls/threading.h> |
| 18 | |
| 19 | /* A version number for the internal threading interface. |
| 20 | * This is meant to allow the framework to remain compatible with |
| 21 | * multiple versions, to facilitate transitions. |
| 22 | * |
| 23 | * Conventionally, this is the Mbed TLS version number when the |
| 24 | * threading interface was last changed in a way that may impact the |
| 25 | * test framework, with the lower byte incremented as necessary |
| 26 | * if multiple changes happened between releases. */ |
| 27 | #define MBEDTLS_THREADING_INTERNAL_VERSION 0x04000001 |
| 28 | |
| 29 | #if defined(MBEDTLS_THREADING_C) |
| 30 | |
| 31 | /* |
| 32 | * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock |
| 33 | * |
| 34 | * They are exposed for the sake of the mutex usage verification framework |
| 35 | * (see framework/tests/src/threading_helpers.c). |
| 36 | */ |
| 37 | extern int (*mbedtls_mutex_init_ptr)(mbedtls_platform_mutex_t *mutex); |
| 38 | extern void (*mbedtls_mutex_free_ptr)(mbedtls_platform_mutex_t *mutex); |
| 39 | extern int (*mbedtls_mutex_lock_ptr)(mbedtls_platform_mutex_t *mutex); |
| 40 | extern int (*mbedtls_mutex_unlock_ptr)(mbedtls_platform_mutex_t *mutex); |
| 41 | |
| 42 | /* |
| 43 | * Global mutexes |
| 44 | */ |
| 45 | #if defined(MBEDTLS_PSA_CRYPTO_C) |
| 46 | /* |
| 47 | * A mutex used to make the PSA subsystem thread safe. |
| 48 | * |
| 49 | * key_slot_mutex protects the registered_readers and |
| 50 | * state variable for all key slots in &global_data.key_slots. |
| 51 | * |
| 52 | * This mutex must be held when any read from or write to a state or |
| 53 | * registered_readers field is performed, i.e. when calling functions: |
| 54 | * psa_key_slot_state_transition(), psa_register_read(), psa_unregister_read(), |
| 55 | * psa_key_slot_has_readers() and psa_wipe_key_slot(). */ |
| 56 | extern mbedtls_threading_mutex_t mbedtls_threading_key_slot_mutex; |
| 57 | |
| 58 | /* |
| 59 | * A mutex used to make the non-rng PSA global_data struct members thread safe. |
| 60 | * |
| 61 | * This mutex must be held when reading or writing to any of the PSA global_data |
| 62 | * structure members, other than the rng_state or rng struct. */ |
| 63 | extern mbedtls_threading_mutex_t mbedtls_threading_psa_globaldata_mutex; |
| 64 | |
| 65 | /* |
| 66 | * A mutex used to make the PSA global_data rng data thread safe. |
| 67 | * |
| 68 | * This mutex must be held when reading or writing to the PSA |
| 69 | * global_data rng_state or rng struct members. */ |
| 70 | extern mbedtls_threading_mutex_t mbedtls_threading_psa_rngdata_mutex; |
| 71 | #endif |
| 72 | |
| 73 | #endif /* MBEDTLS_THREADING_C */ |
| 74 | |
| 75 | #endif /* TF_PSA_CRYPTO_THREADING_INTERNAL_H */ |