Skip to content

Commit

Permalink
fixup! crypto: nrf_cc3xx: Update mutex support for Mbed TLS 3.6.0
Browse files Browse the repository at this point in the history
-Don't reuse RNG mutex for the PSA rng mutex type

Signed-off-by: Frank Audun Kvamtrø <[email protected]>
  • Loading branch information
frkv committed Sep 26, 2024
1 parent d4cf0cf commit 7acb5ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 14 additions & 3 deletions crypto/nrf_cc310_platform/src/nrf_cc3xx_platform_mutex_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ K_MUTEX_DEFINE(key_slot_mutex_int);
*/
K_MUTEX_DEFINE(psa_globaldata_mutex_int);

/** @brief Definition of mutex for PSA global access
*/
K_MUTEX_DEFINE(psa_rng_mutex_int);

#elif CONFIG_CC3XX_ATOMIC_LOCK

/** @brief Definition of mutex for symmetric cryptography
Expand All @@ -79,6 +83,10 @@ static atomic_t key_slot_mutex_int;
*/
static atomic_t psa_globaldata_mutex_int;

/** @brief Definition of mutex for PSA global access
*/
static atomic_t psa_rng_mutex_int;

#elif defined(NRF5340_XXAA_APPLICATION) && NRF_CC3XX_PLATFORM_MUTEX_MASK_IS_HW_MUTEX

typedef enum {
Expand All @@ -88,6 +96,7 @@ typedef enum {
HW_MUTEX_HEAP_ALLOC = 12,
HW_MUTEX_KEY_SLOT = 11,
HW_MUTEX_PSA_GLOBALDATA = 10,
HW_MUTEX_PSA_RNG = 9,
} hw_mutex_t;

/** @brief Definition of mutex for symmetric cryptography
Expand All @@ -114,6 +123,10 @@ static hw_mutex_t key_slot_mutex_int = HW_MUTEX_KEY_SLOT;
*/
static hw_mutex_t psa_globaldata_mutex_int = HW_MUTEX_PSA_GLOBALDATA;

/** @brief Definition of mutex for PSA global access
*/
static hw_mutex_t psa_rng_mutex_int = HW_MUTEX_PSA_RNG;

#else
#error "Improper configuration of the lock variant!"
#endif
Expand Down Expand Up @@ -233,11 +246,9 @@ nrf_cc3xx_platform_mutex_t mbedtls_threading_psa_globaldata_mutex = {
* allocation is unneccesary
*
* @note This symbol can't be static as it is referenced from Mbed TLS
*
* @note Reusing the RNG mutex used for CryptoCell.
*/
nrf_cc3xx_platform_mutex_t mbedtls_threading_psa_rngdata_mutex = {
.mutex = &rng_mutex_int,
.mutex = &psa_rng_mutex_int,
.flags = IS_ENABLED(CONFIG_CC3XX_ATOMIC_LOCK) ?
NRF_CC3XX_PLATFORM_MUTEX_MASK_IS_ATOMIC :
IS_ENABLED(CONFIG_CC3XX_HW_MUTEX_LOCK) ?
Expand Down
17 changes: 14 additions & 3 deletions crypto/nrf_cc312_platform/src/nrf_cc3xx_platform_mutex_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ K_MUTEX_DEFINE(key_slot_mutex_int);
*/
K_MUTEX_DEFINE(psa_globaldata_mutex_int);

/** @brief Definition of mutex for PSA global access
*/
K_MUTEX_DEFINE(psa_rng_mutex_int);

#elif CONFIG_CC3XX_ATOMIC_LOCK

/** @brief Definition of mutex for symmetric cryptography
Expand All @@ -79,6 +83,10 @@ static atomic_t key_slot_mutex_int;
*/
static atomic_t psa_globaldata_mutex_int;

/** @brief Definition of mutex for PSA global access
*/
static atomic_t psa_rng_mutex_int;

#elif defined(NRF5340_XXAA_APPLICATION) && NRF_CC3XX_PLATFORM_MUTEX_MASK_IS_HW_MUTEX

typedef enum {
Expand All @@ -88,6 +96,7 @@ typedef enum {
HW_MUTEX_HEAP_ALLOC = 12,
HW_MUTEX_KEY_SLOT = 11,
HW_MUTEX_PSA_GLOBALDATA = 10,
HW_MUTEX_PSA_RNG = 9,
} hw_mutex_t;

/** @brief Definition of mutex for symmetric cryptography
Expand All @@ -114,6 +123,10 @@ static hw_mutex_t key_slot_mutex_int = HW_MUTEX_KEY_SLOT;
*/
static hw_mutex_t psa_globaldata_mutex_int = HW_MUTEX_PSA_GLOBALDATA;

/** @brief Definition of mutex for PSA global access
*/
static hw_mutex_t psa_rng_mutex_int = HW_MUTEX_PSA_RNG;

#else
#error "Improper configuration of the lock variant!"
#endif
Expand Down Expand Up @@ -233,11 +246,9 @@ nrf_cc3xx_platform_mutex_t mbedtls_threading_psa_globaldata_mutex = {
* allocation is unneccesary
*
* @note This symbol can't be static as it is referenced from Mbed TLS
*
* @note Reusing the RNG mutex used for CryptoCell.
*/
nrf_cc3xx_platform_mutex_t mbedtls_threading_psa_rngdata_mutex = {
.mutex = &rng_mutex_int,
.mutex = &psa_rng_mutex_int,
.flags = IS_ENABLED(CONFIG_CC3XX_ATOMIC_LOCK) ?
NRF_CC3XX_PLATFORM_MUTEX_MASK_IS_ATOMIC :
IS_ENABLED(CONFIG_CC3XX_HW_MUTEX_LOCK) ?
Expand Down

0 comments on commit 7acb5ae

Please sign in to comment.