Skip to content
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

Some MAX_SIZE macros are too small when PSA ECC is accelerated #7103

Merged
merged 18 commits into from
Apr 3, 2023

Conversation

valeriosetti
Copy link
Contributor

@valeriosetti valeriosetti commented Feb 15, 2023

Description

The goal of this PR is to fix PSA_VENDOR_ECC_MAX_CURVE_BITS when some of the curves are accelerated.
Resolve #6622

This PR is a draft because even though ECDH is accelerated there are tests failing due to key derivation. This issue is known and should be addressed in a different PR.

This PR depends on #7321 (explanation here)

Gatekeeper checklist

  • changelog required as this is a bug fix, provided
  • backport not required - the bug is only visible when using new features from 3.x (driver-only ECC)
  • tests provided

@valeriosetti valeriosetti requested a review from mpg February 15, 2023 10:39
@valeriosetti valeriosetti self-assigned this Feb 15, 2023
@valeriosetti valeriosetti added bug component-crypto Crypto primitives and low-level interfaces needs-ci Needs to pass CI tests needs-preceding-pr Requires another PR to be merged first size-s Estimated task size: small (~2d) labels Feb 15, 2023
@ronald-cron-arm ronald-cron-arm self-requested a review February 15, 2023 13:06
@valeriosetti valeriosetti marked this pull request as ready for review March 21, 2023 11:07
@valeriosetti valeriosetti removed the needs-preceding-pr Requires another PR to be merged first label Mar 21, 2023
@valeriosetti
Copy link
Contributor Author

valeriosetti commented Mar 21, 2023

Notes for reviewers:

  1. I'm finally changing this PR from draft to normal thanks to the latest changes introduced in psa_crypto: Fix psa_key_derivation_output_key ECC without builtin keys #7192
  2. I had to set legacy MBEDTLS_ECP_DP_xxx requirements on some key derivations (see this commit) because:
  • driver's dispatching is not implemented yet
  • when deriving weierstrass key it goes through ECP module, which itself uses MBEDTLS_ECP_DP_xxx definitions, which are however excluded from the library part.

BTW the double dependency PSA_WANT_xxx + MBEDTLS_ECP_DP_xxx seems reasonable to me until key derivation does not implement driver's dispatching. @mpg Wdyt?

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.

Just a first pass.

include/psa/crypto_sizes.h Outdated Show resolved Hide resolved
tests/scripts/all.sh Outdated Show resolved Hide resolved
tests/suites/test_suite_psa_crypto.data Outdated Show resolved Hide resolved
tests/scripts/all.sh Outdated Show resolved Hide resolved
tests/scripts/all.sh Outdated Show resolved Hide resolved
tests/scripts/all.sh Outdated Show resolved Hide resolved
@valeriosetti valeriosetti added needs-preceding-pr Requires another PR to be merged first and removed needs-ci Needs to pass CI tests labels Mar 24, 2023
@valeriosetti
Copy link
Contributor Author

@mpg I just set the need-preceding-pr label on this PR because I forgot to mention that it depends on #7321 for a fix that will be introduced by the top level ECC epic; #7321 in particular.

tests/scripts/all.sh Outdated Show resolved Hide resolved
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.

Looking pretty good, and thanks for adding the 2nd component! Other than the EC J-PAKE depenency, the only things I found are minor nits.

include/mbedtls/check_config.h Outdated Show resolved Hide resolved
tests/scripts/all.sh Outdated Show resolved Hide resolved
tests/scripts/all.sh Outdated Show resolved Hide resolved
tests/scripts/all.sh Outdated Show resolved Hide resolved
tests/scripts/all.sh Outdated Show resolved Hide resolved
tests/scripts/all.sh Show resolved Hide resolved
@mpg
Copy link
Contributor

mpg commented Mar 27, 2023

backport -> question for gatekeepers: since this is a bugfix, should this be backported?

I don't think so. I agree it's technically a bug, but one that only shows in configurations that we don't really support in 2.28, considering that even the possibility of building with driver-only ECDSA or ECDH is new in development. Other reviewers please shout if you disagree.

*tests -> question for gatekeepers: should I test it with outcome-analysis.sh to be sure I did not change the number of tests executed?

I don't think that's needed here, as we didn't massively change existing dependency declarations.

Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Choose a reason for hiding this comment

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

I only have one minor comment otherwise this looks good to me. Thanks for the two well-crafted non-regression all.sh components. I have checked that when reverting the changes in crypto_size.h the PSA crypto unit tests actually fail in the two components. Otherwise I would say this deserves a change log as it's a bug fix.


# Ensure also RSA_C is disabled so that the size of the public/private
# keys cannot be taken from there
scripts/config.py unset MBEDTLS_RSA_C
Copy link
Contributor

Choose a reason for hiding this comment

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

As the PSA configuration is enabled, some PSA_WANT_ALG_RSA_xxx are defined without acceleration this does not have any impact on the build I think.

All RSA associated algs are now forcedly disabled both on library
and driver sides.
Some PSA driver tests required to be fixed because they were just
requiring for not having the built-in version, but they didn't check
if the driver one was present (kind of assuming that RSA was always
supported on the driver side).

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
mpg
mpg previously approved these changes Apr 3, 2023
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

@mpg
Copy link
Contributor

mpg commented Apr 3, 2023

Despite this being a bug, and sort-of present in 2.28 already, I'm inclined not to backport, because the bug is only visible when using driver-only ECC, which only became possible in 3.4/development. (Practically, in 2.28 we'd have no way to test the fix like we did here.) @valeriosetti @ronald-cron-arm please shout if you disagree.

@valeriosetti
Copy link
Contributor Author

I'm inclined not to backport, because the bug is only visible when using driver-only ECC, which only became possible in 3.4/development

I agree with you. Do I need to write this somewhere (i.e. the fact that we are intentionally not backporting this fix) for future reference?

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

mpg commented Apr 3, 2023

Do I need to write this somewhere (i.e. the fact that we are intentionally not backporting this fix) for future reference?

Yes, we want it written in the "gatekeeper checklist" part of the PR description, but no, you don't need to, I had already written it :) Just wanted to make sure you two had an opportunity to tell if you disagreed, because it's easy to not notice I had edited the description.

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

Copy link
Contributor

@ronald-cron-arm ronald-cron-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, thanks for the changes.

@ronald-cron-arm
Copy link
Contributor

Despite this being a bug, and sort-of present in 2.28 already, I'm inclined not to backport, because the bug is only visible when using driver-only ECC, which only became possible in 3.4/development. (Practically, in 2.28 we'd have no way to test the fix like we did here.) @valeriosetti @ronald-cron-arm please shout if you disagree.

I am fine with that.

@mpg mpg added the approved Design and code approved - may be waiting for CI or backports label Apr 3, 2023
@mpg mpg merged commit 86d5d4b into Mbed-TLS:development Apr 3, 2023
@valeriosetti valeriosetti mentioned this pull request Apr 17, 2023
3 tasks
mpg added a commit to valeriosetti/mbedtls that referenced this pull request Sep 20, 2023
Those components were introduced in Mbed-TLS#7103, resolving Mbed-TLS#6622: Some PSA
ECC size macros are too small when the largest accelerated curve is
larger than the largest built-in curve.

At that point, it was not possible yet to omit all built-in curves,
so we made these components that had only one (small) curve built-in and
all the others accelerated.

Now that it's possible to disable all ECC built-ins, and we have tests
doing that, we don't need that kind of fiddling any more.

Note: these component disabled RSA in order to make sure max key size
macros were not taken from RSA. We have test components with all of ECC
accelerated and RSA disabled
(component_test_psa_crypto_config_accel_ecc_no_bignum and
component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum), making the
"all curves except one" components really redundant.

Note: removing them was one of the items in Mbed-TLS#7757.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
mpg added a commit to valeriosetti/mbedtls that referenced this pull request Sep 21, 2023
Those components were introduced in Mbed-TLS#7103, resolving Mbed-TLS#6622: Some PSA
ECC size macros are too small when the largest accelerated curve is
larger than the largest built-in curve.

At that point, it was not possible yet to omit all built-in curves,
so we made these components that had only one (small) curve built-in and
all the others accelerated.

Now that it's possible to disable all ECC built-ins, and we have tests
doing that, we don't need that kind of fiddling any more.

Note: these component disabled RSA in order to make sure max key size
macros were not taken from RSA. We have test components with all of ECC
accelerated and RSA disabled
(component_test_psa_crypto_config_accel_ecc_no_bignum and
component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum), making the
"all curves except one" components really redundant.

Note: removing them was one of the items in Mbed-TLS#7757.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
mpg added a commit to valeriosetti/mbedtls that referenced this pull request Sep 24, 2023
Those components were introduced in Mbed-TLS#7103, resolving Mbed-TLS#6622: Some PSA
ECC size macros are too small when the largest accelerated curve is
larger than the largest built-in curve.

At that point, it was not possible yet to omit all built-in curves,
so we made these components that had only one (small) curve built-in and
all the others accelerated.

Now that it's possible to disable all ECC built-ins, and we have tests
doing that, we don't need that kind of fiddling any more.

Note: these component disabled RSA in order to make sure max key size
macros were not taken from RSA. We have test components with all of ECC
accelerated and RSA disabled
(component_test_psa_crypto_config_accel_ecc_no_bignum and
component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum), making the
"all curves except one" components really redundant.

Note: removing them was one of the items in Mbed-TLS#7757.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
mpg added a commit to valeriosetti/mbedtls that referenced this pull request Sep 25, 2023
Those components were introduced in Mbed-TLS#7103, resolving Mbed-TLS#6622: Some PSA
ECC size macros are too small when the largest accelerated curve is
larger than the largest built-in curve.

At that point, it was not possible yet to omit all built-in curves,
so we made these components that had only one (small) curve built-in and
all the others accelerated.

Now that it's possible to disable all ECC built-ins, and we have tests
doing that, we don't need that kind of fiddling any more.

Note: these component disabled RSA in order to make sure max key size
macros were not taken from RSA. We have test components with all of ECC
accelerated and RSA disabled
(component_test_psa_crypto_config_accel_ecc_no_bignum and
component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum), making the
"all curves except one" components really redundant.

Note: removing them was one of the items in Mbed-TLS#7757.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
@valeriosetti valeriosetti deleted the issue6622 branch December 6, 2024 05:41
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 bug component-crypto Crypto primitives and low-level interfaces priority-high High priority - will be reviewed soon size-s Estimated task size: small (~2d)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some MAX_SIZE macros are too small when PSA ECC is accelerated
4 participants