-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
ECP keypair utility functions #7815
ECP keypair utility functions #7815
Conversation
c7d878d
to
895fbf6
Compare
This increases code size by 200 bytes when compiled for TF-M (their config, P-256 only, no
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a design review for now. I'm mostly happy except for export_coordinates()
where I disagree with the current API and am not convinced we really need it at all (but not opposed to adding it either).
Add a simple function to get the group id from a key object. This information is available via mbedtls_ecp_export, but that function consumes a lot of memory, which is a waste if all you need is to identify the curve. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Sometimes you don't need to have all the parts of a key pair object. Relax the behavior of mbedtls_ecp_keypair so that you can extract just the parts that you need. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
13ef596
to
28e9d86
Compare
I've pushed a new history that never creates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty good, just a few minor things and a couple of questions.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, apart from the superfluous BIGNUM_C
guards that I'd like removed.
I'm removing "needs-design-approval" as I think we know have an agreement on the design. |
All of ECP requires the bignum module and there is no plan to change that, so guarding a few bits of code is just noise. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall.
Two notes:
-
I assume that the setter for public key
mbedtls_ecp_read_public_key
is intentionally missing?If a user needs to importa public key they should import the private one using
mbedtls_ecp_read_key ()
and then calculate the public usingmbedtls_ecp_keypair_calc_public()
? -
The
show_ecp_key(const mbedtls_ecp_keypair *ecp, int has_private)
method could be either a helper function for programs or even an API call? Given the complexity to produce a readable printout, we should at least point the users to how to do it.
The latter is not a strong ask, and should not block this PR.
I'm not sure what that would be. How would it differ from
It could be, but those programs are currently self-contained. They're sample programs, so there's a strong argument that people should be able to just take the one
Printing out keys in a readable format is rarely done apart from demos. So it doesn't belong in the API, and I don't think we need to call it out in documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
b1f96c0
Add utility functions to the ECP module to query and construct key pairs and points. This replaces the direct access to
mbedtls_ecp_keypair
andmbedtls_ecp_point
fields that was possible in Mbed TLS 2.x. Fixes #5441, fixes #8367, fixes #8652.Update the sample programs. They now no longer do any direct access to private fields of
mbedtls_ecp_keypair
ormbedtls_ecp_point
. Fixes #5017. Note that any unrelated improvement of sample programs or their testing is out of scope here. I used the following to test them:programs/pkey/ecdsa
smoke.sh secp256r1 && smoke.sh x25519
using smoke.sh.txtFollow-up: use the new functions to simplify the PSA transition guide.
PR checklist
Please tick as appropriate and edit the reasons (e.g.: "backport: not needed because this is a new feature")