Skip to content

Commit 2955fcc

Browse files
committed
[crypto] PSA API: enable native ITS
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>
1 parent e8d2dea commit 2955fcc

File tree

12 files changed

+70
-6
lines changed

12 files changed

+70
-6
lines changed

examples/apps/cli/ftd.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ target_link_libraries(ot-cli-ftd PRIVATE
4141
openthread-cli-ftd
4242
${OT_PLATFORM_LIB_FTD}
4343
openthread-ftd
44-
${OT_PLATFORM_LIB_FTD}
4544
openthread-cli-ftd
4645
${OT_MBEDTLS}
46+
${OT_PLATFORM_LIB_FTD}
4747
ot-config-ftd
4848
ot-config
4949
)

examples/apps/cli/mtd.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ target_link_libraries(ot-cli-mtd PRIVATE
4141
openthread-cli-mtd
4242
${OT_PLATFORM_LIB_MTD}
4343
openthread-mtd
44-
${OT_PLATFORM_LIB_MTD}
4544
openthread-cli-mtd
4645
${OT_MBEDTLS}
46+
${OT_PLATFORM_LIB_MTD}
4747
ot-config-mtd
4848
ot-config
4949
)

examples/apps/ncp/ftd.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ target_link_libraries(ot-ncp-ftd PRIVATE
4141
openthread-ncp-ftd
4242
${OT_PLATFORM_LIB_FTD}
4343
openthread-ftd
44-
${OT_PLATFORM_LIB_FTD}
4544
openthread-ncp-ftd
4645
${OT_MBEDTLS}
46+
${OT_PLATFORM_LIB_FTD}
4747
ot-config-ftd
4848
ot-config
4949
)

examples/apps/ncp/mtd.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ target_link_libraries(ot-ncp-mtd PRIVATE
4141
openthread-ncp-mtd
4242
${OT_PLATFORM_LIB_MTD}
4343
openthread-mtd
44-
${OT_PLATFORM_LIB_MTD}
4544
openthread-ncp-mtd
4645
${OT_MBEDTLS}
46+
${OT_PLATFORM_LIB_MTD}
4747
ot-config-mtd
4848
ot-config
4949
)

examples/platforms/simulation/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ endif()
103103

104104
target_link_libraries(openthread-simulation PRIVATE
105105
openthread-platform
106+
mbedtls
107+
openthread-native-its-file
106108
ot-simulation-config
107109
ot-config
108-
mbedtls
109110
)
110111

111112
target_compile_options(openthread-simulation PRIVATE

examples/platforms/simulation/system.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ extern otRadioCaps gRadioCaps;
6161

6262
static volatile bool gTerminate = false;
6363

64+
#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE && (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
65+
static char sNativeItsFileNamePrefix[256];
66+
extern const char *gItsFileNamePrefix;
67+
#endif
68+
6469
static void handleSignal(int aSignal)
6570
{
6671
OT_UNUSED_VARIABLE(aSignal);
@@ -193,6 +198,12 @@ void otSysInit(int aArgCount, char *aArgVector[])
193198
signal(SIGTERM, &handleSignal);
194199
signal(SIGHUP, &handleSignal);
195200

201+
#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE && (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
202+
snprintf(sNativeItsFileNamePrefix, sizeof(sNativeItsFileNamePrefix), "%s/%s_%d_",
203+
OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH, getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId);
204+
gItsFileNamePrefix = sNativeItsFileNamePrefix;
205+
#endif
206+
196207
platformLoggingInit(basename(aArgVector[0]));
197208
platformAlarmInit(speedUpFactor);
198209
platformRadioInit();

examples/platforms/simulation/virtual_time/platform-sim.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ static volatile bool gTerminate = false;
6060
int gArgumentsCount = 0;
6161
char **gArguments = NULL;
6262

63+
#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE && (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
64+
static char sNativeItsFileNamePrefix[256];
65+
extern const char *gItsFileNamePrefix;
66+
#endif
67+
6368
uint64_t sNow = 0; // microseconds
6469
int sSockFd;
6570
uint16_t sPortBase = 9000;
@@ -222,6 +227,12 @@ void otSysInit(int argc, char *argv[])
222227
DieNow(OT_EXIT_FAILURE);
223228
}
224229

230+
#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE && (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
231+
snprintf(sNativeItsFileNamePrefix, sizeof(sNativeItsFileNamePrefix), "%s/%s_%d_",
232+
OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH, getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId);
233+
gItsFileNamePrefix = sNativeItsFileNamePrefix;
234+
#endif
235+
225236
socket_init();
226237

227238
platformAlarmInit(1);

tests/gtest/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ add_library(ot-fake-platform
4242
)
4343
target_link_libraries(ot-fake-platform
4444
ot-config
45+
${OT_MBEDTLS}
46+
openthread-native-its-ram
4547
)
4648

4749
add_library(ot-fake-ftd INTERFACE)

tests/gtest/fake_platform.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
#include <openthread/platform/trel.h>
5050
#include <openthread/platform/udp.h>
5151

52+
#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
53+
#include <psa/crypto.h>
54+
#endif
55+
5256
using namespace ot;
5357

5458
bool operator<(const otExtAddress &aLeft, const otExtAddress &aRight)
@@ -480,6 +484,38 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
480484
return error;
481485
}
482486

487+
#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA) && defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
488+
/**
489+
* When OpenThread is compiled with the PSA Crypto backend using Mbed TLS 3.x, there is no
490+
* API to configure a dedicated non-default entropy source. It is documented that a future version of
491+
* Mbed TLS (likely 4.x) will include a PSA interface for configuring entropy sources.
492+
*
493+
* For now, we need to define the external RNG. Since the implementation of `otPlatEntropyGet` already
494+
* uses CSPRNG, we will call it here as well.
495+
*/
496+
extern "C" psa_status_t mbedtls_psa_external_get_random(mbedtls_psa_external_random_context_t *context,
497+
uint8_t *output,
498+
size_t output_size,
499+
size_t *output_length)
500+
{
501+
OT_UNUSED_VARIABLE(context);
502+
503+
otError error;
504+
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
505+
506+
error = otPlatEntropyGet(output, (uint16_t)output_size);
507+
if (error == OT_ERROR_NONE)
508+
{
509+
*output_length = output_size;
510+
status = PSA_SUCCESS;
511+
}
512+
513+
return status;
514+
}
515+
#endif
516+
517+
// otError otPlatCryptoExportKey(otCryptoKeyRef, uint8_t *, size_t, size_t *) { return OT_ERROR_NONE; }
518+
483519
void otPlatDiagSetOutputCallback(otInstance *, otPlatDiagOutputCallback, void *) {}
484520

485521
void otPlatDiagModeSet(bool) {}

tests/unit/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ set(COMMON_LIBS
117117
ot-test-platform-ftd
118118
openthread-ftd
119119
ot-test-platform-ftd
120-
${OT_MBEDTLS}
121120
ot-config
122121
openthread-ftd
123122
openthread-url
123+
${OT_MBEDTLS}
124+
openthread-native-its-ram
124125
)
125126

126127
set(COMMON_LIBS_RCP

0 commit comments

Comments
 (0)