Fix explicit Elliptic Curve parsing#705
Fix explicit Elliptic Curve parsing#705Marandil wants to merge 6 commits intoMbed-TLS:developmentfrom
Conversation
|
Thanks for the patch! Please note that due to review bandwidth limitations, it may take a while before we can review it. Before that, please do the following:
|
1e6ba2d to
843dcb7
Compare
For reference, as just discussed elsewhere, I don't think it's a new feature: we have an option that's supposed to enable support for that except we only have tests for parsing private keys encoded this way, so quite unsurprisingly we have bugs in the part that's not tested: parsing public keys encoded this way. |
By the way, do you understand why these problems only manifest when parsing public keys, and are somehow avoided when parsing private keys? I haven't had the time to investigate yet, but that's a bit surprising to me. |
mpg
left a comment
There was a problem hiding this comment.
I have not done a full review, but the general shape of the PR is looking good.
I'm interested in reviewing this fully, but unfortunately it comes at a time where our load is unusually high. I want to review this before the end of the month, but I'm afraid I can't promise anything better at this point. (I realise this is not ideal as you are very responsive, but I think the second best thing we can do, other than reviewing immediately, is setting realistic expectations about timelines.)
|
The CI has run and a few jobs are failing. Some of them are in driver tests, which are a bit weird, let us know if you need help figuring them out. Generally, to reporoduce a job, run |
|
Some additional "fun" for reproducing locally: if the component that fails lives in the mbedtls repo (we haven't finished migrating components to the right repo yet, sorry), you'll need to check out mbedtls, locally checkout your your branch into the tf-psa-crypto submodule, and then you can run the failing component. Or, since you have already prepared a 3.6 backport, I think reproducing in 3.6 will just be easier. |
I checked the failing pipelines, I think it has something to do with missing flags on tests as the following failed:
I'm assuming these tests should not be ran in these configs. I'll look into it. |
|
Ah, you want to mark the new test cases as depending on |
bcdc256 to
543ca29
Compare
I also found an answer to this one. It's actually because the test data for private key actually does not use the canonical representation and instead uses a highly compressed variant. This is the extracted SpecifiedECDomain from the test file: While the same file converted to PEM using To answer specifically "why does this work" -- the first file contains a compressed EC point that already had a special case built-in and was not the case of |
|
Ah, very nice, thanks! Ok, so unlike what we (or at least I) originally thought, it has nothing to do with public vs private. As mentioned in the PR description, there are two bugs here:
Both bugs affect both Taking a quick look at the companion framework PR, I can see that you generated files for all curves, so that's good, thanks! I wonder if we can easily control whether G is encoded in compressed form or not. It would be great to be able to test both variants for each curve if we can. |
|
Out of curiosity, I checked if we had any record of how the existing test file |
|
Hey, just to clarify: is there any more work that must be done or my side, or are we just waiting for review capacity now? |
|
Hi! I was going to say we're just waiting for review capacity now, but I see there are conflicts this morning:
We usually resolve conflicts by rebasing when doable. If you ca do that in the coming days, then I'll kick the CI again (it has to be started manually on external contributions), then we'll be all set for when there's review capacity. |
FWIW, I just rebased one of my own PRs due to the same conflicts (file reorg) and git resolved it automatically, so hopefully it will be the same for you. |
Signed-off-by: Marcin Słowik <marcin@edgecorp.io>
Signed-off-by: Marcin Słowik <marcin@edgecorp.io>
Signed-off-by: Marcin Słowik <marcin@edgecorp.io>
…curve) pkparse tests. Signed-off-by: Marcin Słowik <marcin@edgecorp.io>
Signed-off-by: Marcin Słowik <marcin@edgecorp.io>
Signed-off-by: Marcin Słowik <marcin@edgecorp.io>
746a5be to
4c4fe7b
Compare
|
Thanks, rebase indeed worked, although framework updates are a bit of a headache. Could we maybe get Mbed-TLS/mbedtls-framework#285 going first s.t. it's not a moving target? |
|
Yes, that's the plan! Thanks for the rebase. We're experiencing CI issues at the moment that should be fixed shortly, I'll kick the CI on this PR once it's functional again. |
|
The CI is almost happy but has the following feedback:
Specifically, our code style checker suggests the following patch: --- extras/pkparse.c 2026-03-13 10:25:28.000000000 +0000
+++ extras/pkparse.c.uncrustify 2026-03-13 11:11:58.965754598 +0000
@@ -191,11 +191,11 @@
* see mbedtls_ecp_group_a_is_minus_3
*/
mbedtls_mpi_init(&tmp);
- if((ret = mbedtls_mpi_sub_int(&tmp, &grp->P, 3)) != 0) {
+ if ((ret = mbedtls_mpi_sub_int(&tmp, &grp->P, 3)) != 0) {
mbedtls_mpi_free(&tmp);
return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
}
- if(mbedtls_mpi_cmp_mpi(&tmp, &grp->A) == 0) {
+ if (mbedtls_mpi_cmp_mpi(&tmp, &grp->A) == 0) {You can either address this now, or just wait for review feedback and address both at the same time, whatever you prefer. |
Description
Fixes Mbed-TLS/mbedtls#4314.
pk_group_from_specifiedself-referencing group generator G while loading G.pk_group_from_specifiednot accounting for the a = p-3 internal representation.mbedtls_pk_parse_public_keyfailing to load keys with explicit curve parameters.PR checklist
Please remove the segment/s on either side of the | symbol as appropriate, and add any relevant link/s to the end of the line.
If the provided content is part of the present PR remove the # symbol.
Notes for the submitter
Please refer to the contributing guidelines, especially the
checklist for PR contributors.
Help make review efficient: