-
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
Implement psa_sign_message and psa_verify_message #4357
Implement psa_sign_message and psa_verify_message #4357
Conversation
e80a36e
to
2198a7e
Compare
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.
I made a first review pass, just for design. I did not review the documentation, the code or the test data in detail. I'm happy with the design. The test coverage looks ok (but I may ask for a few specific tests once I've done a detailed review).
Some things are missing. They can be done either in this PR or in a follow-up.
- Drivers can have a sign/verify-message entry point. So there needs to be a
psa_driver_wrapper_sign_message
and apsa_driver_wrapper_sign_hash
. If there is no all-in-one method for the given algorithm, then fall back to the code you've already written that hashes then signs. It may be better to first merge this PR, then implement the new driver dispatch at once for both sign-hash and sign-message — what do you think @ronald-cron-arm? -
psa_exercise_key
should have cases for keys that have theSIGN_MESSAGE
orVERIFY_MESSAGE
usage.
There's plenty of examples for functionality that has been converted to driver dispatch already. Conversion for this PR should be the same as following the footpath already created by the dispatch of |
2198a7e
to
b8e985e
Compare
library/psa_crypto.c
Outdated
return( PSA_ERROR_BUFFER_TOO_SMALL ); | ||
|
||
status = psa_get_and_lock_key_slot_with_policy( key, &slot, | ||
PSA_KEY_USAGE_SIGN_MESSAGE, |
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.
@gilles-peskine-arm Shouldn't keys registered with PSA_KEY_USAGE_SIGN_HASH
also be able to be used with sign_message
, since SIGN_HASH
is more permissive than SIGN_MESSAGE
?
Asking in the interest of compatibility, i.e. keys that have so far been created with SIGN_HASH permission cannot be upgraded to SIGN_MESSAGE, so the next best thing would be to allow them to be used for the all-in-one operation too.
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.
Indeed, and likewise with VERIFY
. Though this isn't the best place to implement it, since according to the specification
if an application sets the flag PSA_KEY_USAGE_SIGN_HASH when creating a key, then the key always has the permissions conveyed by PSA_KEY_USAGE_SIGN_MESSAGE, and the flag PSA_KEY_USAGE_SIGN_MESSAGE will also be present when the application queries the usage flags of the key.
So the right place to implement this is when setting the attributes of a new key. Otherwise psa_get_key_attributes
won't do the right thing. This is part of the scope of #3267, but it's up to @gabor-mezei-arm whether to do it in this pull request or in a follow-up.
Upgrading existing keys in persistent storage was not in scope, so I've filed a separate issue for it.
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.
It will done in a separate PR.
@stevew817 @ronald-cron-arm The driver wrapper of |
The current approach regarding the dynamically registered drivers is just to not break the current support, no need to add additional support. Thus here I don't think you need to do anything regarding the dynamically registered drivers. |
9ed23a7
to
e48e4bd
Compare
c80d7a2
to
66a8b9b
Compare
Rebased to development_2.x, need to be forwardported to the development branch. |
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 even better to me after these last 4 commits 👍
Thanks for the updates, looks good to me as well. Please make a PR for 3.0. |
|
||
PSA_ASSERT( psa_crypto_init( ) ); | ||
psa_set_key_type( &attributes, | ||
PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP_R1 ) ); |
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.
Please replace PSA_ECC_CURVE_xxx
by PSA_ECC_FAMILY_xxx
as well. PSA_ECC_CURVE_xxx
are deprecated in 2.x, even if they aren't removed yet.
CI only let this through because this code isn't built in the full
config.
Signed-off-by: gabor-mezei-arm <[email protected]>
fc51f43
to
c97b8ab
Compare
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
Backport 2.x: Add changelog entry for #4357
Description
Implement the PSA Crypto API 1.0.0 functions psa_sign_messsage and psa_verify_message.
Since Mbed TLS only supports hash-and-sign algorithms, these are simple wrappers around psa_hash_compute and psa_sign_hash/psa_verify_hash.
Also part of the goal of this task is to implement the corresponding policies PSA_KEY_USAGE_SIGN_MESSAGE and PSA_KEY_USAGE_VERIFY_MESSAGE.
Resolve #3267
Requires Forwardporting