PK: remove pk_can_do() -- part 1#615
Open
valeriosetti wants to merge 16 commits intoMbed-TLS:developmentfrom
Open
PK: remove pk_can_do() -- part 1#615valeriosetti wants to merge 16 commits intoMbed-TLS:developmentfrom
pk_can_do() -- part 1#615valeriosetti wants to merge 16 commits intoMbed-TLS:developmentfrom
Conversation
4eded3a to
3924975
Compare
3924975 to
63d088d
Compare
7cc1d09 to
78fe6c1
Compare
78fe6c1 to
643ec31
Compare
The function is testing both "pk_sign_ext" and "pk_verify_ext" and in follow-up commits it's going to be extended to become the main function for testing these 2 functions. So this commits just rename it before any real reshaping happens. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
This will allow to test the same functions with PK contexts generated in different ways. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Add one exta param to allow specify which algorithm must be associated to the PSA key. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
…_ext Usage of mbedtls_pk_type_t type as input parameters to sign_ext/verify_ext belong to the past. These functions nowadays use mbedtls_pk_sigalg_t types. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Expected return values are added indipendently for both sign and verify because wrapped keys might miss some functionality so having them separate will become handy in future steps. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
There are already 2 hash algorithm being tested: SHA-256 and SHA-384. Testing 2 is already enough and the 3rd one doesn't bring any useful info when it comes to sign_ext/verify_ext. Moreover tests are going to be expanded soon, so adding extra complexity doesn't help. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Previous testing was limited to PK contexts that were copied from PSA. Now we also test the wrapped case (i.e. what was once named "opaque"). Signed-off-by: Valerio Setti <vsetti@baylibre.com>
This kind of tests are now covered from "pk_sign_ext_verify_ext()". Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Add more positive and negative testing for all the relevant cases. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Just try to perform a signature with the given signature and MD algorithms. Rely on psa_sign_hash() to check if the PSA key in the PK context supports the operation of not. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Similarly to what has been done with mbedtls_pk_sign_ext() this commit modifies mbedtls_pk_verify_ext() so that it tries to perform a signature verification using the signature and MD algorithms provided as input. psa_verify_hash() will determine if the provided PK context can perform the requested operation or not. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Adapt the test function to recent changes in mbedtls_pk_verify_ext(). Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Adapt pk_sign_ext_verify_ext to recent changes in sign_ext and verify_ext. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Adapt pk_rsa_overflow() to recent changes in pk_sign_ext() and pk_verify_ext(). Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Now that "pk_[sign|verify]_ext()" work the same for all PK context types it doesn't make sense to translate "PSA_ERROR_INVALID_SIGNATURE" to "MBEDTLS_ERR_RSA_VERIFY_FAILED". Besides this translation is only available when RSA key types are defined, which is not always true. For this reason this commit introduces a more generic "MBEDTLS_ERR_PK_INVALID_SIGNATURE" which is valid for any PK context handled by PK module. The translation is trivially to "PSA_ERROR_INVALID_SIGNATURE" of course. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
643ec31 to
fe33401
Compare
…A-PSS This change is related to recent changes that have been done to mbedtls_pk_verify_ext() and the explanation is as follows. Ideally the public key material in the RSA context would be OK to perform RSA-PSS verification if this were the main algorithm associated with the key once imported to PSA. However when an RSA key-pair is imported to PK do a signature the main algorithm is always PKCS v1.5 and PSS is the enrollment one (which is gated by MBEDTLS_PSA_CRYPTO_C). As a consequence, for sake of symmetrical behavior, the same algorithms should be used for verification, meaning that in order to have RSA-PSS successfully working with verify_ext() it requires MBEDTLS_PSA_CRYPTO_C to be enabled. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
bjwtaylor
reviewed
Feb 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
TL;DR
Addresses the first part of #523: modify
mbedtls_pk_[sign|verify]_ext()so that they don't usembedtls_pk_can_do().Details
Commits in this PR can be divided into 3 blocks:
mbedtls_pk_[sign|verify]_ext()in order to cover all possible casesmbedtls_pk_[sign|verify]_ext()so that they really perform as an_extfunction over the simplermbedtls_pk_[sign|verify]()counterparts: i.e. try to sign|verify using the specified sigalg and PK context.[sign|verify]_ext()was behaving differently than expected are removed.[sign|verify]_ext()are not affected by this functions' reshaping! To me this is a sort of proof that these changes might be potentially transparent for the end user.Advantage of the reshape
Once this will be merged we can make
mbedtls_pk_[sign|verify]()calling into their_ext()counterpart (instead of the restartable ones) as it it normally happens for other "standard"/"extended" functions in the library.PR checklist
mbedtls_pk_can_dois internal, so nothing to be notified