-
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
Script to determine PSA crypto test dependencies automatically #4012
Script to determine PSA crypto test dependencies automatically #4012
Conversation
7191372
to
ae48909
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.
That's look great. I have a few comments.
Her are snippets of code to compare outcomes.
|
Here's my analysis of the outcomes of 3cceab1 compared to a51e1db. See Easy casesFormerly skipped tests now passingThese are either spurious dependencies that resulted from copypasta, or in a few cases negative tests with a dependency that doesn't really matter. All is fine.
|
5cb5fbf
to
5b5b547
Compare
Is there an intention to have this script be part of all.sh's |
We are even thinking to improve it to stop having to set up dependencies manually anymore: see #4018. |
I'm not sure whether the one comment I have needs to be addressed in this PR or taken in a follow-up, therefore not blocking: Now that SHA384 and SHA512 are disentangled, would it make sense to change the PSA Crypto config to set |
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, see my previous comment for the one minor thing I had.
I haven't run the new script and compared the results myself, since it looks like @ronald-cron-arm did that already. I have reviewed the generated test suite changes and they look consistent to me.
You mean something like the following in config_psa.h: #if defined(PSA_WANT_ALG_SHA_512) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) #if defined(PSA_WANT_ALG_SHA_384) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) |
Or, with less changes:
|
Regarding SHA-384: the PSA config is supposed to be additive to the classic config. If it sets I hope we can resolve that in Mbed TLS 3.0 by changing |
[EDITED] I invoked the set_psa_test_dependencies.py script on test_suite_psa_crypto.data in commit 9a68810 ( our patch release branch ) and I applied some different test configs and I found a some issues. Some of them are in Silicon Labs device drivers, and the following in standard mbedTLS code: When I applied a "minimal" test config with no key derivation algos supported there was a test case that failed because psa_key_derivation_setup() returned PSA_ERROR_INVALID_ARGUMENT when PSA_ERROR_NOT_SUPPORTED is expected. I will apply the following fix in the integration branch of SIlicon Labs (which should eventually be requested merged upstream), however you may want to apply the patch for this PR :
Additionally, I needed to apply the following patches in test_suite_psa_crypto.function in order to pass a few tests:
|
Some symbols don't require a dependency symbol: * Modifiers such as truncated MAC * Always-on features such as the raw data key type * Aliases or special values such as RSA PKCS#1v1.5 raw I'm not convinced that all of these warrant special handling in the script, rather than having the expected symbol defined somewhere. But for now I prefer to minimize changes to the header files. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
PSA_xxx_CATEGORY_yyy is used in metadata tests where it doesn't involve any particular support, and elsewhere it's used as a value that is definitely not supported but is in a plausible range. Such symbols do not require any dependency. If a test case is expects PSA_ERROR_NOT_SUPPORTED, its dependencies (often including one negative dependency) cannot be determined automatically, so leave that test case alone. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
It doesn't make much difference in practice, but to keep closer to what the current code does, run negative key policy tests even if the algorithm for the operation attempt is not supported. In particular, this allows the following test cases to run: * "PSA key policy: agreement + KDF, wrong agreement algorithm" * "PSA key policy: raw agreement, wrong algorithm" Without this exception, those two test cases would never run, because they would depend on PSA_ALG_WANT_FFDH. Since FFDH is not implemented yet, it isn't enabled in any configuration. There's no alternative to FFDH for these particular test cases because ECDH is the only key agreement that is implemented in Mbed TLS so far. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This avoids having to bother with edge cases of the .data syntax. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Replace manually written dependencies on MBEDTLS_xxx with PSA_WANT_xxx dependencies that are determined automatically from the test data. Run tests/scripts/set_psa_test_dependencies.py on tests/suites/test_suite_psa_crypto*.data, except for the dynamic secure element tests in tests/suites/test_suite_psa_crypto_se_driver_hal*.data. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Switch dependencies on MBEDTLS_xxx to PSA_WANT_xxx for hash algorithms. Add a missing dependency in bad_order functions (it was previously expressed in the .data file, but this is no longer the case when dependencies in the .data file are determined automatically). Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
The test function asymmetric_signature_key_policy combines positive and negative tests inside the code, so it doesn't take a status as its last argument. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
It isn't a set of dependencies, it's a set of symbols. So give it a name that describes the symbol rather than a name that pretends it's a collection of dependencies. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
The negative test cases for psa_copy_key() don't actually care whether the target policy is supported. This is similar to _key_policy tests. Add a similar rule. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Storage format tests that only look at how the file is structured and don't care about the format of the key material don't depend on any cryptographic mechanisms. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
612ffd2
0d6ded0
to
612ffd2
Compare
There were merge conflicts, so I rebased on top of the target branch (at 53943ca). I also rewrote the history to squash the one fixup commit. I also tried merging and the result https://github.com/gilles-peskine-arm/mbedtls/tree/psa-test-new-dependencies-3-merge is identical to what I obtained by rebasing. The previous version is at https://github.com/gilles-peskine-arm/mbedtls/tree/psa-test-new-dependencies-3. |
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.
e4f539c has too long of a commit message. Otherwise still looking good.
At this point, given that we haven't historically been consistently enforcing any particular maximum length, I'd prefer to let it go. |
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've been through the rebase and ended up with the same result but for the new tests introduced in test_suite_psa_crypto_entropy.data by #3912. After running tests/scripts/set_psa_test_dependencies.py as in "Change PSA crypto test dependencies to PSA_WANT_xxx" commit I ended up with the same tree. Thus this looks good to me.
tests/suites/test_suite_psa_crypto*.data
This pull request adds a new script
tests/scripts/set_psa_test_dependencies.py
which determines thePSA_WANT_xxx
of PSA crypto test cases automatically.PSA_WANT_xxx
is not implemented for them yet.test_suite_psa_crypto*.data
(except for old-style SE tests).Out of scope of this PR:
.function
files (I only did enough to pass CI)MBEDTLS_PSA_CRYPTO_SE_C
)MBEDTLS_USE_PSA_CRYPTO
testsssl-opt.sh
all.sh
Outcome files are useful to check whether the same test cases run as before. Here's how I compared before/after for the default configuration:
outcomes.csv.xz
from a Jenkins CI run for a51e1db, which is the commit at which this PR's branch forks fromdevelopment
. Save the uncompressed file asa51e1dbe7611eb58593d0f63956f6eee2d489034.outcomes.csv
.data
files):default.csv
.