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

Move tests/scripts/check_names.py to the framework #103

Merged
merged 62 commits into from
Jan 9, 2025

Conversation

valeriosetti
Copy link
Contributor

@valeriosetti valeriosetti commented Dec 13, 2024

Resolves #73

development PR: Mbed-TLS/mbedtls#9853
mbedtls-3.6 PR: Mbed-TLS/mbedtls#9854

eleuzi01 and others added 30 commits December 9, 2024 15:35
Signed-off-by: Elena Uziunaite <[email protected]>
Signed-off-by: Elena Uziunaite <[email protected]>
Signed-off-by: Elena Uziunaite <[email protected]>
Signed-off-by: Elena Uziunaite <[email protected]>
Uniformly return PSA_ERROR_NOT_SUPPORTED if given an algorithm that includes
a hash, but that hash algorithm is not supported. This will make it easier
to have a uniform treatment of unsupported hashes in automatically generated
tests.

Signed-off-by: Gilles Peskine <[email protected]>
Allow imports of an ECC public key on an unsupported curve to return
INVALID_ARGUMENT rather than NOT_SUPPORTED. This can happen in our library
code in edge cases when only certain curve families are supported, and it's
acceptable.

The new code does not trigger yet, but it will be useful for a future commit
"Do run not-supported test cases on not-implemented mechanisms"
(forward port of 995d7d4c15406b0a115cadf3f5ec69becafdf20f).

Signed-off-by: Gilles Peskine <[email protected]>
Following "PSA sign/verify: more uniform error on an unsupported hash", some
error cases are detected earlier, so there is some sloppiness in test case
dependencies that is not longer acceptable.

* In test_suite_psa_crypto, one test case for a hash+sign algorithm now
  returns NOT_SUPPORTED rather than INVALID_ARGUMENT when the hash is not
  supported and the key is invalid.
* In test_suite_psa_crypto_se_driver_hal_mocks, some test cases now error
  out before reaching the mocks rather than after when they attempt to
  use an unsupported hash.

Signed-off-by: Gilles Peskine <[email protected]>
ECDSA has two variants: deterministic (PSA_ALG_DETERMINISTIC_ECDSA) and
randomized (PSA_ALG_ECDSA). The two variants are different for signature but
identical for verification. Mbed TLS accepts either variant as the algorithm
parameter for verification even when only the other variant is supported,
so we need to handle this as a special case when generating not-supported
test cases.

In this commit:

* Add manually written not-supported test cases for the signature
  operation when exactly one variant is supported.
* Add manually written positive test cases for the verification
  operation when exactly one variant is supported.
* Register that !ECDSA but DETERMINISTIC_ECDSA is not tested yet
  (Mbed-TLS/mbedtls#9592).

A commit in the framework will take care of automatically generated test cases.

Signed-off-by: Gilles Peskine <[email protected]>
In particular, if interruptible ECDSA is supported but not the deterministic
variant, detect this in psa_sign_hash_start(), whereas before start() would
succeed and psa_sign_hash_complete() would fail. This avoids an
inconsistency between psa_sign_hash() and psa_sign_hash_start() that would
be annoying to handle in test_suite_psa_crypto_op_fail.

Signed-off-by: Gilles Peskine <[email protected]>
For ECDSA verification, there is no difference between the deterministic and
randomized algorithm. The PSA core consider the two variants as identical as
far as key policies are concerned, and the built-in implementation accepts
either variant even if only the other variant is supported for signature.

In p256-m, accept to perform an ECDSA verification when the algorithm is
specified as deterministic ECDSA. This makes the behavior identical to the
built-in implementation, which is less surprising for users and saves us
from having to cope with a difference in our testing.

Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
Key type must be a key pair or public-key if not we return
PSA_ERROR_INVALID_ARGUMENT.

The key type must be ECC key as this is what we support for
now otherwise we return PSA_ERROR_NOT_SUPPORTED.

Signed-off-by: Waleed Elmelegy <[email protected]>
The test is marked as opaque but the parameter was set
to PSA_KEY_LIFETIME_VOLATILE.

Signed-off-by: Waleed Elmelegy <[email protected]>
Rename it to mbedtls_psa_export_public_key_iop_t as
iop stands for "interuptible operation" already.

Signed-off-by: Waleed Elmelegy <[email protected]>
The test is supposed to be an opaque key test but the
testing function does not support specifying an
opaque driver.

Signed-off-by: Waleed Elmelegy <[email protected]>
Signed-off-by: Elena Uziunaite <[email protected]>
* Improve wording of comments.
* Zeroize buffer before doing iop testing to
  avoid comparing with previous values in
  case they are not overwritten.
* Remove redundant testing.

Signed-off-by: Waleed Elmelegy <[email protected]>
Move scripts used by all-core.sh to the framework
Just to ease the eventual migration
of check-generated-files.sh to
the framework.

Signed-off-by: Ronald Cron <[email protected]>
ronald-cron-arm and others added 15 commits December 11, 2024 14:07
…key-complete

Add PSA interruptible export public-key complete API
Signed-off-by: Ronald Cron <[email protected]>
The following files are added (imported) from the main Mbed TLS repo:

scripts/check_names.py

Signed-off-by: Valerio Setti <[email protected]>
@valeriosetti valeriosetti added needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review size-xs Estimated task size: extra small (a few hours at most) priority-high High priority - will be reviewed soon and removed needs-ci Needs to pass CI tests labels Dec 13, 2024
Copy link
Contributor

@eleuzi01 eleuzi01 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@eleuzi01
Copy link
Contributor

eleuzi01 commented Jan 9, 2025

I imagine this needs rebasing too just like in #95 (comment)

@valeriosetti
Copy link
Contributor Author

I imagine this needs rebasing too just like in #95 (comment)

I'm not sure. GH doesn't complain for a potential merge conflict (as of now) so whenever this will be merged it will be on the top of the main branch in the framework repo. Then yes, Mbed-TLS/mbedtls#9853 and Mbed-TLS/mbedtls#9854 will be updated to use the new hash reference of the framework.
Am I missing something?

@ronald-cron-arm
Copy link
Contributor

ronald-cron-arm commented Jan 9, 2025

I imagine this needs rebasing too just like in #95 (comment)

I'm not sure. GH doesn't complain for a potential merge conflict (as of now) so whenever this will be merged it will be on the top of the main branch in the framework repo. Then yes, Mbed-TLS/mbedtls#9853 and Mbed-TLS/mbedtls#9854 will be updated to use the new hash reference of the framework. Am I missing something?

That's right actually, we do not really need to fix the framework conflict in Mbed-TLS/mbedtls#9853 and Mbed-TLS/mbedtls#9854 now.

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.

LGTM

@ronald-cron-arm ronald-cron-arm merged commit fe852d3 into Mbed-TLS:main Jan 9, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 priority-high High priority - will be reviewed soon size-xs Estimated task size: extra small (a few hours at most)
Development

Successfully merging this pull request may close these issues.

Move tests/scripts/check_names.py to the framework
8 participants