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

Implement psa_sign_message and psa_verify_message #4357

Conversation

gabor-mezei-arm
Copy link
Contributor

@gabor-mezei-arm gabor-mezei-arm commented Apr 16, 2021

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

@gabor-mezei-arm gabor-mezei-arm added enhancement component-crypto Crypto primitives and low-level interfaces needs-ci Needs to pass CI tests PSA compliance labels Apr 16, 2021
@gabor-mezei-arm gabor-mezei-arm self-assigned this Apr 16, 2021
@gabor-mezei-arm gabor-mezei-arm force-pushed the 3267_Implement_psa_sign_message_and_verify branch from e80a36e to 2198a7e Compare April 16, 2021 14:41
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.

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 a psa_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 the SIGN_MESSAGE or VERIFY_MESSAGE usage.

library/psa_crypto.c Outdated Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
tests/suites/test_suite_psa_crypto.data Show resolved Hide resolved
include/psa/crypto_values.h Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
@stevew817
Copy link
Contributor

It may be better to first merge this PR, then implement the new driver dispatch at once for both sign-hash and sign-message.

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 psa_sign_hash and psa_verify_hash. I'd very much like for that to happen in this PR, since it's not all that much work and avoids the lead-time of yet another PR.

@gabor-mezei-arm gabor-mezei-arm force-pushed the 3267_Implement_psa_sign_message_and_verify branch from 2198a7e to b8e985e Compare April 19, 2021 10:51
@gabor-mezei-arm gabor-mezei-arm added needs-work and removed needs-ci Needs to pass CI tests labels Apr 19, 2021
return( PSA_ERROR_BUFFER_TOO_SMALL );

status = psa_get_and_lock_key_slot_with_policy( key, &slot,
PSA_KEY_USAGE_SIGN_MESSAGE,
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@gabor-mezei-arm
Copy link
Contributor Author

@stevew817 @ronald-cron-arm The driver wrapper of psa_sign_hash is calling the crypto SE driver p_sign if crypto SE is enabled. Is there a need for a similar driver for the psa_sign_message or just use the p_sign for the signing step?

@ronald-cron-arm
Copy link
Contributor

@stevew817 @ronald-cron-arm The driver wrapper of psa_sign_hash is calling the crypto SE driver p_sign if crypto SE is enabled. Is there a need for a similar driver for the psa_sign_message or just use the p_sign for the signing step?

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.

@gabor-mezei-arm gabor-mezei-arm force-pushed the 3267_Implement_psa_sign_message_and_verify branch 5 times, most recently from 9ed23a7 to e48e4bd Compare April 27, 2021 09:14
@gabor-mezei-arm gabor-mezei-arm changed the base branch from development to development_2.x April 27, 2021 15:08
@gabor-mezei-arm gabor-mezei-arm force-pushed the 3267_Implement_psa_sign_message_and_verify branch from c80d7a2 to 66a8b9b Compare April 27, 2021 15:10
@gabor-mezei-arm
Copy link
Contributor Author

Rebased to development_2.x, need to be forwardported to the development branch.

@gabor-mezei-arm gabor-mezei-arm added needs-ci Needs to pass CI tests 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-work needs-ci Needs to pass CI tests labels Apr 27, 2021
stevew817
stevew817 previously approved these changes May 12, 2021
Copy link
Contributor

@stevew817 stevew817 left a 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 👍

@gilles-peskine-arm gilles-peskine-arm removed the needs-review Every commit must be reviewed by at least two team members, label May 12, 2021
@gilles-peskine-arm
Copy link
Contributor

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 ) );
Copy link
Contributor

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.

stevew817
stevew817 previously approved these changes May 14, 2021
Signed-off-by: gabor-mezei-arm <[email protected]>
@gabor-mezei-arm gabor-mezei-arm added needs-review Every commit must be reviewed by at least two team members, and removed needs-backports Backports are missing or are pending review and approval. labels May 14, 2021
@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 May 17, 2021
@gilles-peskine-arm gilles-peskine-arm merged commit bed4e9e into Mbed-TLS:development_2.x May 17, 2021
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this pull request May 17, 2021
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this pull request May 17, 2021
gilles-peskine-arm added a commit that referenced this pull request May 19, 2021
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement psa_sign_message and psa_verify_message
5 participants