Skip to content

Commit

Permalink
[Silabs] Added tinycrypt changes (#24024)
Browse files Browse the repository at this point in the history
* Added tinycrypt changes

* Added tinycrypt files in matter support
  • Loading branch information
ShubhamMalasane authored and pull[bot] committed Jun 23, 2023
1 parent 5d4eb55 commit 75d776c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/platform/silabs/PlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
// the implementation methods provided by this class.
friend PlatformManager;

#if defined(TINYCRYPT_PRIMITIVES)
// Since the RNG callback will be called from multiple threads,
// use this mutex to lock/unlock the call to Matter RNG API, which
// uses some global variables.
static sys_mutex_t rngMutexHandle;

// Callback used by tinycrypt to generate random numbers.
// It must be set before calling any sign operations,
// which are used in both Matter and OT threads.
static int uECC_RNG_Function(uint8_t * dest, unsigned int size);
#endif

// Allow the generic implementation base class to call helper methods on
// this class.
#ifndef DOXYGEN_SHOULD_SKIP_THIS
Expand Down
27 changes: 27 additions & 0 deletions src/platform/silabs/SiWx917/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <platform/PlatformManager.h>
#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.ipp>
#include <platform/silabs/DiagnosticDataProviderImpl.h>
#if defined(TINYCRYPT_PRIMITIVES)
#include "tinycrypt/ecc.h"
#endif

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/tcpip.h>
Expand All @@ -42,6 +45,22 @@ namespace chip {
namespace DeviceLayer {

PlatformManagerImpl PlatformManagerImpl::sInstance;
#if defined(TINYCRYPT_PRIMITIVES)
sys_mutex_t PlatformManagerImpl::rngMutexHandle = NULL;
#endif

#if defined(TINYCRYPT_PRIMITIVES)
int PlatformManagerImpl::uECC_RNG_Function(uint8_t * dest, unsigned int size)
{
int res;

sys_mutex_lock(&rngMutexHandle);
res = (chip::Crypto::DRBG_get_bytes(dest, size) == CHIP_NO_ERROR) ? size : 0;
sys_mutex_unlock(&rngMutexHandle);

return res;
}
#endif

static void app_get_random(uint8_t * aOutput, size_t aLen)
{
Expand Down Expand Up @@ -79,6 +98,14 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
// 16 : Threshold value
ReturnErrorOnFailure(chip::Crypto::add_entropy_source(app_entropy_source, NULL, 16));

#if defined(TINYCRYPT_PRIMITIVES)
/* Set RNG function for tinycrypt operations. */
err_t ret;
ret = sys_mutex_new(&rngMutexHandle);
VerifyOrExit((ERR_OK == ret), err = CHIP_ERROR_NO_MEMORY);
uECC_set_rng(PlatformManagerImpl::uECC_RNG_Function);
#endif

// Call _InitChipStack() on the generic implementation base class
// to finish the initialization process.
err = Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>::_InitChipStack();
Expand Down
2 changes: 2 additions & 0 deletions src/platform/silabs/SiWx917/wifi_args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ arm_platform_config = "${efr32_sdk_build_root}/efr32_arm.gni"

mbedtls_target = "${efr32_sdk_build_root}:efr32_sdk"

chip_crypto = "tinycrypt"

# Transitional CommissionableDataProvider not used anymore
# examples/platform/efr32/EFR32DeviceDataProvider is now used.
chip_use_transitional_commissionable_data_provider = false
Expand Down
22 changes: 15 additions & 7 deletions third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ template("efr32_sdk") {
# Treat these includes as system includes, so warnings in them are not fatal.
_include_dirs = [
"${sdk_support_root}/platform/emdrv/nvm3/inc",

"${sdk_support_root}/matter/mbedtls/tinycrypt/inc",
"${chip_root}/third_party/mbedtls/repo/include",

### CCP includes ###
Expand Down Expand Up @@ -138,6 +138,8 @@ template("efr32_sdk") {
"RSI_BLE_ENABLE=1",
"BRD4325A",
"CHIP_9117",
"TINYCRYPT_PRIMITIVES",
"OPTIMIZE_TINYCRYPT_ASM",
"RS91X_BLE_ENABLE=1",
]

Expand Down Expand Up @@ -311,17 +313,23 @@ template("efr32_sdk") {
"${chip_root}/third_party/mbedtls/repo/library/hkdf.c",
"${chip_root}/third_party/mbedtls/repo/library/hmac_drbg.c",
"${chip_root}/third_party/mbedtls/repo/library/md.c",
"${chip_root}/third_party/mbedtls/repo/library/oid.c",
"${chip_root}/third_party/mbedtls/repo/library/pk.c",
"${chip_root}/third_party/mbedtls/repo/library/pk_wrap.c",
"${chip_root}/third_party/mbedtls/repo/library/pkcs5.c",
"${chip_root}/third_party/mbedtls/repo/library/pkwrite.c",
"${chip_root}/third_party/mbedtls/repo/library/platform.c",
"${chip_root}/third_party/mbedtls/repo/library/platform_util.c",
"${chip_root}/third_party/mbedtls/repo/library/sha256.c",
"${chip_root}/third_party/mbedtls/repo/library/sha512.c",
"${chip_root}/third_party/mbedtls/repo/library/x509_create.c",
"${chip_root}/third_party/mbedtls/repo/library/x509write_csr.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/ecc.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/ecc_dh.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/ecc_dsa.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/error.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/oid.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/pk.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/pk_wrap.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/pkparse.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/pkwrite.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/platform_util.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/x509_crt.c",
"${sdk_support_root}/matter/mbedtls/tinycrypt/src/x509write_csr.c",
]

public_deps = [
Expand Down
2 changes: 1 addition & 1 deletion third_party/silabs/matter_support
Submodule matter_support updated 30 files
+3 −1 matter/efr32/efr32mg12/BRD4161A/autogen/sl_event_handler.c
+2 −0 matter/efr32/efr32mg24/BRD4186C/autogen/sl_event_handler.c
+2 −0 matter/efr32/efr32mg24/BRD4187C/autogen/sl_event_handler.c
+7 −0 matter/mbedtls/tinycrypt/CMakeLists.txt
+61 −0 matter/mbedtls/tinycrypt/LICENSE
+77 −0 matter/mbedtls/tinycrypt/README
+977 −0 matter/mbedtls/tinycrypt/inc/mbedtls/check_config.h
+1,772 −0 matter/mbedtls/tinycrypt/inc/mbedtls/config.h
+927 −0 matter/mbedtls/tinycrypt/inc/mbedtls/oid.h
+948 −0 matter/mbedtls/tinycrypt/inc/mbedtls/pk.h
+139 −0 matter/mbedtls/tinycrypt/inc/mbedtls/pk_internal.h
+448 −0 matter/mbedtls/tinycrypt/inc/mbedtls/platform.h
+461 −0 matter/mbedtls/tinycrypt/inc/mbedtls/platform_util.h
+131 −0 matter/mbedtls/tinycrypt/inc/psa/crypto_config.h
+478 −0 matter/mbedtls/tinycrypt/inc/tinycrypt/ecc.h
+135 −0 matter/mbedtls/tinycrypt/inc/tinycrypt/ecc_dh.h
+144 −0 matter/mbedtls/tinycrypt/inc/tinycrypt/ecc_dsa.h
+1,739 −0 matter/mbedtls/tinycrypt/src/ecc.c
+182 −0 matter/mbedtls/tinycrypt/src/ecc_dh.c
+308 −0 matter/mbedtls/tinycrypt/src/ecc_dsa.c
+1,064 −0 matter/mbedtls/tinycrypt/src/error.c
+884 −0 matter/mbedtls/tinycrypt/src/oid.c
+640 −0 matter/mbedtls/tinycrypt/src/pk.c
+1,344 −0 matter/mbedtls/tinycrypt/src/pk_wrap.c
+1,672 −0 matter/mbedtls/tinycrypt/src/pkparse.c
+716 −0 matter/mbedtls/tinycrypt/src/pkwrite.c
+449 −0 matter/mbedtls/tinycrypt/src/platform_util.c
+3,196 −0 matter/mbedtls/tinycrypt/src/x509_crt.c
+355 −0 matter/mbedtls/tinycrypt/src/x509write_csr.c
+12 −0 platform/emdrv/nvm3/src/nvm3_hal_flash_ccp.c

0 comments on commit 75d776c

Please sign in to comment.