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

Document driver testing status #8566

Merged
merged 20 commits into from
Apr 17, 2024
Merged

Document driver testing status #8566

merged 20 commits into from
Apr 17, 2024

Conversation

mpg
Copy link
Contributor

@mpg mpg commented Nov 24, 2023

Description

This PR's main goal is to document the strategy used to test the PSA Crypto driver interface, as well as the current implementation status of that strategy.

Along the way, a couple of minor things are modified, but the PR's goal is not to fix things, or even to provide a complete plan for action - only to document the current state of things (which could be the first step towards an action plan).

Main gaps identified:

  • Opaque is mostly not tested at all (only a few key management entry points are tested but not even all of them (edit: and now asymmetric encrypt/decrypt), and not simulating an opaque driver with internal storage).
  • Key derivation is not tested at all.
  • Fallback to other entry points for operations that support it (like using mulit-part entry points for one-short API when the driver doesn't provide one-shot) is not tested at all - see also Support PSA drivers without verify entry points #4570
  • Two gaps in driver-only testing (compared to what we're supposed to support). Fixed in the meantime: 8616, 8734.
  • A number of gaps in test_suite_psa_crypto_driver_wrapper.data.

PR checklist

  • changelog not required - only documentation and testing
  • backport not required - only useful for new development
  • tests not required - only documentation and testing changes

@mpg mpg 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 size-s Estimated task size: small (~2d) labels Nov 24, 2023
@mpg mpg self-assigned this Nov 24, 2023
@mpg mpg requested a review from valeriosetti November 24, 2023 11:53
@mpg
Copy link
Contributor Author

mpg commented Nov 24, 2023

@gilles-peskine-arm @ronald-cron-arm Since you're probably the most familiar with this, I'd appreciate if you could take a look - maybe not a complete review but at high-level view to see if this looks reasonable or if you notice any misunderstanding or obvious omissions here.

Copy link
Contributor

@valeriosetti valeriosetti left a comment

Choose a reason for hiding this comment

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

I only found 1 typo, the rest is fine for me. However the CI is not fully happy about the change made to generate_ec_key

valeriosetti
valeriosetti previously approved these changes Nov 30, 2023
Copy link
Contributor

@valeriosetti valeriosetti left a comment

Choose a reason for hiding this comment

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

LGTM

@mpg mpg removed the needs-reviewer This PR needs someone to pick it up for review label Dec 1, 2023
@mpg mpg requested a review from valeriosetti December 18, 2023 10:38
@valeriosetti
Copy link
Contributor

I think that at least 3 out of 4 errors found in test_psa_crypto_config_accel_cipher_aead belong to the fact that CTR-DRBG is using AES through PSA now:

[2023-12-18T11:12:54.941Z] generate_ec_key through transparent driver: fake .................. FAILED
[2023-12-18T11:12:54.941Z]   mbedtls_test_driver_key_management_hooks.hits == 1
[2023-12-18T11:12:54.941Z]   at line 791, suites/test_suite_psa_crypto_driver_wrappers.function
[2023-12-18T11:12:54.941Z]   lhs = 0x0000000000000005 = 5
[2023-12-18T11:12:54.941Z]   rhs = 0x0000000000000001 = 1
[2023-12-18T11:12:54.941Z] generate_ec_key through transparent driver: in-driver ............. FAILED
[2023-12-18T11:12:54.941Z]   mbedtls_test_driver_key_management_hooks.hits == 1
[2023-12-18T11:12:54.941Z]   at line 791, suites/test_suite_psa_crypto_driver_wrappers.function
[2023-12-18T11:12:54.941Z]   lhs = 0x0000000000000008 = 8
[2023-12-18T11:12:54.941Z]   rhs = 0x0000000000000001 = 1
[2023-12-18T11:12:54.941Z] generate_ec_key through transparent driver: fallback .............. FAILED
[2023-12-18T11:12:54.941Z]   mbedtls_test_driver_key_management_hooks.hits == 1
[2023-12-18T11:12:54.941Z]   at line 791, suites/test_suite_psa_crypto_driver_wrappers.function
[2023-12-18T11:12:54.941Z]   lhs = 0x0000000000000008 = 8
[2023-12-18T11:12:54.941Z]   rhs = 0x0000000000000001 = 1

I think we should fix this (as we did recently) by adding a specific hit counter instead of mbedtls_test_driver_key_management_hooks.hits. Wdyt?

@mpg
Copy link
Contributor Author

mpg commented Dec 20, 2023

I think we should fix this (as we did recently) by adding a specific hit counter instead of mbedtls_test_driver_key_management_hooks.hits. Wdyt?

Sounds good, thanks for the suggestion! I hadn't even looked at the CI results yet, thanks for analyzing the failures!

Copy link
Contributor

@valeriosetti valeriosetti left a comment

Choose a reason for hiding this comment

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

I only found 1 typo which I didn't see before. The rest is fine for me :)

@@ -37,34 +37,76 @@
#endif

/* Use the accelerator driver for all cryptographic mechanisms for which
* the test driver implemented. */
* the test driver is implemented. This is copied from psa/crypto_config.h
* with the parts not implmented by the test driver commented out. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* with the parts not implmented by the test driver commented out. */
* with the parts not implemented by the test driver commented out. */

@mpg mpg force-pushed the driver-status branch 3 times, most recently from be21b16 to 9cf821c Compare December 22, 2023 10:01
@mpg
Copy link
Contributor Author

mpg commented Dec 29, 2023

Note to self: update names of cipher/aead components when #8641 has been merged.

@mpg mpg added the needs-work label Jan 4, 2024
@mpg mpg removed the needs-work label Jan 10, 2024
@mpg mpg requested a review from valeriosetti January 10, 2024 11:55
valeriosetti
valeriosetti previously approved these changes Jan 11, 2024
mpg added 12 commits April 12, 2024 12:40
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Improved by Mbed-TLS#8616 - closing
8553.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Been merged in the meantime.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Mbed-TLS#8700 merged in the meantime.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
@mpg
Copy link
Contributor Author

mpg commented Apr 12, 2024

@gilles-peskine-arm Thanks for your review! I believe I have addressed your feedback.

I've also had to rebase to resolve a conflict. Turns out the commit "Fix failure in some configs by being more precise" was no longer needed as something similar had been done in development in the meantime.

@mpg mpg requested review from gilles-peskine-arm and ronald-cron-arm and removed request for ronald-cron-arm April 12, 2024 10:46
@mpg mpg removed the needs-work label Apr 12, 2024
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.

LGTM except for a typo, and maybe one bit of explanation to add.

As before, I haven't reviewed the details of which entry points are covered, and I intend to approve regardless. I'm confident that even if there are mistakes, they're minor, and no worse than what this document is likely to become over time when people improve the tests and forget to update the document.

implementing the operation. This will remain hard to test until we have proper
support for JSON-defined drivers with auto-generation of dispatch code.
(The `MBEDTLS_PSA_ACCEL_xxx` macros we currently use are not expressive enough
to specify which entry points are support for a given mechanism.)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
to specify which entry points are support for a given mechanism.)
to specify which entry points are supported for a given mechanism.)

operation: entry points always return `NOT_SUPPORTED`.
The opaque driver implements the declared entry points, and can use any
backend: internal or libtestdriver1. However it does not implement the
instrumentation (hits, forced output/status), as this [was not an immediate
Copy link
Contributor

Choose a reason for hiding this comment

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

From a chat with Ronald: hits is actually probably an obsolete concern. With the internal backend, hits were how we knew that the driver was called, as opposed to directly calling the built-in code. With libtestdriver1, we check that by ensuring that the built-in code is not present, so if the operation gives the correct result, only a driver call can have calculated that result. So there is low value in checking the hit count. There is still some value for hit counts, e.g. checking that we don't call a multipart entry point when we intended to call the one-shot entry point, but it's limited.

And fix a typo while at it.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
@mpg mpg requested a review from gilles-peskine-arm April 15, 2024 08:57
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.

LGTM

Copy link
Contributor

@valeriosetti valeriosetti left a comment

Choose a reason for hiding this comment

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

LGTM ;)

@mpg mpg 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 Apr 17, 2024
@mpg mpg added this pull request to the merge queue Apr 17, 2024
Merged via the queue into Mbed-TLS:development with commit 68deadd Apr 17, 2024
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 size-s Estimated task size: small (~2d)
Projects
Status: Driver-only cleanups
Development

Successfully merging this pull request may close these issues.

4 participants