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 PSA interruptible key generation setup & abort APIs #9639

Merged

Conversation

waleed-elmelegy-arm
Copy link
Contributor

@waleed-elmelegy-arm waleed-elmelegy-arm commented Sep 25, 2024

Description

Partially fixes #9106
fixes #9642
Add PSA interruptible key generation setup & abort APIs

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.

  • changelog not required because:
  • development PR not required because:
  • framework PR not required
  • 3.6 PR not required because: New feature
  • 2.28 PR pnot required because: New feature
  • tests provided

Notes for the submitter

Please refer to the contributing guidelines, especially the
checklist for PR contributors.

Help make review efficient:

  • Multiple simple commits
    • please structure your PR into a series of small commits, each of which does one thing
  • Avoid force-push
    • please do not force-push to update your PR - just add new commit(s)
  • See our Guidelines for Contributors for more details about the review process.

@waleed-elmelegy-arm waleed-elmelegy-arm added DO-NOT-MERGE needs-ci Needs to pass CI tests component-psa PSA keystore/dispatch layer (storage, drivers, …) size-s Estimated task size: small (~2d) labels Sep 25, 2024
@waleed-elmelegy-arm waleed-elmelegy-arm force-pushed the add-iop-key-gen-setup branch 6 times, most recently from 989ca52 to 6ba71ec Compare September 27, 2024 14:12
@waleed-elmelegy-arm waleed-elmelegy-arm 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 DO-NOT-MERGE needs-ci Needs to pass CI tests labels Sep 27, 2024
@waleed-elmelegy-arm
Copy link
Contributor Author

CI failure not related

Copy link
Member

@paul-elliott-arm paul-elliott-arm left a comment

Choose a reason for hiding this comment

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

Seems generally ok, just would like an answer to the copying key attributes question.

goto exit;
}


Copy link
Member

Choose a reason for hiding this comment

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

Nit: Extraneous line

goto exit;
}

operation->attributes = *attributes;
Copy link
Member

Choose a reason for hiding this comment

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

Question: is this really the best way to copy attributes? I admittedly can't find any other operations copying attributes, but this feels dangerous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no pointers in the struct currently, there might be an issue if someone adds a pointer in the future and it soesn't seem very propable to add a pointer to attributes, if we decide that it is still dangerous what I can do is add copy_attributes() function that still does a shallow copy and later will do a deep copy if needed.

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!

There used to be a pointer in the attributes (domain parameters). We removed it in 3.6.0. I don't recall that we ever copied the data at that pointer: either we never copied attributes anywhere (most likely — we used to copy a sub-structure that didn't have pointers), or we only copied attributes at a point where we knew there were no domain parameters, or we had a memory management bug.

At this point I can't think of anything in the proposed evolution of the PSA API that would make us add a pointer back. But just in case it would be good to write and use a copy function, that can be just a static inline that does an assignment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually there is one place where we are copying the attribute structure: in psa_start_key_creation. We used to copy a sub-structure (attributes.core) that didn't have any embedded pointer, and we flattened the structure when we removed the pointer.

So at this point it's a preexisting issue. (Of my doing, incidentally — I did the patch that flattened the structure.) It would be good to use a copy function for future-proofing. But we would also need to ensure that we're calling psa_key_attributes_reset on all paths where the attributes become dead. We used to do that, but one of the advantages of simplifying the attribute structure was that we wouldn't have to do it any longer.

So at this point, I lean weakly towards not bothering. If we ever add a pointer into the attribute structure, we'll have to review the code carefully to ensure that all places that might possibly copy or free an attribute structure are covered by the copy/free function, anyway. We won't gain much just because there are places where the copy/free functions are used, since there'll be no way to know that it's missing in other places.

@gilles-peskine-arm gilles-peskine-arm added the priority-high High priority - will be reviewed soon label Oct 28, 2024
Copy link
Contributor

@yanesca yanesca left a comment

Choose a reason for hiding this comment

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

I have a couple of questions and suggestions which I left inline.

One generic remark: it is easier to review a PR when it is divided into smaller commits. This one for example could have been 3 commits. (I am not asking you to split it up, this is just a remark/ask for future PRs which haven't been raised yet.)

tf-psa-crypto/core/psa_crypto.c Outdated Show resolved Hide resolved
tf-psa-crypto/core/psa_crypto.c Show resolved Hide resolved
tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.c Outdated Show resolved Hide resolved
tf-psa-crypto/tests/suites/test_suite_psa_crypto.function Outdated Show resolved Hide resolved
tf-psa-crypto/include/psa/crypto_struct.h Show resolved Hide resolved
tf-psa-crypto/core/psa_crypto_core.h Outdated Show resolved Hide resolved
@yanesca yanesca added needs-work 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 Oct 29, 2024
@waleed-elmelegy-arm waleed-elmelegy-arm added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Oct 31, 2024
yanesca
yanesca previously approved these changes Nov 1, 2024
Copy link
Contributor

@yanesca yanesca 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 to me.

If I am not missing something obvious here, it would be nice to add that, but I won't hold off the review for that.

@yanesca
Copy link
Contributor

yanesca commented Nov 1, 2024

(API break CI failure is necessary and acceptable.)

@yanesca yanesca added needs-work needs-ci Needs to pass CI tests and removed needs-review Every commit must be reviewed by at least two team members, labels Nov 4, 2024
@waleed-elmelegy-arm
Copy link
Contributor Author

Had to force push because the revert commit lacked signing off

@yanesca
Copy link
Contributor

yanesca commented Nov 5, 2024

Error: Test case not executed: test_suite_psa_crypto;PSA generate key: ECC, SECP224K1, good
Error: Test case not executed: test_suite_psa_crypto;PSA generate key: ECC, brainpool160r1, good

Both of these curves are scheduled to be removed in 4.0, I think it is acceptable to remove these two test cases to have a clean CI.

Remove generate key brainpool160r1 & SECP224K1 test cases
as they are scheduled to be removed in 4.0 .

Signed-off-by: Waleed Elmelegy <[email protected]>
Copy link
Contributor

@yanesca yanesca left a comment

Choose a reason for hiding this comment

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

LGTM

@yanesca yanesca added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Nov 5, 2024
Copy link
Member

@paul-elliott-arm paul-elliott-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

@paul-elliott-arm paul-elliott-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, needs-ci Needs to pass CI tests labels Nov 5, 2024
@yanesca yanesca added this pull request to the merge queue Nov 6, 2024
@yanesca
Copy link
Contributor

yanesca commented Nov 6, 2024

(API break CI failure is necessary and acceptable.)

Merged via the queue into Mbed-TLS:development with commit 502ff7b Nov 6, 2024
4 of 6 checks passed
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-high High priority - will be reviewed soon size-s Estimated task size: small (~2d)
Development

Successfully merging this pull request may close these issues.

Implement interruptible ECC Key Generation (Setup / Abort) Implement Interruptible ECC Keypair Generation
4 participants