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

Add test for PK parsing of keys using compressed points #6937

Merged
merged 6 commits into from
Feb 14, 2023

Conversation

valeriosetti
Copy link
Contributor

@valeriosetti valeriosetti commented Jan 16, 2023

Description

Following merging of PR #6282, PK parse module should now be able to parse EC compressed points. This PR adds some test for that purpose.
Resolves #6886

Gatekeeper checklist

  • changelog not required - tests only
  • backport not required - tests for a feature that's only in development
  • tests provided - the point of this PR

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
@valeriosetti valeriosetti requested a review from mpg January 16, 2023 15:31
@valeriosetti valeriosetti added enhancement 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) labels Jan 16, 2023
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
@valeriosetti valeriosetti self-assigned this Jan 16, 2023
tests/data_files/Makefile Outdated Show resolved Hide resolved
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
@valeriosetti valeriosetti removed the needs-ci Needs to pass CI tests label Jan 17, 2023
@valeriosetti valeriosetti added 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 and removed needs-reviewer This PR needs someone to pick it up for review labels Jan 18, 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.

What's there looks good to me, but I have a question about what isn't there: why no ec_224_pub.comp.pem (and associated Parse Public EC Key #3a test case)?

@valeriosetti
Copy link
Contributor Author

What's there looks good to me, but I have a question about what isn't there: why no ec_224_pub.comp.pem (and associated Parse Public EC Key #3a test case)?

Because I'm not sure those curves are supported:
https://github.com/Mbed-TLS/mbedtls/blob/development/ChangeLog.d/mbedtls_ecp_point_read_binary-compressed-fmt.txt

Indeed if I try to add it then mbedtls_ecp_sw_derive_y return at line 1280

@mpg
Copy link
Contributor

mpg commented Jan 25, 2023

Ah good point :) Still, it might be better to be explicit about it and add a negative test case with a comment then. Otherwise it's hard to know if the missing case is intentional or an oversight when looking at it in the future.

@valeriosetti
Copy link
Contributor Author

Ah good point :) Still, it might be better to be explicit about it and add a negative test case with a comment then. Otherwise it's hard to know if the missing case is intentional or an oversight when looking at it in the future.

I thought about adding a comment, but you're right: a negative test is probably better here in order to enforce/verify the check

The test is expected to fail, so we verify that this is really
not suppported

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
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.

Looks good except one point where I think a cleaner solution is available.

tests/suites/test_suite_pkparse.function Outdated Show resolved Hide resolved
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
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 one bit of documentation to improve.

include/mbedtls/ecp.h Outdated Show resolved Hide resolved
@gilles-peskine-arm
Copy link
Contributor

CI is still going, but already unhappy

mpg
mpg previously approved these changes Feb 7, 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 Feb 8, 2023

I created #7060 to track the parts that we decided to consider out of scope here. @gilles-peskine-arm perhaps that should be added to some tech debt list?

Also, CI is now green so this is ready for re-review.

@mpg
Copy link
Contributor

mpg commented Feb 8, 2023

Note to self & other gatekeepers: I suspect this might conflict (as in, not seen by git but only by the CI) with #6970 which was just merged, so we want to wait for the nightly re-run of pr-merge before merging this. Temporarily labeling "do not merge" "needs-ci" as a reminder.

@mpg mpg added DO-NOT-MERGE needs-ci Needs to pass CI tests needs-review Every commit must be reviewed by at least two team members, and removed DO-NOT-MERGE needs-ci Needs to pass CI tests labels Feb 8, 2023
@mpg
Copy link
Contributor

mpg commented Feb 10, 2023

No conflict with #6970. Now that I see the results, I should have known: 6970 is about building without ECDSA, and we'll run into problem with compressed points only when building without ECP. Anyway, better safe than sorry.

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.

Just one problem in the documentation.

* Point formats, from RFC 4492's enum ECPointFormat
/**
* The uncompressed point format for Short Weierstrass curves
* (MBEDTLS_ECP_DP_SECP* and MBEDTLS_ECP_DP_BP*). //no-check-names
Copy link
Contributor

Choose a reason for hiding this comment

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

This includes “//no-check-names” in the documentation. That's not good.

Our normal convention is to write XXX or xxx for a wildcard, not *. And check_names.py has an exception for names containing these.

Suggested change
* (MBEDTLS_ECP_DP_SECP* and MBEDTLS_ECP_DP_BP*). //no-check-names
* (MBEDTLS_ECP_DP_SECP_XXX and MBEDTLS_ECP_DP_BP_XXX).

and likewise below.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
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

* \warning While this format is supported for all concerned curves for
* writing, when it comes to parsing, it is not supported for all
* curves. Specifically, parsing compressed points on
* MBEDTLS_ECP_DP_SECP224R1 and MBEDTLS_ECP_DP_SECP224K1 is not
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocker:

Suggested change
* MBEDTLS_ECP_DP_SECP224R1 and MBEDTLS_ECP_DP_SECP224K1 is not
* #MBEDTLS_ECP_DP_SECP224R1 and #MBEDTLS_ECP_DP_SECP224K1 is not

(Doxygen automatically makes links for foo(), but not for a macro name.)

@gilles-peskine-arm gilles-peskine-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 Feb 14, 2023
@gilles-peskine-arm gilles-peskine-arm merged commit c5e2a4f into Mbed-TLS:development Feb 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 component-crypto Crypto primitives and low-level interfaces enhancement size-s Estimated task size: small (~2d)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add test for PK parsing of keys using compressed points
4 participants