mirror of
https://github.com/espressif/openthread.git
synced 2026-06-06 05:24:51 +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 <lukasz.duda@nordicsemi.no>
This commit is contained in:
@@ -48,9 +48,9 @@ target_link_libraries(ot-cli-ftd PRIVATE
|
||||
openthread-cli-ftd
|
||||
${OT_PLATFORM_LIB_FTD}
|
||||
openthread-ftd
|
||||
${OT_PLATFORM_LIB_FTD}
|
||||
openthread-cli-ftd
|
||||
${OT_MBEDTLS}
|
||||
${OT_PLATFORM_LIB_FTD}
|
||||
ot-config-ftd
|
||||
ot-config
|
||||
)
|
||||
|
||||
@@ -48,9 +48,9 @@ target_link_libraries(ot-cli-mtd PRIVATE
|
||||
openthread-cli-mtd
|
||||
${OT_PLATFORM_LIB_MTD}
|
||||
openthread-mtd
|
||||
${OT_PLATFORM_LIB_MTD}
|
||||
openthread-cli-mtd
|
||||
${OT_MBEDTLS}
|
||||
${OT_PLATFORM_LIB_MTD}
|
||||
ot-config-mtd
|
||||
ot-config
|
||||
)
|
||||
|
||||
@@ -41,9 +41,9 @@ target_link_libraries(ot-ncp-ftd PRIVATE
|
||||
openthread-ncp-ftd
|
||||
${OT_PLATFORM_LIB_FTD}
|
||||
openthread-ftd
|
||||
${OT_PLATFORM_LIB_FTD}
|
||||
openthread-ncp-ftd
|
||||
${OT_MBEDTLS}
|
||||
${OT_PLATFORM_LIB_FTD}
|
||||
ot-config-ftd
|
||||
ot-config
|
||||
)
|
||||
|
||||
@@ -41,9 +41,9 @@ target_link_libraries(ot-ncp-mtd PRIVATE
|
||||
openthread-ncp-mtd
|
||||
${OT_PLATFORM_LIB_MTD}
|
||||
openthread-mtd
|
||||
${OT_PLATFORM_LIB_MTD}
|
||||
openthread-ncp-mtd
|
||||
${OT_MBEDTLS}
|
||||
${OT_PLATFORM_LIB_MTD}
|
||||
ot-config-mtd
|
||||
ot-config
|
||||
)
|
||||
|
||||
@@ -103,9 +103,10 @@ endif()
|
||||
|
||||
target_link_libraries(openthread-simulation PRIVATE
|
||||
openthread-platform
|
||||
mbedtls
|
||||
openthread-native-its-file
|
||||
ot-simulation-config
|
||||
ot-config
|
||||
mbedtls
|
||||
)
|
||||
|
||||
target_compile_options(openthread-simulation PRIVATE
|
||||
|
||||
@@ -64,6 +64,11 @@ extern otRadioCaps gRadioCaps;
|
||||
|
||||
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)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aSignal);
|
||||
@@ -196,6 +201,12 @@ void otSysInit(int aArgCount, char *aArgVector[])
|
||||
signal(SIGTERM, &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]));
|
||||
platformAlarmInit(speedUpFactor);
|
||||
platformRadioInit();
|
||||
|
||||
@@ -64,6 +64,11 @@ static bool sUseUnixSocket = false;
|
||||
int gArgumentsCount = 0;
|
||||
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
|
||||
int sSockFd;
|
||||
uint16_t sPortBase = 9000;
|
||||
@@ -273,6 +278,12 @@ void otSysInit(int argc, char *argv[])
|
||||
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();
|
||||
|
||||
platformAlarmInit(1);
|
||||
|
||||
@@ -309,6 +309,7 @@ Instance::Instance(void)
|
||||
, mIsInitialized(false)
|
||||
, 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_STATIC_INSTANCE_ENABLE
|
||||
mCryptoStorageKeyRefManager.SetKeyRefExtraOffset(Crypto::Storage::KeyRefManager::kKeyRefExtraOffset * GetIdx(this));
|
||||
@@ -317,6 +318,7 @@ Instance::Instance(void)
|
||||
"The `KeyRef` values will be shared across different `Instance` objects"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#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
|
||||
ot-config
|
||||
${OT_MBEDTLS}
|
||||
openthread-native-its-ram
|
||||
)
|
||||
|
||||
add_library(ot-fake-ftd INTERFACE)
|
||||
|
||||
@@ -50,6 +50,10 @@
|
||||
#include <openthread/platform/trel.h>
|
||||
#include <openthread/platform/udp.h>
|
||||
|
||||
#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
|
||||
#include <psa/crypto.h>
|
||||
#endif
|
||||
|
||||
using namespace ot;
|
||||
|
||||
bool operator<(const otExtAddress &aLeft, const otExtAddress &aRight)
|
||||
@@ -482,6 +486,36 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
|
||||
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 otPlatDiagModeSet(bool) {}
|
||||
|
||||
@@ -117,10 +117,11 @@ set(COMMON_LIBS
|
||||
ot-test-platform-ftd
|
||||
openthread-ftd
|
||||
ot-test-platform-ftd
|
||||
${OT_MBEDTLS}
|
||||
ot-config
|
||||
openthread-ftd
|
||||
openthread-url
|
||||
${OT_MBEDTLS}
|
||||
openthread-native-its-ram
|
||||
)
|
||||
|
||||
set(COMMON_LIBS_RCP
|
||||
|
||||
Vendored
+1
@@ -28,6 +28,7 @@
|
||||
|
||||
if(NOT OT_EXTERNAL_MBEDTLS)
|
||||
add_subdirectory(mbedtls)
|
||||
add_subdirectory(mbedtls/native_its)
|
||||
endif()
|
||||
|
||||
add_subdirectory(tcplp)
|
||||
|
||||
Vendored
+1
@@ -140,4 +140,5 @@ target_include_directories(mbedcrypto
|
||||
PRIVATE
|
||||
${OT_PUBLIC_INCLUDES}
|
||||
$<TARGET_PROPERTY:ot-config,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
native_its/include
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user