Skip to content

Commit

Permalink
bt-mesh: remove BT_MESH_USES_TINYCRYPT
Browse files Browse the repository at this point in the history
As part of the deprecation process of TinyCrypt in Zephyr codebase
(zephyrproject-rtos#79566) this commit removes TinyCrypt usage from BT mesh and
also the related CONFIG_BT_MESH_USES_TINYCRYPT symbol and it sets
PSA Crypto APIs as the default library for crypto operations.
Tests are also updated in this commit.

Signed-off-by: Valerio Setti <[email protected]>
  • Loading branch information
valeriosetti committed Nov 6, 2024
1 parent 23662a5 commit b0c61a2
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 234 deletions.
8 changes: 0 additions & 8 deletions include/zephyr/bluetooth/mesh/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ struct bt_mesh_key {
psa_key_id_t key;
};

#elif defined CONFIG_BT_MESH_USES_TINYCRYPT

/** The structure that keeps representation of key. */
struct bt_mesh_key {
/** tinycrypt key representation is the pure key value. */
uint8_t key[16];
};

#else
#error "Crypto library has not been chosen"
#endif
Expand Down
6 changes: 1 addition & 5 deletions subsys/bluetooth/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH_STATISTIC statistic.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG delayable_msg.c)

if (CONFIG_BT_MESH_USES_TINYCRYPT)
zephyr_library_sources(crypto_tc.c)
else()
zephyr_library_sources(crypto_psa.c)
endif()
zephyr_library_sources(crypto_psa.c)

zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS)

Expand Down
20 changes: 3 additions & 17 deletions subsys/bluetooth/mesh/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1457,29 +1457,15 @@ endmenu # Proxy
choice BT_MESH_CRYPTO_LIB
prompt "Crypto library:"
default BT_MESH_USES_TFM_PSA if BUILD_WITH_TFM
default BT_MESH_USES_TINYCRYPT
default BT_MESH_USES_MBEDTLS_PSA
help
Crypto library selection for mesh security.

config BT_MESH_USES_TINYCRYPT
bool "TinyCrypt"
select TINYCRYPT
select TINYCRYPT_AES
select TINYCRYPT_AES_CMAC
select TINYCRYPT_ECC_DH
select TINYCRYPT_SHA256
select TINYCRYPT_SHA256_HMAC
select BT_HOST_CCM
help
Use TinyCrypt library to perform crypto operations.

config BT_MESH_USES_MBEDTLS_PSA
bool "mbed TLS PSA [EXPERIMENTAL]"
select EXPERIMENTAL
bool "mbed TLS PSA"
select MBEDTLS
select MBEDTLS_ENTROPY_C
select MBEDTLS_PSA_CRYPTO_C
select MBEDTLS_USE_PSA_CRYPTO
select MBEDTLS_ENTROPY_C
select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT
select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT
select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE
Expand Down
156 changes: 0 additions & 156 deletions subsys/bluetooth/mesh/crypto_tc.c

This file was deleted.

34 changes: 0 additions & 34 deletions subsys/bluetooth/mesh/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,8 @@ enum bt_mesh_key_type {
BT_MESH_KEY_TYPE_DEV
};

#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA || defined CONFIG_BT_MESH_USES_TFM_PSA

int bt_mesh_key_import(enum bt_mesh_key_type type, const uint8_t in[16], struct bt_mesh_key *out);
int bt_mesh_key_export(uint8_t out[16], const struct bt_mesh_key *in);
void bt_mesh_key_assign(struct bt_mesh_key *dst, const struct bt_mesh_key *src);
int bt_mesh_key_destroy(const struct bt_mesh_key *key);
int bt_mesh_key_compare(const uint8_t raw_key[16], const struct bt_mesh_key *mesh_key);

#elif defined CONFIG_BT_MESH_USES_TINYCRYPT

static inline int bt_mesh_key_import(enum bt_mesh_key_type type, const uint8_t in[16],
struct bt_mesh_key *out)
{
memcpy(out, in, 16);
return 0;
}

static inline int bt_mesh_key_export(uint8_t out[16], const struct bt_mesh_key *in)
{
memcpy(out, in, 16);
return 0;
}

static inline void bt_mesh_key_assign(struct bt_mesh_key *dst, const struct bt_mesh_key *src)
{
memcpy(dst, src, sizeof(struct bt_mesh_key));
}

static inline int bt_mesh_key_destroy(const struct bt_mesh_key *key)
{
return 0;
}

static inline int bt_mesh_key_compare(const uint8_t raw_key[16], const struct bt_mesh_key *mesh_key)
{
return memcmp(mesh_key, raw_key, 16);
}

#endif
2 changes: 1 addition & 1 deletion tests/bluetooth/mesh/brg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ target_compile_options(app
-DCONFIG_BT_SETTINGS
-DCONFIG_BT_MESH_BRG_CFG_SRV
-DCONFIG_BT_MESH_BRG_TABLE_ITEMS_MAX=16
-DCONFIG_BT_MESH_USES_TINYCRYPT)
-DCONFIG_BT_MESH_USES_MBEDTLS_PSA)
2 changes: 1 addition & 1 deletion tests/bluetooth/mesh/delayable_msg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ target_compile_options(app
-DCONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_COUNT=4
-DCONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE=20
-DCONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT=20
-DCONFIG_BT_MESH_USES_TINYCRYPT)
-DCONFIG_BT_MESH_USES_MBEDTLS_PSA)
2 changes: 1 addition & 1 deletion tests/bluetooth/mesh/rpl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ target_compile_options(app
-DCONFIG_BT_MESH_CRPL=10
-DCONFIG_BT_MESH_RPL_STORE_TIMEOUT=1
-DCONFIG_BT_SETTINGS
-DCONFIG_BT_MESH_USES_TINYCRYPT)
-DCONFIG_BT_MESH_USES_MBEDTLS_PSA)
11 changes: 0 additions & 11 deletions tests/bsim/bluetooth/mesh/src/test_provision.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA
#include <psa/crypto.h>
#elif defined CONFIG_BT_MESH_USES_TINYCRYPT
#include <tinycrypt/constants.h>
#include <tinycrypt/ecc.h>
#include <tinycrypt/ecc_dh.h>
#else
#error "Unknown crypto library has been chosen"
#endif
Expand Down Expand Up @@ -435,7 +431,6 @@ static void oob_auth_set(int test_step)
prov.input_actions = oob_auth_test_vector[test_step].input_actions;
}

#if defined CONFIG_BT_MESH_USES_MBEDTLS_PSA
static void generate_oob_key_pair(void)
{
psa_key_attributes_t key_attributes = PSA_KEY_ATTRIBUTES_INIT;
Expand Down Expand Up @@ -470,12 +465,6 @@ static void generate_oob_key_pair(void)

memcpy(public_key_be, public_key_repr + 1, 64);
}
#elif defined CONFIG_BT_MESH_USES_TINYCRYPT
static void generate_oob_key_pair(void)
{
ASSERT_TRUE(uECC_make_key(public_key_be, private_key_be, uECC_secp256r1()));
}
#endif

static void oob_device(bool use_oob_pk)
{
Expand Down

0 comments on commit b0c61a2

Please sign in to comment.