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

Define (private) "light" subset of ECP #7410

Merged
merged 12 commits into from
Apr 14, 2023
Merged

Conversation

valeriosetti
Copy link
Contributor

@valeriosetti valeriosetti commented Apr 5, 2023

The goal of this PR is to create a new symbol named MBEDTLS_ECP_LIGHT which can be used in conjunction with MBEDTLS_ECP_C to exclude some code from the ecp module at build time.
It basically works like this:

  • MBEDTLS_ECP_LIGHT only --> ecp module is built without its internal arithmetic functions
  • MBEDTLS_ECP_LIGHT + MBEDTLS_ECP_C --> ecp module is built entirely as it has been until now

This PR mimics the idea recently introduced by the MBEDTLS_MD_LIGHT symbol.

Depends on #7393
Resolves #7390

Gatekeeper checklist

@valeriosetti valeriosetti self-assigned this Apr 5, 2023
@valeriosetti valeriosetti requested a review from mpg April 5, 2023 16:34
@valeriosetti valeriosetti added enhancement 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-s Estimated task size: small (~2d) priority-high High priority - will be reviewed soon labels Apr 5, 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.

Looking pretty good to me, just one nit about a comment and a question about dependencies & parity.

include/mbedtls/build_info.h Outdated Show resolved Hide resolved
library/pk_wrap.c Outdated Show resolved Hide resolved
tests/suites/test_suite_psa_crypto.data Outdated Show resolved Hide resolved
@mpg mpg mentioned this pull request Apr 7, 2023
7 tasks
@valeriosetti
Copy link
Contributor Author

valeriosetti commented Apr 7, 2023

Adding the need-work label because as @mpg correctly pointed out analyze_outcomes.py script is failing
Solved!
But I noticed that the list of conflicts in the merge is increased. I will rebase and fix them as soon as preceding PRs are merged.

@mpg
Copy link
Contributor

mpg commented Apr 11, 2023

changelog question: even thought the new symbol is internal and it's not present in mbedtls_config.h, the final user can still take advantage of it when compiling from the command line, so in my opinion this should be mentioned with a Changelog. Wdyt?

Related: #6839 (comment) - initially I was thinking fully internal as it would be a temporary thing until we complete the 2c EPIC, but now I see reasons for keeping it beyond that.

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>
Changes in test_suite_psa_crypto are to enforce the dependency
on ECP_C which is mandatory for some key's derivation.

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

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>
Only some test cases are skipped for which ECP_C is mandatory,
but the other ones are included.

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

mpg commented Apr 11, 2023

We should just mention that "part of the ECP module might be automatically re-enabled when some features are required by the user" and then list these cases.

But that's not really the case now, is it? The only case where ECP_LIGHT is auto-enabled in build_info.h right now is when ECP_C is enabled. If you want ECP_LIGHT without the full ECP_C right now the only way is -DMBEDTLS_ECP_LIGHT on the compiler's command line.

For MBEDTLS_PK_PARSE_EC_EXTENDED we could have it auto-enable ECP_LIGHT. But for compressed points and ECC key derivation, there is no feature macro we can use. So I think it's easier to go the other way round: let the user explicitly enable ECP_LIGHT is they want support for reading compressed points and/or deriving ECC keys on Short Weierstrass curves.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
@valeriosetti valeriosetti force-pushed the issue7390 branch 2 times, most recently from 32c56e5 to 4e1d32e Compare April 12, 2023 07:58
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.

I'm afraid there's some confusion about limitations and what the current step is. I also have a number of suggestions about wording.

include/mbedtls/build_info.h Outdated Show resolved Hide resolved
ChangeLog.d/ecp-light.txt Outdated Show resolved Hide resolved
ChangeLog.d/ecp-light.txt Outdated Show resolved Hide resolved
ChangeLog.d/ecp-light.txt Outdated Show resolved Hide resolved
include/mbedtls/mbedtls_config.h Outdated Show resolved Hide resolved
include/mbedtls/mbedtls_config.h Outdated Show resolved Hide resolved
include/mbedtls/mbedtls_config.h Outdated Show resolved Hide resolved
include/mbedtls/mbedtls_config.h Outdated Show resolved Hide resolved
include/mbedtls/mbedtls_config.h Outdated Show resolved Hide resolved
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.

LGTM, thanks!

@AndrzejKurek AndrzejKurek self-requested a review April 14, 2023 08:26
Copy link
Contributor

@AndrzejKurek AndrzejKurek left a comment

Choose a reason for hiding this comment

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

Some questions left.

#if defined(MBEDTLS_ECP_C)
static unsigned long add_count, dbl_count;
#endif /* MBEDTLS_ECP_C */
static unsigned long mul_count;
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

/* MBEDTLS_ECP_LIGHT */

make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
loc_symbols="-DPSA_CRYPTO_DRIVER_TEST \
-DMBEDTLS_TEST_LIBTESTDRIVER1 \
-DMBEDTLS_ECP_LIGHT"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this passed as a CFLAGS option, not in the config file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because we want to keep it private (mostly because it doesn't have well-defined semantics), so it can't appear in the config file.

Passing it in the CFLAGS is a temporary situation, though: in the future it will be auto-enabled based on options that need it, but we're going step by step.

Copy link
Contributor

Choose a reason for hiding this comment

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

See #7442.

@@ -211,6 +210,44 @@ def do_analyze_driver_vs_reference(outcome_file, args):
'test_suite_random': [
'PSA classic wrapper: ECDSA signature (SECP256R1)',
],
# In the accelerated test ECP_C is not set (only ECP_LIGHT is)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we also only enable ECP_LIGHT in component_test_psa_crypto_config_reference_all_ec_algs_use_psa instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

For the same reason we're not disabling ECDSA_C in the reference component: we want the feature set of ECC-using modules (PK, X.509, TLS) with ECP_LIGHT && !ECP_C to be as close as possible to the feature set with ECP_C. That's why we're keeping ECP_C enabled in the component, and have an ignore list for test_suite_ecp. This is similar to how we have ECDSA_C in the reference but ignore the whole test_suite_ecdsa - except here we don't ignore the whole test_suite_ecp, just part of it.

@@ -5360,7 +5360,6 @@ run_test "Authentication: server goodcert, client required, no trusted CA" \
# occasion (to be fixed). If that bug's fixed, the test needs to be altered to use a
# different means to have the server ignoring the client's supported curve list.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we require ECP_LIGHT here and below instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question. I don't think we should require ECP_LIGHT here: we already auto-detect based on using server5 that ECDSA support is required. Now perhaps we need to reflect somewhere that PK only has support for ECDSA when ECP_LIGHT is present. Let me check.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I checked and I think there are multiple sides to this:

  1. Definition of MBEDTLS_PK_CAN_ECDSA_xxx macros in pk.h.
  2. Definition of MBEDTLS_PK_HAVE_ECDSA helper macro in check_config.h.
  3. Definition of requires_pk_alg() in ssl-opt.sh.

None of them are fully correct right now - that is, neither in this PR nor in development. Before this PR, in the USE_PSA case, we should require ECP_C in addition to PSA_WANT_ALG_ECDSA because without it, PK doesn't support ECC keys; after this PR it should be ECP_LIGHT.

Though since we don't want to make ECP_LIGHT public, again what we should do it not require it, but instead auto-enable it when needed, so for example PK_C && USE_PSA && PSA_WANT_ALG_ECDSA would auto-enable ECP_LIGHT and then I think all three of the above definitions would become correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

See #7442.

Copy link
Contributor

@AndrzejKurek AndrzejKurek left a comment

Choose a reason for hiding this comment

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

Approved based on follow-up work.

@AndrzejKurek AndrzejKurek 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, needs-reviewer This PR needs someone to pick it up for review labels Apr 14, 2023
@mpg mpg mentioned this pull request Apr 14, 2023
3 tasks
@mpg mpg merged commit 6942cc3 into Mbed-TLS:development Apr 14, 2023
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 enhancement 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.

Define (private) "light" subset of ECP
4 participants