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 multipart cipher accelerator support and test driver #3644

Conversation

stevew817
Copy link
Contributor

@stevew817 stevew817 commented Sep 3, 2020

Description

This PR adds support for delegating multipart cipher operations to an accelerator driver complying to the spec in #3493. It also adds a multipart cipher test driver implementing AES-CTR, as requested in #3345. Test suite tests are added to make sure the test driver is called when expected.

Status

READY

Requires Backporting

NO

Migrations

NO

Additional comments

NOTE: this PR currently depends on #3501 (reflected in the fact that it is based on the head of 3501). Will rebase once 3501 gets merged to development, so for review, please only look at commits e6167ca .. b9eddca.

Todos

  • Tests
  • Documentation
  • Changelog updated

Steps to test or reproduce

Tests are added to the test suite.

@stevew817
Copy link
Contributor Author

@danh-arm Can you tell me what the internal CI is complaining about this time?

@gilles-peskine-arm
Copy link
Contributor

The only CI failure is the ABI check, which signals that some structures in crypto_struct.h have changed size. So we need to bump the libmbedcrypto soversion. It doesn't have to be done in this PR: we usually do it as part of the release. So you can consider the CI to have passed.

@ronald-cron-arm ronald-cron-arm self-requested a review September 7, 2020 16:43
@ronald-cron-arm
Copy link
Contributor

I've had a quick look to the commits and overall it looks as I was expecting (following the review of #3501) with regard to changes in psa_crypto.c, psa_crypto_driver_wrappers.c and the testing. Please rebase on top of development and update the changes according to the review of #3501 and I will do the complete review.

@stevew817
Copy link
Contributor Author

Awesome, thanks. Will do tomorrow.

@gilles-peskine-arm
Copy link
Contributor

Like Ronald, I've had a quick look and the general shape looks about right. I would suggest one design change: rather than a “cipher” driver, I think it makes more sense to have a “multipart” driver, which would be extended later with multipart hash, MAC and AEAD.

@stevew817
Copy link
Contributor Author

rather than a “cipher” driver, I think it makes more sense to have a “multipart” driver, which would be extended later with multipart hash, MAC and AEAD.

Not sure I agree. I'm more convinced these should be grouped by functional (algorithm) group.

@stevew817
Copy link
Contributor Author

@ronald-cron-arm and @gilles-peskine-arm, I've now rebased, so actual review can go ahead.

@gilles-peskine-arm gilles-peskine-arm added component-crypto Crypto primitives and low-level interfaces HwDrivers needs-review Every commit must be reviewed by at least two team members, labels Sep 8, 2020
include/psa/crypto_struct.h Outdated Show resolved Hide resolved
library/psa_crypto.c Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
tests/src/drivers/cipher.c Show resolved Hide resolved
tests/include/test/drivers/cipher.h Outdated Show resolved Hide resolved
tests/include/test/drivers/cipher.h Show resolved Hide resolved
include/psa/crypto_struct.h Outdated Show resolved Hide resolved
library/psa_crypto.c Show resolved Hide resolved
library/psa_crypto_driver_wrappers.c Outdated Show resolved Hide resolved
library/psa_crypto_driver_wrappers.c Outdated Show resolved Hide resolved
library/psa_crypto_driver_wrappers.c Outdated Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
(void) iv;
(void) iv_size;
(void) iv_length;

Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, please add the "usual" code for negative testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

(void) operation;
(void) iv;
(void) iv_length;

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, code for negative testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -39,3 +39,87 @@ generate_key:PSA_ERROR_NOT_SUPPORTED:"":PSA_SUCCESS

generate_key through transparent driver: error
generate_key:PSA_ERROR_GENERIC_ERROR:"":PSA_ERROR_GENERIC_ERROR

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some negative testing as well as you did in #3501. We should have for each driver entry point at least one test where the driver entry point returns in error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@stevew817
Copy link
Contributor Author

@gilles-peskine-arm and @ronald-cron-arm , your review comments should now be incorporated in the changes. The one exception is negative testing, which I'll add, but I'd like you to review the changes already while I work on the negative testcases.

@gilles-peskine-arm
Copy link
Contributor

The pr-merge job passed except for the expected ABI change in crypto_struct.h so CI can be considered a pass. The pr-head job had a failure due to a network glitch but it's unnecessary to run it since pr-merge passed.

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.

Mostly looking good, but a few issues remain.

library/psa_crypto.c Outdated Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
include/psa/crypto_struct.h Outdated Show resolved Hide resolved
library/psa_crypto.c Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
tests/src/drivers/cipher.c Show resolved Hide resolved
@stevew817
Copy link
Contributor Author

@gilles-peskine-arm thanks for the continued feedback. All issues you flagged should now be resolved.

@stevew817
Copy link
Contributor Author

@ronald-cron-arm negative testing is now implemented too.

@ronald-cron-arm
Copy link
Contributor

ok, thanks, looking.

Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Choose a reason for hiding this comment

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

Thank you very much for all the changes especially the addition of negative testing. Here is my second round of review, mostly suggestions for improvement.

library/psa_crypto.c Outdated Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
library/psa_crypto.c Outdated Show resolved Hide resolved
tests/suites/test_suite_psa_crypto_driver_wrappers.data Outdated Show resolved Hide resolved
tests/suites/test_suite_psa_crypto_driver_wrappers.data Outdated Show resolved Hide resolved
@stevew817
Copy link
Contributor Author

@ronald-cron-arm Your feedback has been taken into account. Does this look good to you now?

@ronald-cron-arm
Copy link
Contributor

Thanks. I am attending a training right know. I will look at it this afternoon.

Signed-off-by: Steven Cooreman <[email protected]>
Signed-off-by: Steven Cooreman <[email protected]>
Signed-off-by: Steven Cooreman <[email protected]>
Added zeroization of the wrapper context on failure/abort, and reliance on
the crypto core to not call an uninitialised wrapper.

Signed-off-by: Steven Cooreman <[email protected]>
As pointed out by Ronald. The key slot is populated using
get_key_from_slot, and after calling the driver the slot is
validated to not contain an external key, so calling
get_transparent_key is superfluous.

Signed-off-by: Steven Cooreman <[email protected]>
As pointed out by Gilles

Signed-off-by: Steven Cooreman <[email protected]>
* Reworked the cipher context once again to be more robustly defined
* Removed redundant memset
* Unified behaviour on failure between driver and software in cipher_finish
* Cipher test driver setup function now also returns early when its status
  is overridden, like the other test driver functions
* Removed redundant test cases
* Added bad-order checking to verify the driver doesn't get called where
  the spec says it won't.

Signed-off-by: Steven Cooreman <[email protected]>
Signed-off-by: Steven Cooreman <[email protected]>
@stevew817
Copy link
Contributor Author

Rebased onto development due to merge conflict after merge of #3480. @ronald-cron-arm and @gilles-peskine-arm, please re-approve.

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 reviewed the commits up to 4d55104, then I checked that merging this with development gives the same content as 6d81f7e (up to cosmetic choices).

Looks good to me.

CI passes. The failure is the API/ABI check pointing out the expected ABI changes in crypto_struct.h.

Copy link
Contributor

@ronald-cron-arm ronald-cron-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've been through the rebase myself and ended-up with a result compatible with the result in this PR. LGTM.

@gilles-peskine-arm gilles-peskine-arm removed the needs-review Every commit must be reviewed by at least two team members, label Sep 15, 2020
@gilles-peskine-arm gilles-peskine-arm merged commit 7107e66 into Mbed-TLS:development Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-crypto Crypto primitives and low-level interfaces
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants