mirror of
https://github.com/espressif/openthread.git
synced 2026-09-13 20:50:05 +00:00
[crypto] PSA API: enable native ITS in build system
This commit enables PSA native ITS implementation in the build system for simulation and test platforms. Signed-off-by: Łukasz Duda <[email protected]>
This commit is contained in:
@@ -48,9 +48,9 @@ target_link_libraries(ot-cli-ftd PRIVATE
|
|||||||
openthread-cli-ftd
|
openthread-cli-ftd
|
||||||
${OT_PLATFORM_LIB_FTD}
|
${OT_PLATFORM_LIB_FTD}
|
||||||
openthread-ftd
|
openthread-ftd
|
||||||
${OT_PLATFORM_LIB_FTD}
|
|
||||||
openthread-cli-ftd
|
openthread-cli-ftd
|
||||||
${OT_MBEDTLS}
|
${OT_MBEDTLS}
|
||||||
|
${OT_PLATFORM_LIB_FTD}
|
||||||
ot-config-ftd
|
ot-config-ftd
|
||||||
ot-config
|
ot-config
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ target_link_libraries(ot-cli-mtd PRIVATE
|
|||||||
openthread-cli-mtd
|
openthread-cli-mtd
|
||||||
${OT_PLATFORM_LIB_MTD}
|
${OT_PLATFORM_LIB_MTD}
|
||||||
openthread-mtd
|
openthread-mtd
|
||||||
${OT_PLATFORM_LIB_MTD}
|
|
||||||
openthread-cli-mtd
|
openthread-cli-mtd
|
||||||
${OT_MBEDTLS}
|
${OT_MBEDTLS}
|
||||||
|
${OT_PLATFORM_LIB_MTD}
|
||||||
ot-config-mtd
|
ot-config-mtd
|
||||||
ot-config
|
ot-config
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ target_link_libraries(ot-ncp-ftd PRIVATE
|
|||||||
openthread-ncp-ftd
|
openthread-ncp-ftd
|
||||||
${OT_PLATFORM_LIB_FTD}
|
${OT_PLATFORM_LIB_FTD}
|
||||||
openthread-ftd
|
openthread-ftd
|
||||||
${OT_PLATFORM_LIB_FTD}
|
|
||||||
openthread-ncp-ftd
|
openthread-ncp-ftd
|
||||||
${OT_MBEDTLS}
|
${OT_MBEDTLS}
|
||||||
|
${OT_PLATFORM_LIB_FTD}
|
||||||
ot-config-ftd
|
ot-config-ftd
|
||||||
ot-config
|
ot-config
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ target_link_libraries(ot-ncp-mtd PRIVATE
|
|||||||
openthread-ncp-mtd
|
openthread-ncp-mtd
|
||||||
${OT_PLATFORM_LIB_MTD}
|
${OT_PLATFORM_LIB_MTD}
|
||||||
openthread-mtd
|
openthread-mtd
|
||||||
${OT_PLATFORM_LIB_MTD}
|
|
||||||
openthread-ncp-mtd
|
openthread-ncp-mtd
|
||||||
${OT_MBEDTLS}
|
${OT_MBEDTLS}
|
||||||
|
${OT_PLATFORM_LIB_MTD}
|
||||||
ot-config-mtd
|
ot-config-mtd
|
||||||
ot-config
|
ot-config
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -103,9 +103,10 @@ endif()
|
|||||||
|
|
||||||
target_link_libraries(openthread-simulation PRIVATE
|
target_link_libraries(openthread-simulation PRIVATE
|
||||||
openthread-platform
|
openthread-platform
|
||||||
|
mbedtls
|
||||||
|
openthread-native-its-file
|
||||||
ot-simulation-config
|
ot-simulation-config
|
||||||
ot-config
|
ot-config
|
||||||
mbedtls
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(openthread-simulation PRIVATE
|
target_compile_options(openthread-simulation PRIVATE
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ extern otRadioCaps gRadioCaps;
|
|||||||
|
|
||||||
static volatile bool gTerminate = false;
|
static volatile bool gTerminate = false;
|
||||||
|
|
||||||
|
#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE && (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
|
||||||
|
static char sNativeItsFileNamePrefix[256];
|
||||||
|
extern const char *gItsFileNamePrefix;
|
||||||
|
#endif
|
||||||
|
|
||||||
static void handleSignal(int aSignal)
|
static void handleSignal(int aSignal)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aSignal);
|
OT_UNUSED_VARIABLE(aSignal);
|
||||||
@@ -193,6 +198,12 @@ void otSysInit(int aArgCount, char *aArgVector[])
|
|||||||
signal(SIGTERM, &handleSignal);
|
signal(SIGTERM, &handleSignal);
|
||||||
signal(SIGHUP, &handleSignal);
|
signal(SIGHUP, &handleSignal);
|
||||||
|
|
||||||
|
#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE && (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
|
||||||
|
snprintf(sNativeItsFileNamePrefix, sizeof(sNativeItsFileNamePrefix), "%s/%s_%d_",
|
||||||
|
OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH, getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId);
|
||||||
|
gItsFileNamePrefix = sNativeItsFileNamePrefix;
|
||||||
|
#endif
|
||||||
|
|
||||||
platformLoggingInit(basename(aArgVector[0]));
|
platformLoggingInit(basename(aArgVector[0]));
|
||||||
platformAlarmInit(speedUpFactor);
|
platformAlarmInit(speedUpFactor);
|
||||||
platformRadioInit();
|
platformRadioInit();
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ static bool sUseUnixSocket = false;
|
|||||||
int gArgumentsCount = 0;
|
int gArgumentsCount = 0;
|
||||||
char **gArguments = NULL;
|
char **gArguments = NULL;
|
||||||
|
|
||||||
|
#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE && (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
|
||||||
|
static char sNativeItsFileNamePrefix[256];
|
||||||
|
extern const char *gItsFileNamePrefix;
|
||||||
|
#endif
|
||||||
|
|
||||||
uint64_t sNow = 0; // microseconds
|
uint64_t sNow = 0; // microseconds
|
||||||
int sSockFd;
|
int sSockFd;
|
||||||
uint16_t sPortBase = 9000;
|
uint16_t sPortBase = 9000;
|
||||||
@@ -273,6 +278,12 @@ void otSysInit(int argc, char *argv[])
|
|||||||
DieNow(OT_EXIT_FAILURE);
|
DieNow(OT_EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE && (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
|
||||||
|
snprintf(sNativeItsFileNamePrefix, sizeof(sNativeItsFileNamePrefix), "%s/%s_%d_",
|
||||||
|
OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH, getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId);
|
||||||
|
gItsFileNamePrefix = sNativeItsFileNamePrefix;
|
||||||
|
#endif
|
||||||
|
|
||||||
socket_init();
|
socket_init();
|
||||||
|
|
||||||
platformAlarmInit(1);
|
platformAlarmInit(1);
|
||||||
|
|||||||
@@ -303,6 +303,7 @@ Instance::Instance(void)
|
|||||||
, mIsInitialized(false)
|
, mIsInitialized(false)
|
||||||
, mId(Random::NonCrypto::GetUint32())
|
, mId(Random::NonCrypto::GetUint32())
|
||||||
{
|
{
|
||||||
|
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||||
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||||
#if OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
|
#if OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
|
||||||
mCryptoStorageKeyRefManager.SetKeyRefExtraOffset(Crypto::Storage::KeyRefManager::kKeyRefExtraOffset * GetIdx(this));
|
mCryptoStorageKeyRefManager.SetKeyRefExtraOffset(Crypto::Storage::KeyRefManager::kKeyRefExtraOffset * GetIdx(this));
|
||||||
@@ -311,6 +312,7 @@ Instance::Instance(void)
|
|||||||
"The `KeyRef` values will be shared across different `Instance` objects"
|
"The `KeyRef` values will be shared across different `Instance` objects"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (OPENTHREAD_MTD || OPENTHREAD_FTD) && !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
#if (OPENTHREAD_MTD || OPENTHREAD_FTD) && !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ add_library(ot-fake-platform
|
|||||||
)
|
)
|
||||||
target_link_libraries(ot-fake-platform
|
target_link_libraries(ot-fake-platform
|
||||||
ot-config
|
ot-config
|
||||||
|
${OT_MBEDTLS}
|
||||||
|
openthread-native-its-ram
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(ot-fake-ftd INTERFACE)
|
add_library(ot-fake-ftd INTERFACE)
|
||||||
|
|||||||
@@ -50,6 +50,10 @@
|
|||||||
#include <openthread/platform/trel.h>
|
#include <openthread/platform/trel.h>
|
||||||
#include <openthread/platform/udp.h>
|
#include <openthread/platform/udp.h>
|
||||||
|
|
||||||
|
#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
|
||||||
|
#include <psa/crypto.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace ot;
|
using namespace ot;
|
||||||
|
|
||||||
bool operator<(const otExtAddress &aLeft, const otExtAddress &aRight)
|
bool operator<(const otExtAddress &aLeft, const otExtAddress &aRight)
|
||||||
@@ -482,6 +486,36 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA) && defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||||
|
/**
|
||||||
|
* When OpenThread is compiled with the PSA Crypto backend using Mbed TLS 3.x, there is no
|
||||||
|
* API to configure a dedicated non-default entropy source. It is documented that a future version of
|
||||||
|
* Mbed TLS (likely 4.x) will include a PSA interface for configuring entropy sources.
|
||||||
|
*
|
||||||
|
* For now, we need to define the external RNG. Since the implementation of `otPlatEntropyGet` already
|
||||||
|
* uses CSPRNG, we will call it here as well.
|
||||||
|
*/
|
||||||
|
extern "C" psa_status_t mbedtls_psa_external_get_random(mbedtls_psa_external_random_context_t *context,
|
||||||
|
uint8_t *output,
|
||||||
|
size_t output_size,
|
||||||
|
size_t *output_length)
|
||||||
|
{
|
||||||
|
OT_UNUSED_VARIABLE(context);
|
||||||
|
|
||||||
|
otError error;
|
||||||
|
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
|
||||||
|
|
||||||
|
error = otPlatEntropyGet(output, (uint16_t)output_size);
|
||||||
|
if (error == OT_ERROR_NONE)
|
||||||
|
{
|
||||||
|
*output_length = output_size;
|
||||||
|
status = PSA_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void otPlatDiagSetOutputCallback(otInstance *, otPlatDiagOutputCallback, void *) {}
|
void otPlatDiagSetOutputCallback(otInstance *, otPlatDiagOutputCallback, void *) {}
|
||||||
|
|
||||||
void otPlatDiagModeSet(bool) {}
|
void otPlatDiagModeSet(bool) {}
|
||||||
|
|||||||
@@ -117,10 +117,11 @@ set(COMMON_LIBS
|
|||||||
ot-test-platform-ftd
|
ot-test-platform-ftd
|
||||||
openthread-ftd
|
openthread-ftd
|
||||||
ot-test-platform-ftd
|
ot-test-platform-ftd
|
||||||
${OT_MBEDTLS}
|
|
||||||
ot-config
|
ot-config
|
||||||
openthread-ftd
|
openthread-ftd
|
||||||
openthread-url
|
openthread-url
|
||||||
|
${OT_MBEDTLS}
|
||||||
|
openthread-native-its-ram
|
||||||
)
|
)
|
||||||
|
|
||||||
set(COMMON_LIBS_RCP
|
set(COMMON_LIBS_RCP
|
||||||
|
|||||||
Vendored
+1
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
if(NOT OT_EXTERNAL_MBEDTLS)
|
if(NOT OT_EXTERNAL_MBEDTLS)
|
||||||
add_subdirectory(mbedtls)
|
add_subdirectory(mbedtls)
|
||||||
|
add_subdirectory(mbedtls/native_its)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(tcplp)
|
add_subdirectory(tcplp)
|
||||||
|
|||||||
Vendored
+1
@@ -140,4 +140,5 @@ target_include_directories(mbedcrypto
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
${OT_PUBLIC_INCLUDES}
|
${OT_PUBLIC_INCLUDES}
|
||||||
$<TARGET_PROPERTY:ot-config,INTERFACE_INCLUDE_DIRECTORIES>
|
$<TARGET_PROPERTY:ot-config,INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
|
native_its/include
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user