Skip to content

Backport 3.6: md: allow dispatch to PSA whenever CRYPTO_CLIENT is enabled #9562

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

Merged
merged 8 commits into from
Mar 4, 2025

Conversation

valeriosetti
Copy link
Contributor

@valeriosetti valeriosetti commented Sep 13, 2024

Description

Instead of allowing PSA dispatching only when CRYPTO_C is set and some MBEDTLS_PSA_ACCEL_ALG_xxx is set, we enable dispatching when CRYPTO_CLIENT and PSA_WANT_ALG_xxx are set. This makes the feature more useful in cases where the PSA support is provided externally, like for example TF-M in Zephyr.

PR checklist

@valeriosetti valeriosetti self-assigned this Sep 13, 2024
@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 size-xs Estimated task size: extra small (a few hours at most) labels Sep 13, 2024
@valeriosetti valeriosetti requested a review from mpg September 13, 2024 09:11
@valeriosetti
Copy link
Contributor Author

@mpg I took the liberty to add you as reviewer because you were the one who improved MD last year, allowing for the PSA dispatch, and we also discussed about this change in Slack. However if you don't have enough review bandwidth for this, please let me know and I'll remove you ;)

@valeriosetti valeriosetti force-pushed the md-psa-dispatch-3.6 branch 2 times, most recently from a011d15 to 51772c4 Compare September 16, 2024 08:55
@valeriosetti
Copy link
Contributor Author

The ABI-API break is expected because struct mbedtls_md_context_t will change its size depending on PSA_WANT_ instead of MBEDTLS_PSA_ACCEL_ symbols.

@valeriosetti valeriosetti force-pushed the md-psa-dispatch-3.6 branch 3 times, most recently from acd4c96 to e43f2e1 Compare September 16, 2024 13:27
@valeriosetti valeriosetti removed the needs-ci Needs to pass CI tests label Sep 16, 2024
@valeriosetti
Copy link
Contributor Author

CI green (a part from the ABI-API failure mentioned above), so I think the PR is ready for reviews

@mpg
Copy link
Contributor

mpg commented Sep 17, 2024

  • changelog TBD, but I would like to have some feedback from reviewers about this change before doing it.

IMO not ChangeLog for this, as support for CLIENT && !C is not official yet, and when it will become official it will have a ChangeLog entry with a scope much broader than just this :)

@mpg
Copy link
Contributor

mpg commented Sep 17, 2024

  • development PR not required because, if I'm not wrong, the MD module is internal in development, so the user is not able to make direct usage of it.

The current plan is for MD to remain public in 4.0, so I think we want to forward-port this to development. However there might be other changes planned (or already done) in development that would make this moot, I'm not sure. Cc @gilles-peskine-arm

@mpg
Copy link
Contributor

mpg commented Sep 17, 2024

The ABI-API break is expected because struct mbedtls_md_context_t will change its size depending on PSA_WANT_ instead of MBEDTLS_PSA_ACCEL_ symbols.

Aw, I'm afraid this is a blocker. We promise not to change the ABI in LTS branches (which 3.6 now is) unless we can't find another way to fix a security issue. So, changing the size of struct mbedtls_md_context_t in the default configuration is not something we can do in 3.6.

Would there be a way to achieve what you're after while keeping the structure unchanged in the default config, and only changing it in a few specific configs?

@mpg mpg added the needs-work label Sep 17, 2024
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

@valeriosetti
Copy link
Contributor Author

The current plan is for MD to remain public in 4.0, so I think we want to forward-port this to development.

Oh, I see. I based my previous comment on the fact that md.h header is now in tf-psa-crypto/drivers/builtin/include/mbedtls/md.h which looks like a quite "hidden" place not meant to be included by end user's code directly. However I surely missed something, so please apologize for the wrong assumption.

Would there be a way to achieve what you're after while keeping the structure unchanged in the default config, and only changing it in a few specific configs?

I think the easiest way will be to enable PSA dispatching based on PSA_WANTs only in the usual CRYPTO_CLIENT && !CRYPTO_C configuration. This is still relevant for Mbed TLS users like Zephyr, but it does not affect the default configuration. I will try to rework the PR in this direction.

@gilles-peskine-arm
Copy link
Contributor

gilles-peskine-arm commented Sep 17, 2024

The current plan is for MD to remain public in 4.0, so I think we want to forward-port this to development.

Oh, I see. I based my previous comment on the fact that md.h header is now in tf-psa-crypto/drivers/builtin/include/mbedtls/md.h which looks like a quite "hidden" place not meant to be included by end user's code directly. However I surely missed something, so please apologize for the wrong assumption.

Currently all of the legacy crypto headers have moved as part of the work to split the repositories. We'll move some of them again as part of the work to evolve the API. md.h will remain public (but without HMAC functionality). Most other crypto headers will become private or unstable.

Sorry about the lack of clarity. We're still working on clarifying what's going to happen and making a plan for it to happen in time.

@valeriosetti
Copy link
Contributor Author

valeriosetti commented Sep 17, 2024

Would there be a way to achieve what you're after while keeping the structure unchanged in the default config, and only changing it in a few specific configs?

I think the easiest way will be to enable PSA dispatching based on PSA_WANTs only in the usual CRYPTO_CLIENT && !CRYPTO_C configuration. This is still relevant for Mbed TLS users like Zephyr, but it does not affect the default configuration. I will try to rework the PR in this direction.

Thanks to this change the ABI-API failure disappeared and the CI is fully green now :)

The current plan is for MD to remain public in 4.0, so I think we want to forward-port this to development.

Oh, I see. I based my previous comment on the fact that md.h header is now in tf-psa-crypto/drivers/builtin/include/mbedtls/md.h which looks like a quite "hidden" place not meant to be included by end user's code directly. However I surely missed something, so please apologize for the wrong assumption.

Currently all of the legacy crypto headers have moved as part of the work to split the repositories. We'll move some of them again as part of the work to evolve the API. #8450 (but without HMAC functionality). #8663.

Thanks a lot for the update! So I think that the forward port of this fix will need to wait until MD design is stabilized/planned on development.

mpg
mpg previously approved these changes Sep 19, 2024
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@gilles-peskine-arm gilles-peskine-arm added priority-medium Medium priority - this can be reviewed as time permits component-psa PSA keystore/dispatch layer (storage, drivers, …) and removed needs-reviewer This PR needs someone to pick it up for review labels Oct 28, 2024
@gilles-peskine-arm gilles-peskine-arm self-requested a review October 28, 2024 10:44
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.

Thanks for updating the documentation! Looks good to me now.

mpg
mpg previously approved these changes Feb 26, 2025
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mpg mpg added approved Design and code approved - may be waiting for CI or backports needs-preceding-pr Requires another PR to be merged first and removed needs-review Every commit must be reviewed by at least two team members, labels Feb 26, 2025
@mpg
Copy link
Contributor

mpg commented Feb 28, 2025

@valeriosetti can you update the submodule pointer now that Mbed-TLS/mbedtls-framework#140 has been merged?

Signed-off-by: Valerio Setti <[email protected]>
@valeriosetti valeriosetti dismissed stale reviews from mpg and gilles-peskine-arm via bc55af8 February 28, 2025 11:18
@valeriosetti valeriosetti removed the needs-preceding-pr Requires another PR to be merged first label Feb 28, 2025
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.

LGTM after framework update

@gilles-peskine-arm gilles-peskine-arm added the needs-backports Backports are missing or are pending review and approval. label Feb 28, 2025
@gilles-peskine-arm
Copy link
Contributor

Can you please make a PR to development? Sure, the md interface will change, but that doesn't affect the changes here.

@valeriosetti
Copy link
Contributor Author

Can you please make a PR to development? Sure, the md interface will change, but that doesn't affect the changes here.

I was about to start the forward porting few days ago, but then went checking the current status of development. There MD module is internal in TF-PSA-Crypto repo so in theory end users should not include/use it directly. As far as I saw TLS code only imports md.h to have new types definition and few #defines.
In short, I didn't saw any benefit in forward porting this PR so I stopped. Do you think it's still worth it? If so I can start the forward port anyway

@gilles-peskine-arm
Copy link
Contributor

md.h will remain public in TF-PSA-Crypto 1.x, with a subset of functionality: just hash calculation, not HMAC or metadata. Basically the current MBEDTLS_MD_LIGHT.

@gilles-peskine-arm gilles-peskine-arm changed the title md: allow dispatch to PSA whenever CRYPTO_CLIENT is enabled Backport 3.6: md: allow dispatch to PSA whenever CRYPTO_CLIENT is enabled Feb 28, 2025
@mpg mpg removed the needs-backports Backports are missing or are pending review and approval. label Mar 4, 2025
@mpg mpg added this pull request to the merge queue Mar 4, 2025
Merged via the queue into Mbed-TLS:mbedtls-3.6 with commit 1d25c71 Mar 4, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from Has Approval to Done in Roadmap pull requests (new board) Mar 4, 2025
@yanesca yanesca moved this to 3.6.3 / 2.28.10 (final) release in Past EPICs Apr 8, 2025
@yanesca yanesca removed this from Mbed TLS Epics Apr 8, 2025
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 component-psa PSA keystore/dispatch layer (storage, drivers, …) priority-medium Medium priority - this can be reviewed as time permits size-xs Estimated task size: extra small (a few hours at most)
Projects
Status: 3.6.3 / 2.28.10 (final) release
Status: In Development
Development

Successfully merging this pull request may close these issues.

4 participants