Skip to content

[Backport 3.6] PSA: use static key slots to store keys #9448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

valeriosetti
Copy link
Contributor

@valeriosetti valeriosetti commented Aug 5, 2024

Description

This is the backport of #9302 to the 3.6 LTS branch.

PR checklist

@valeriosetti valeriosetti added needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review priority-high High priority - will be reviewed soon size-xs Estimated task size: extra small (a few hours at most) labels Aug 5, 2024
@valeriosetti valeriosetti self-assigned this Aug 5, 2024
@valeriosetti valeriosetti changed the base branch from development to mbedtls-3.6 August 5, 2024 14:47
@valeriosetti valeriosetti removed the needs-ci Needs to pass CI tests label Aug 6, 2024
@valeriosetti
Copy link
Contributor Author

I removed the need-ci label because the OpenCI is fine. Failures were only found in the InternalCI (which I cannot check), but since they are not confirmed by the OpenCI, I think they might be spurious failures.

@valeriosetti valeriosetti force-pushed the psa-use-static-slots-backport branch from 3b4b7bc to 1c68450 Compare August 6, 2024 13:18
@tom-cosgrove-arm
Copy link
Contributor

Note: conflicts

@gilles-peskine-arm
Copy link
Contributor

Now that the main PR has been approved, please complete and rebase this backport.

@gilles-peskine-arm gilles-peskine-arm added needs-work size-s Estimated task size: small (~2d) and removed needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review size-xs Estimated task size: extra small (a few hours at most) labels Oct 7, 2024
@valeriosetti valeriosetti force-pushed the psa-use-static-slots-backport branch from 1c68450 to a65c8a0 Compare October 8, 2024 12:55
@valeriosetti valeriosetti added needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests and removed needs-work labels Oct 8, 2024
@valeriosetti
Copy link
Contributor Author

I've just backported all the commits from #9302 to mbedtls-3.6. Only some of them required a manual fix, in particular a couple of *.data files (pkwrite and pkparse) that were moved in tf-psa-crypto in the development branch.

depends_on:MBEDTLS_RSA_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_PEM_WRITE_C
pk_write_pubkey_check:"../framework/data_files/rsa4096_pub.pem":TEST_PEM
depends_on:MBEDTLS_RSA_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_PEM_WRITE_C:MBEDTLS_TEST_PK_ALLOW_RSA_KEY_PAIR_4096
pk_write_pubkey_check:"../../framework/data_files/rsa4096_pub.pem":TEST_PEM
Copy link
Contributor

Choose a reason for hiding this comment

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

How come this line needs ../../framework but line 7 only needs ../framework?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ops, sorry, that's one of the 2 files who had conflicts during the rebase and apprently I missed a change here :/

@valeriosetti valeriosetti force-pushed the psa-use-static-slots-backport branch from a65c8a0 to c6e50d0 Compare October 8, 2024 15:03
…est symbols

- MBEDTLS_TEST_STATIC_KEY_SLOTS_SUPPORT_RSA_[2048/4096] are always
  defined because they are only used in test_suite_psa_crypto
  tests.

- MBEDTLS_TEST_ALLOW_RSA_4096 was renamed as
  MBEDTLS_TEST_PK_ALLOW_RSA_KEY_PAIR_4096 because this is only used in
  PK related test suites.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
…r size

Instead of skipping some tests when !MBEDTLS_PSA_STATIC_KEY_SLOTS,
add a proper check in the depends_on to verify if
MBEDTLS_PSA_KEY_BUFFER_MAX_SIZE is actually large enough to contain
the key used in such test.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
…EQUEST

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
…RT_RSA_xxx

PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE() is not defined when there
is no MBEDTLS_PSA_CRYPTO_CLIENT so we need this guard to
define MBEDTLS_TEST_STATIC_KEY_SLOTS_SUPPORT_RSA_[2048/4096].

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
MBEDTLS_PSA_KEY_BUFFER_MAX_SIZE is only used in tests so it should
not be defined in a public header such as "crypto_extra.h".
"psa_crypto_helpers.h" is a better option.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
- psa_crypto_helpers.h

mbedtls-3.6 branch misses some crypto client changes that has
been done in the development branch since the LTS release. Therefore
CRYPTO_C guard here is more accurate than CRYPTO_CLIENT.

- entropy.h

In the development branch MBEDTLS_ENTROPY_BLOCK_SIZE is defined
when PSA_WANT_ALG_SHA_[256/512] is defined while in the mbedtls-3.6
branch is guarded by MBEDTLS_MD_CAN_SHA[256/512] which is slightly
different. Since MBEDTLS_ENTROPY_BLOCK_SIZE is used in some tests's
data files, we need to have it defined also if the related test
is skipped. Therefore we add the PSA_WANT_ALG_SHA conditions together
with the MBEDTLS_MD_CAN_SHA ones to mimic the development behavior.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
@valeriosetti
Copy link
Contributor Author

I just backported the same changes done in development #9302 (comment)

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

Looks good to me after rebase from my previous approval at b287a40 to the current head at 40859ac.

Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-arm left a comment

Choose a reason for hiding this comment

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

LGTM

@tom-cosgrove-arm tom-cosgrove-arm added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Oct 24, 2024
@gilles-peskine-arm gilles-peskine-arm added this pull request to the merge queue Oct 24, 2024
Merged via the queue into Mbed-TLS:mbedtls-3.6 with commit 0b8b7a1 Oct 24, 2024
4 of 5 checks passed
valeriosetti added a commit to valeriosetti/zephyr-mbedtls that referenced this pull request Oct 24, 2024
This commit takes only the relevant part of PR
Mbed-TLS/mbedtls#9448 that was merged
in upstream Mbed TLS in the LTS branch "mbedtls-3.6".
Since the original PR was made of several commits, but most
of them were only affecting tests cases (not used in Zephyr),
only relevant changes were extracted from the PR and squashed
in a single commit.

Changes introduced in this commit will be automatically
included in 3.6.3, so by the time Zephyr's Mbed TLS fork repo
is bumbed to that official release, this commit MUST be
discarded.

This commit introduces the possibility to use static key slot
buffers in the PSA core instead of dynamically allocating them
when needed. This helps reducing heap memory usage as well as
potentially removing heap management ROM code if heap is not
used anywhere else in the Zephyr application.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
valeriosetti added a commit to valeriosetti/zephyr-mbedtls that referenced this pull request Oct 24, 2024
This commit takes only relevant changes of PR
Mbed-TLS/mbedtls#9448 that was merged
in upstream Mbed TLS in the LTS branch "mbedtls-3.6".
Since the original PR was made of several commits, but most
of them were only affecting tests cases (not used in Zephyr),
only changes belonging to the "include" and "library" folders
were included here.

== IMPORTANT ==
Changes introduced in this commit will be automatically
part of Mbed TLS release 3.6.3, so by the time Zephyr's
Mbed TLS fork repo is bumbed to that official release,
this commit MUST be discarded.

This commit introduces the possibility to use static key slot
buffers in the PSA core instead of dynamically allocating them
when needed. This helps reducing heap memory usage as well as
potentially removing heap management ROM code if heap is not
used anywhere else in the Zephyr application.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
carlescufi pushed a commit to zephyrproject-rtos/mbedtls that referenced this pull request Nov 20, 2024
This commit takes only relevant changes of PR
Mbed-TLS/mbedtls#9448 that was merged
in upstream Mbed TLS in the LTS branch "mbedtls-3.6".
Since the original PR was made of several commits, but most
of them were only affecting tests cases (not used in Zephyr),
only changes belonging to the "include" and "library" folders
were included here.

== IMPORTANT ==
Changes introduced in this commit will be automatically
part of Mbed TLS release 3.6.3, so by the time Zephyr's
Mbed TLS fork repo is bumbed to that official release,
this commit MUST be discarded.

This commit introduces the possibility to use static key slot
buffers in the PSA core instead of dynamically allocating them
when needed. This helps reducing heap memory usage as well as
potentially removing heap management ROM code if heap is not
used anywhere else in the Zephyr application.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
@valeriosetti valeriosetti deleted the psa-use-static-slots-backport branch December 6, 2024 08:22
frkv pushed a commit to frkv/sdk-mbedtls that referenced this pull request Feb 4, 2025
This commit takes only relevant changes of PR
Mbed-TLS/mbedtls#9448 that was merged
in upstream Mbed TLS in the LTS branch "mbedtls-3.6".
Since the original PR was made of several commits, but most
of them were only affecting tests cases (not used in Zephyr),
only changes belonging to the "include" and "library" folders
were included here.

== IMPORTANT ==
Changes introduced in this commit will be automatically
part of Mbed TLS release 3.6.3, so by the time Zephyr's
Mbed TLS fork repo is bumbed to that official release,
this commit MUST be discarded.

This commit introduces the possibility to use static key slot
buffers in the PSA core instead of dynamically allocating them
when needed. This helps reducing heap memory usage as well as
potentially removing heap management ROM code if heap is not
used anywhere else in the Zephyr application.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no>
(Cherry-picked from commit 4952e13)
Dat-NguyenDuy pushed a commit to nxp-upstream/zephyr-mbedtls that referenced this pull request Apr 4, 2025
This commit takes only relevant changes of PR
Mbed-TLS/mbedtls#9448 that was merged
in upstream Mbed TLS in the LTS branch "mbedtls-3.6".
Since the original PR was made of several commits, but most
of them were only affecting tests cases (not used in Zephyr),
only changes belonging to the "include" and "library" folders
were included here.

== IMPORTANT ==
Changes introduced in this commit will be automatically
part of Mbed TLS release 3.6.3, so by the time Zephyr's
Mbed TLS fork repo is bumbed to that official release,
this commit MUST be discarded.

This commit introduces the possibility to use static key slot
buffers in the PSA core instead of dynamically allocating them
when needed. This helps reducing heap memory usage as well as
potentially removing heap management ROM code if heap is not
used anywhere else in the Zephyr application.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports priority-high High priority - will be reviewed soon size-s Estimated task size: small (~2d)
Projects
Development

Successfully merging this pull request may close these issues.

3 participants