Skip to content

Conversation

@valeriosetti
Copy link
Contributor

@valeriosetti valeriosetti commented Oct 22, 2025

Modify OpenThread's Kconfig options in order to always use PSA Crypto API by default instead of legacy Mbed TLS crypto.
Please check commits messages for details.

These changes were tested with zephyr/samples/net/openthread/coap/ on 2x nrf52840dk boards .

CONFIG_OPENTHREAD_NETWORK_NAME="OpenThreadDemo"

# Use ZMS as storage backend for Secure Storage
CONFIG_SECURE_STORAGE_ITS_STORE_IMPLEMENTATION_ZMS=y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we need this in other samples as well? And those generic networking samples that have overlay-ot.conf?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still no clear to me, do we need thsoe configs in other samples/OT overlays as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still working on making other samples building properly :). I think the CI is not even testing them and they need fixes for sure.
I just pushed the PR to let @tomi-font and other reviewers see requested changes in place ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the DNM label to ensure that this PR is not merged accidentally before we're happy with test coverage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say just enable the Settings backend instead, it's the simplest to enable, just a Kconfig option, no DT overlay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even with CONFIG_SECURE_STORAGE_ITS_STORE_IMPLEMENTATION_SETTINGS you need to select the backend for Settings, otherwise CONFIG_SETTINGS_NONE would be used.
Then if I enable Settings to use ZMS as backend, why not using ZMS directly from Secure Storage and save some footprint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still no clear to me, do we need thsoe configs in other samples/OT overlays as well?

@rlubos I finally had the time to check this question.
Apparently samples/net/openthread/border_router already enables NVS so we don't need ZMS in this case. The same holds also for samples/net/openthread/coprocessor and for samples/net/openthread/shell.

For sake of uniformity I think it's better to enable NVS also in the samples/net/openthread/border_router instead of ZMS as I did previously.

@Cristib05
Copy link
Contributor

Hi @valeriosetti. I have been debugging more in OpenThread border router application from samples/net/openthread/border_router.
At the moment, I have found one issue, related to TREL:
Here is the app call stack:
image
One issue is in psa_key_derivation_setup function. At the moment, the result is return PSA_ERROR_NOT_SUPPORTED;
image
It seems like AT_LEAST_ONE_BUILTIN_KDF has to be defined for an actual call to be made, but I am not sure what flag is required to have this enabled.
image
The question is what flag I should define not to break the functionality and enable the computation of key?

@valeriosetti
Copy link
Contributor Author

It seems like AT_LEAST_ONE_BUILTIN_KDF has to be defined for an actual call to be made, but I am not sure what flag is required to have this enabled.

This is an amazing feedback, thanks! I added a new commit in the series which hopefully should enable what was missing. Can you please give it another try?

@Cristib05
Copy link
Contributor

It seems like AT_LEAST_ONE_BUILTIN_KDF has to be defined for an actual call to be made, but I am not sure what flag is required to have this enabled.

This is an amazing feedback, thanks! I added a new commit in the series which hopefully should enable what was missing. Can you please give it another try?

Meanwhile I have managed to have a working joiner-commissioner scenario on OpenThread Border Router sample. I will compare my changes with yours and let you know. Thanks for the new commit!

@Cristib05
Copy link
Contributor

It seems like AT_LEAST_ONE_BUILTIN_KDF has to be defined for an actual call to be made, but I am not sure what flag is required to have this enabled.

This is an amazing feedback, thanks! I added a new commit in the series which hopefully should enable what was missing. Can you please give it another try?

Meanwhile I have managed to have a working joiner-commissioner scenario on OpenThread Border Router sample. I will compare my changes with yours and let you know. Thanks for the new commit!

Hi @valeriosetti,
For the joiner-commissioner scenario, I have found that those settings are required:
select PSA_WANT_ALG_TLS12_PRF if OPENTHREAD_COMMISSIONER_JOINER
select PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS if OPENTHREAD_COMMISSIONER_JOINER
I also needed to increase CONFIG_MBEDTLS_HEAP_SIZE from 10240 to 15360, but I guess this can be further optimized.

Related to your commit from yesterday,
select PSA_WANT_ALG_HKDF if OPENTHREAD_COMMISSIONER_JOINER
select PSA_WANT_ALG_HKDF_EXTRACT if OPENTHREAD_COMMISSIONER_JOINER
select PSA_WANT_ALG_HKDF_EXPAND if OPENTHREAD_COMMISSIONER_JOINER,
I think that those are not required by OPENTHREAD_COMMISSIONER_JOINER. Maybe this should fall under something related to TREL or Border Router, as HKDF-SHA256 is required by TREL.

Related to TREL initialization, I made use of PSA switch proposal from OpenThread, openthread/openthread@3a6573f#diff-8d6dc63e1ec9adacf9f4215b293513b17f39a8127ea4b89100db42976adace44,
and for KeyManager::ComputeTrelKey to work, a small addition is required in https://github.com/zephyrproject-rtos/zephyr/blob/main/modules/openthread/platform/crypto_psa.c#L97, OT_CRYPTO_KEY_USAGE_DERIVE should also be added to the list of supported flags.

@valeriosetti
Copy link
Contributor Author

valeriosetti commented Nov 26, 2025

I think that those are not required by OPENTHREAD_COMMISSIONER_JOINER. Maybe this should fall under something related to TREL or Border Router, as HKDF-SHA256 is required by TREL.

Thanks for the suggestion. I updated the commit with the information you provided.

Related to TREL initialization, I made use of PSA switch proposal from OpenThread, openthread/openthread@3a6573f#diff-8d6dc63e1ec9adacf9f4215b293513b17f39a8127ea4b89100db42976adace44, and for KeyManager::ComputeTrelKey to work

I updated the companion PR to entirely cherry-pick the commit from the PR on the official OT repo. Previously I only took some part of it.

a small addition is required in https://github.com/zephyrproject-rtos/zephyr/blob/main/modules/openthread/platform/crypto_psa.c#L97, OT_CRYPTO_KEY_USAGE_DERIVE should also be added to the list of supported flags.

Done. Thanks.

@valeriosetti
Copy link
Contributor Author

@Cristib05 did you have a chance to retest this PR after I applied all the changes you proposed in your last message?
I would like to keep this PR progressing and having it completed asap

@Cristib05
Copy link
Contributor

@Cristib05 did you have a chance to retest this PR after I applied all the changes you proposed in your last message? I would like to keep this PR progressing and having it completed asap

Hi @valeriosetti, I managed to re-test using your latest changes. I have tested the following:

  1. joiner-commissioner on 15.4 https://github.com/openthread/openthread/blob/main/src/cli/README_COMMISSIONING.md
  2. external commissioner on Border Router
  3. TREL communication between RW612 Zephyr OTBR and RPI
  4. SRP service registration between RW612 Zephyr OTBR and RPI

Thanks for your updates!

Copy link
Contributor

@tomi-font tomi-font left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenThread needs a PSA ITS provider when using PSA Crypto API, therefore
we enable Secure Storage in builds without TF-M.

Signed-off-by: Valerio Setti <[email protected]>
Make CONFIG_OPENTHREAD_CRYPTO_PSA as enabled by default in order to use
PSA Crypto API instead of legacy Mbed TLS' crypto. This is done with the
final goal to deprecate and remove usage of legacy crypto support in
the near future from Zephyr codebase.

Signed-off-by: Valerio Setti <[email protected]>
Secure Storage is used as PSA ITS in builds where TF-M is not enabled,
but it needs a storage backend where to physically save data.
If CONFIG_SECURE_STORAGE_ITS_STORE_IMPLEMENTATION_ZMS is used then its
"depends on" guarantee that there is a partition to use as physical
storage.
If CONFIG_SECURE_STORAGE_ITS_STORE_IMPLEMENTATION_SETTINGS is used instead
we want to ensure that CONFIG_SETTINGS_NONE doesn't gets selected which
would result in Settings not being able to store data anywhere.

This commit add a depends_on for this last case.

Signed-off-by: Valerio Setti <[email protected]>
Allow MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED to work with either legacy
crypto (i.e. MBEDTLS_ECJPAKE_C) or PSA Crypto API
(i.e. PSA_WANT_ALG_JPAKE).

Signed-off-by: Valerio Setti <[email protected]>
When PSA Crypto API are used they need a PSA ITS implementation and this
is provided by Secure Storage if TF-M is not enabled in the build.
Secure Storage can use Settings as backend and Settings, on its turn, can
use several other backends to store data (ex: ZMS, NVS, etc).
Since NVS is already enabled in other OpenThread Zephyr samples, let's
enable NVS also for this sample.

While at it, also slightly re-organize "sample.yaml" to share more data
between tests and allow building and testing also on the nrf52840dk board.

Signed-off-by: Valerio Setti <[email protected]>
crypto_psa.c was missing an implementation for the following functions:
- otPlatCryptoHkdfInit
- otPlatCryptoHkdfExtract
- otPlatCryptoHkdfExpand
- otPlatCryptoHkdfDeinit
which provide support for HKDF using PSA Crypto API.

This commit fill this gap by copying the implementation from upstream
PR 11445.

Signed-off-by: Valerio Setti <[email protected]>
Select proper PSA_WANT requirements in CONFIG_OPENTHREAD_CRYPTO_PSA_CONFIG
in order to enable KDF algorithms.

Signed-off-by: Valerio Setti <[email protected]>
Increase heap memory when OpenThread is enabled and either "commissioner"
or "joiner" roles are used.

Signed-off-by: Valerio Setti <[email protected]>
Simply move the definition of OPENTHREAD_CRYPTO_PSA Konfig before crypto
configuration related Kconfigs.

Signed-off-by: Valerio Setti <[email protected]>
Include new definitions in crypto.h in order support HKDF algorithm.

Signed-off-by: Valerio Setti <[email protected]>
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mbedTLS / PSA Crypto area: Networking area: OpenThread area: Samples Samples area: Secure Storage Secure Storage DNM (manifest) This PR should not be merged (controlled by action-manifest) DNM This PR should not be merged (Do Not Merge) manifest manifest-openthread Release Notes To be mentioned in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants