PK: inlined & simplify sign functions #537
Open
bjwtaylor wants to merge 53 commits from
bjwtaylor/simplify-sign_func into development
pull from: bjwtaylor/simplify-sign_func
merge into: gh-Mbed-TLS:development
gh-Mbed-TLS:development
gh-Mbed-TLS:tf-psa-crypto-1.1
gh-Mbed-TLS:archive/20261005T153337Z-force/pull/927
gh-Mbed-TLS:archive/20261001T141055Z-force/pull/927
gh-Mbed-TLS:archive/20261005T153337Z-force/pull/931
gh-Mbed-TLS:archive/20261001T083616Z-force/pull/927
gh-Mbed-TLS:archive/20260930T232327Z-force/pull/927
gh-Mbed-TLS:archive/20260930T154618Z-force/pull/927
gh-Mbed-TLS:archive/20260929T231919Z-rescue/rohankl-arm/mldsa-pubkey-899
gh-Mbed-TLS:archive/20260929T231919Z-rescue/sigvartmh/pr/spake2p-9342-public-key-import-export
gh-Mbed-TLS:archive/20260929T231919Z-rescue/ManoharPaturi/fix-pem-ct-padding
gh-Mbed-TLS:archive/20260929T231919Z-rescue/ManoharPaturi/fix-asn1write-null-guard
gh-Mbed-TLS:archive/20260929T231919Z-rescue/ManoharPaturi/fix-pbes2-params-validation
gh-Mbed-TLS:archive/20260929T231919Z-rescue/valeriosetti/blake2
gh-Mbed-TLS:archive/20260929T231919Z-rescue/jfdev001/v1.1.1_bump-cmake-minimum-version
gh-Mbed-TLS:archive/20260929T231919Z-rescue/jfdev001/bump-cmake-minimum-version
gh-Mbed-TLS:archive/20260929T231919Z-rescue/ronald-cron-arm/sm3-base
gh-Mbed-TLS:archive/20260929T231919Z-rescue/valeriosetti/blake2-hmac
gh-Mbed-TLS:archive/20260929T231919Z-rescue/v1rtu3x/enforce-hash-length-sign-verify
gh-Mbed-TLS:archive/20260929T231919Z-rescue/bjwtaylor/file-backed-keystore-doc
gh-Mbed-TLS:archive/20260929T231919Z-rescue/sigvartmh/pr/spake2p-9344-set-context
gh-Mbed-TLS:archive/20260929T231919Z-rescue/sigvartmh/pr/spake2p-9343-key-pair-import-export-depends-on-9342
gh-Mbed-TLS:archive/20260929T231919Z-rescue/romart/development
gh-Mbed-TLS:archive/20260929T231919Z-rescue/sweetlilmre/constant-time-embedded-perf
gh-Mbed-TLS:archive/20260929T231919Z-rescue/JulioLoayzaM/add-wycheproof-rsa-pss
gh-Mbed-TLS:archive/20260929T231919Z-rescue/JulioLoayzaM/add-wycheproof-ecdsa
gh-Mbed-TLS:archive/20260929T231919Z-rescue/JulioLoayzaM/add-wycheproof-tests
gh-Mbed-TLS:archive/20260929T231919Z-rescue/oubaid-a/dev_psa_driver_wrapper
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/keystoreless-prototype-1
gh-Mbed-TLS:archive/20260929T231919Z-rescue/valeriosetti/issue9580
gh-Mbed-TLS:archive/20260929T231919Z-rescue/LeonieReichertABB/hpke-functionality
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/psa-hash-no-buffer-copy-1.1
gh-Mbed-TLS:archive/20260929T231919Z-rescue/vanhauser-thc/development
gh-Mbed-TLS:archive/20260929T231919Z-rescue/tpambor/key-wrap
gh-Mbed-TLS:archive/20260929T231919Z-rescue/ruiliio/psa_xts
gh-Mbed-TLS:archive/20261011T063515Z-force/pull/538
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/fix-broken-links-1.1
gh-Mbed-TLS:archive/20260929T231919Z-rescue/valeriosetti/issue669
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/prepare-release-test
gh-Mbed-TLS:archive/20260929T231919Z-rescue/krish2718/wpa3-sae-design-note
gh-Mbed-TLS:archive/20260929T231919Z-rescue/nzzlinh/fix_iar_endianness_1.1
gh-Mbed-TLS:archive/20260929T231919Z-rescue/nzzlinh/fix-iar-endianness
gh-Mbed-TLS:archive/20260929T231919Z-rescue/abtom87/fix-pbkdf2-iter-count
gh-Mbed-TLS:archive/20260929T231919Z-rescue/minosgalanakis/tools/prepare_release_lite
gh-Mbed-TLS:archive/20260929T231919Z-rescue/Harshal5/fix/aes-xts-in-place-cts
gh-Mbed-TLS:archive/20260929T231919Z-rescue/sigvartmh/pr/spake2p-9347-prover-depends-on-9342-9343-9344
gh-Mbed-TLS:archive/20260929T231919Z-rescue/crabel99/async-hardware-support-c35df962
gh-Mbed-TLS:tf-psa-crypto-1.2.0_mergeback
gh-Mbed-TLS:tf-psa-crypto-1.1.1_mergeback
gh-Mbed-TLS:archive/20260929T231919Z-rescue/asmellby/feature/dispatch-library
gh-Mbed-TLS:tf-psa-crypto-release-sync
gh-Mbed-TLS:archive/20260929T231919Z-rescue/ChakshuGupta13/fix/ecdsa-zeroize-stack-key
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/security-md-option-names
gh-Mbed-TLS:archive/20260929T231919Z-rescue/parmi93/patch-2
gh-Mbed-TLS:archive/20260929T231919Z-rescue/bjwtaylor/remove-mldsa-sign-from-build
gh-Mbed-TLS:archive/20260929T231919Z-rescue/bjwtaylor/tf-m-build-issues
gh-Mbed-TLS:archive/20260929T231919Z-rescue/bjwtaylor/test-context-population
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/iar-1.1.0
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/fork-helper-unit-tests-create-crypto
gh-Mbed-TLS:archive/20260929T231919Z-rescue/bjwtaylor/redundant-declarations
gh-Mbed-TLS:archive/20260929T231919Z-rescue/hasheddan/docs/fix-broken-links
gh-Mbed-TLS:main
gh-Mbed-TLS:archive/20260929T231919Z-rescue/bjwtaylor/reintroduce-dh
gh-Mbed-TLS:archive/20260929T231919Z-rescue/bjwtaylor/cipher-update-incorrect-error
gh-Mbed-TLS:archive/20260929T231919Z-rescue/Marandil/fix/mbedtls-4314-parse-explicit-curve
gh-Mbed-TLS:archive/20260929T231919Z-rescue/schneider-electric/dev/plaj-se/parse-rsassa-pss
gh-Mbed-TLS:archive/20260929T231919Z-rescue/minosgalanakis/bugfix/program-fuzz-mscv
gh-Mbed-TLS:archive/20260929T231919Z-rescue/daverodgman/aesgcm
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/sha3-coverity-20260224
gh-Mbed-TLS:archive/20260929T231919Z-rescue/bensze01/undef
gh-Mbed-TLS:archive/20260929T231919Z-rescue/valeriosetti/issue523
gh-Mbed-TLS:archive/20260929T231919Z-rescue/dannytsen/ppc-dev
gh-Mbed-TLS:archive/20260929T231919Z-rescue/daverodgman/aes12
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/ascon-prototype
gh-Mbed-TLS:archive/20260929T231919Z-rescue/daverodgman/chacha10
gh-Mbed-TLS:archive/20260929T231919Z-rescue/kusumitg/implement_psa_pake_set_context_for_spake2p
gh-Mbed-TLS:archive/20260929T231919Z-rescue/davidhorstmann-arm/add-code-size-target
gh-Mbed-TLS:archive/20260929T231919Z-rescue/bjwtaylor/simplify-sign_func
gh-Mbed-TLS:archive/20260929T231919Z-rescue/mfil/feature/aes_ni_parallel
gh-Mbed-TLS:archive/20260929T231919Z-rescue/ivv19041994/patch-1
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/psa-verify-policy-relax
gh-Mbed-TLS:public_2/main
gh-Mbed-TLS:archive/20260929T231919Z-rescue/mpg/pk-sign-proto
gh-Mbed-TLS:release/tf-psa-crypto1.0.0-documentation
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/0e-plans-july-updates
gh-Mbed-TLS:archive/20260929T231919Z-rescue/davidhorstmann-arm/guard-context-types-in-client-only
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/psa-driver-interface-spec-remove
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/ecp-self-test-race-crypto
gh-Mbed-TLS:archive/20260929T231919Z-rescue/KiruthikPrakash/feature/9342_add-support-for-spake2p-public-key-import-export
gh-Mbed-TLS:archive/20260929T231919Z-rescue/ruiliio/chacha20_16
gh-Mbed-TLS:archive/20260929T231919Z-rescue/irwir/winsock2
gh-Mbed-TLS:archive/20260929T231919Z-rescue/aphroteus/development
gh-Mbed-TLS:archive/20260929T231919Z-rescue/amjoul01/amjoul01/psa-mac-out-of-bound-fix
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/everest-submodule-crypto
gh-Mbed-TLS:archive/20260929T231919Z-rescue/yamt/xtensa-ccount
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/all.sh-generate-only-before-checks-crypto
gh-Mbed-TLS:archive/20260929T231919Z-rescue/Harshal5/feat/builtin_cmac_driver_use_psa_crypto_interface
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/test-data_t-empty_is_empty-crypto
gh-Mbed-TLS:archive/20260929T231919Z-rescue/jean-baptisteboric-eaton/oids-pkcs7-authenticated-attributes
gh-Mbed-TLS:dev/bensze01/public-only-commit
gh-Mbed-TLS:archive/20260929T231919Z-rescue/waleed-elmelegy-arm/psa-key-wrap-aes-kw
gh-Mbed-TLS:archive/20260929T231919Z-rescue/tfloch/psa_add_xts_algorithm
gh-Mbed-TLS:archive/20260929T231919Z-rescue/gilles-peskine-arm/msancf-clang16-crypto
gh-Mbed-TLS:archive/20260929T231919Z-rescue/DemiMarie/document-unexpected-tags
gh-Mbed-TLS:archive/20260929T231919Z-rescue/DemiMarie/strict-len
gh-Mbed-TLS:archive/20260929T231919Z-rescue/valeriosetti/issue9255-tfpsacrypto
gh-Mbed-TLS:archive/20260929T231919Z-rescue/daantimmer/use-compiler-frontend
gh-Mbed-TLS:archive/20260929T231919Z-rescue/benmcollins/enable-rsassa-pss-pkparse
gh-Mbed-TLS:dev/paul-elliott-arm/add_iop_key_agreement_negative_tests
gh-Mbed-TLS:add-iop-export-pub-key-get-num-ops
gh-Mbed-TLS:dev/rc/new-2-d635ea1
gh-Mbed-TLS:dev/bensze01/jenkins
No reviewers
Labels
Clear labels
api-break
This issue/PR breaks the API and must wait for a new major version
approved
Design and code approved - may be waiting for CI or backports
bug
Something isn't working
component-docs
Docs / website issues filed here for tracking
component-platform
Portability layer and build scripts
component-test
Test framework and CI scripts
dependencies
Pull requests that update a dependency file
deprecation
needs deprecation announcement
DO-NOT-MERGE
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
This issue is not being actively worked on, but PRs welcome.
needs-adoption
stalled PR that someone should pick up and complete
needs-backports
Backports are missing or are pending review and approval.
needs-ci
Needs to pass CI tests
needs-design-approval
Needs design discussion / approval
needs-info
An issue or PR which needs further info from the reporter / author
needs-preceding-pr
Requires another PR to be merged first
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
needs-work
priority-high
High priority - will be reviewed soon
priority-low
Low priority - this may not receive review soon
priority-medium
Medium priority - this can be reviewed as time permits
priority-scheduled
This PR is big - it will require time to be scheduled for review
priority-very-high
Highest priority - prioritise this over other review work
resolved-after-1.1
The issue is resolved in development, but still present in 1.1 LTS.
single-reviewer
This PR qualifies for having only one reviewer
size-l
Estimated task size: large (2w+)
size-m
Estimated task size: medium (~1w)
size-optimisation
size-s
Estimated task size: small (~2d)
size-xs
Estimated task size: extra small (a few hours at most)
No labels
api-break
approved
bug
component-docs
component-platform
component-test
dependencies
deprecation
DO-NOT-MERGE
enhancement
good first issue
help wanted
needs-adoption
needs-backports
needs-ci
needs-design-approval
needs-info
needs-preceding-pr
needs-review
needs-reviewer
needs-work
priority-high
priority-low
priority-medium
priority-scheduled
priority-very-high
resolved-after-1.1
single-reviewer
size-l
size-m
size-optimisation
size-s
size-xs
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
gh-Mbed-TLS/TF-PSA-Crypto!537
Loading…
Reference in a new issue
No description provided.
Delete branch "bjwtaylor/simplify-sign_func"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
PK: inlined & simplify sign functions depends https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/499 depends https://github.com/Mbed-TLS/mbedtls/pull/10439 resolves https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/515
We may need to add a task if it doesn't already exist to change MBEDTLS_ECDSA_DETERMINISTIC to PSA_ALG_DETERMINISTIC_ECDSA as itwas preventing some tests involved in this PR from running. I have changed these ones, however there maybe more that need investigation.
From the original issue the following test cases have been added where not present.
Non-wrapping context:
github.com/bjwtaylor/TF-PSA-Crypto@f5322b7cf5/tests/suites/test_suite_pk.data (L515)github.com/bjwtaylor/TF-PSA-Crypto@f5322b7cf5/tests/suites/test_suite_pk.data (L519)Wrapping context (created with pk_wrap_psa()):
github.com/bjwtaylor/TF-PSA-Crypto@f5322b7cf5/tests/suites/test_suite_pk.data (L647)github.com/bjwtaylor/TF-PSA-Crypto@f5322b7cf5/tests/suites/test_suite_pk.data (L599)Common:
github.com/bjwtaylor/TF-PSA-Crypto@589b7c46d8/tests/suites/test_suite_pk.data (L533)and other similar casesgithub.com/bjwtaylor/TF-PSA-Crypto@f5322b7cf5/tests/suites/test_suite_pk.data (L555)PR checklist
I realise now that the way the issue was worded is ambiguous (things were perfectly clear in my mind, but for people who can't read my mind I should have made some assumptions more explicit). I've added a section about scope that should hopefully clarify things: https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/515
@bjwtaylor There are some commits there that I authored, can I assume you've reviewed them? (That way, I can be a reviewer for the rest of the PR.)
@bjwtaylor Just had a quick look at the list of commits, and I'm afraid I'm not happy with the order: I'd like the new tests to come first, and only then the refactoring. That way we can be confident the refactoring is not accidentally changing observable behaviour. (Holds for all issues in this series: the order is always (1) add tests if needed, (2) refactor.)
@mpg, thanks for your feedback. It's safe to assume I've reviewed your commits. In terms of the commit order, this makes perfect sense. Do you want me to put the test changes right at the beginning before your commits, or after them?
@mpg, the commits should hopefully now be updated as you requested. The New CI has passed, so even though the OpenCI has stalled I think this is probably ready for you to take another look. Let me know if anything is not as you expect though.
Just took an initial look at the PR. I'll probably take another one tomorrow
@ -134,4 +123,1 @@sig, sig_size, sig_len);}static int rsa_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv)This comment refers to
mbedtls_pk_psa_rsa_sign_extabove. Why didn't you embed it intombedtls_pk_sign_ext()in the same way as you've done with other signature functions?Is there perhaps another issue for the
sign_extfunction? If so then sorry, but I didn't find it.I'm not sure I got the point in moving this declaration earlier. Unless it's strictly necessary, I suggest to keep changes at minimum.
@ -512,37 +512,49 @@ RSA hash_len overflow (size_t vs unsigned int)depends_on:PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY:MBEDTLS_HAVE_INT64I think
would be more aligned with surrounding test cases
A buffer of length 0 is definitely small, so this is OK :)
But it would be nice to check also other intermediate values. Since ECDSA signatures have (r,s) values written in ASN1 format (adding some overhead) and here you are using secp256r1 curve, I think that something like
PSA_ECDSA_SIGNATURE_SIZE(256)/2should fail as well.If you do this change then name this test case something like:
ECDSA restartable sign/verify: Output buffer too small (0 bytes)and a similar name for the other one
Perhaps
? But this is minor, as you prefer
@ -1204,2 +1211,2 @@ret = mbedtls_pk_sign_restartable(&prv, md_alg, hash->x, hash->len,sig, sizeof(sig), &slen,if (pub_key_test) {ret = mbedtls_pk_sign_restartable(&pub, md_alg, hash->x, hash->len,This is enough:
ditto
Not sure why it was moved, however doesn't seem to be required. So I've restored it to it's original position.
@ -134,4 +123,1 @@sig, sig_size, sig_len);}static int rsa_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv)So, I believe this is out of scope of the issue https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/515 as this is purely about inlining the functions involved in the sign_func element of the struct mbedtls_pk_info_t. I'm not sure if this is or should be involved in another issue? Or if there is another plan for this function? Probably a question for @mpg. Though if he's happy to grow the scope we can probably include it in this PR.
@ -1204,2 +1211,2 @@ret = mbedtls_pk_sign_restartable(&prv, md_alg, hash->x, hash->len,sig, sizeof(sig), &slen,if (pub_key_test) {ret = mbedtls_pk_sign_restartable(&pub, md_alg, hash->x, hash->len,Should now be removed.
@ -1204,2 +1211,2 @@ret = mbedtls_pk_sign_restartable(&prv, md_alg, hash->x, hash->len,sig, sizeof(sig), &slen,if (pub_key_test) {ret = mbedtls_pk_sign_restartable(&pub, md_alg, hash->x, hash->len,Should now be removed.
@ -512,37 +512,49 @@ RSA hash_len overflow (size_t vs unsigned int)depends_on:PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY:MBEDTLS_HAVE_INT64Now updated.
@ -512,37 +512,49 @@ RSA hash_len overflow (size_t vs unsigned int)depends_on:PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY:MBEDTLS_HAVE_INT64I've made the changes, let me know if they are not what you're after.
Had to make the other updates, so did this one also.
Sorry, but I don't understand the reason for this inclusion. What is the change in this PR that makes this necessary?
@ -1201,6 +1213,16 @@ int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx,return MBEDTLS_ERR_PK_BAD_INPUT_DATA;}Isn't
MBEDTLS_ERR_PK_BAD_INPUT_DATAbetter in this case?I know that calling
psa_reset_key_attributes()nowadays is no more mandatory, but since you are calling it ifPSA_KEY_TYPE_IS_ECC(type)orPSA_KEY_TYPE_IS_RSA(type), I noticed it wouldn't be called if you don't fall in one of the above mentioned conditions.IMO for sake of uniformity, it's better to call
psa_reset_key_attributes()at the end of the function anyway.My goal is either to call it in all possible code branches, or never call it.
@ -512,37 +512,49 @@ RSA hash_len overflow (size_t vs unsigned int)depends_on:PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY:MBEDTLS_HAVE_INT64IMO this test duplicates what's already tested from
EC_DH (no) sign-verify: SECP256R1. Isn't it?IMO this is a "duplication" of
PSA wrapped sign: RSA PKCS1 v1.5 (invalid RSA_PKCS1V15_CRYPT algorithm)andPSA wrapped sign: RSA PKCS1 v1.5 (invalid RSA_OAEP algorithm)which are right below this one. In both cases wrong algorithms are used for signature.@ -1160,25 +1160,34 @@ exit:}TEST_CALLOC()can be used for this purpose in tests.@ -1204,2 +1211,2 @@ret = mbedtls_pk_sign_restartable(&prv, md_alg, hash->x, hash->len,sig, sizeof(sig), &slen,if (pub_key_test) {ret = mbedtls_pk_sign_restartable(&pub, md_alg, hash->x, hash->len,I think this assignment is unnecessary as it's overridden below when calling
mbedtls_pk_sign_restartablembedtls_pk_xxx()functions do not return PSA error codes. It works becausePSA_SUCCESS = 0, but technically this is no right. Alsoretis ofinttype, notpsa_status_t@ -1245,3 +1261,4 @@sig, sig_length, &slen,&rs_ctx);TEST_ASSERT(ret == MBEDTLS_ERR_ECP_IN_PROGRESS);}@ -1612,0 +1635,4 @@if (no_sign_usage_test) {TEST_EQUAL(mbedtls_pk_sign_ext(key_pk_type, &pk, md_alg, hash, hash_len,sig, sizeof(sig), &sig_len), MBEDTLS_ERR_RSA_BAD_INPUT_DATA);goto exit;Technically here you are destroying the PSA key before freeing the context that wraps it. Here it doesn't create any problems because after this you jump to
exitlabel, but it's not ideal.I suggest moving call to
psa_destroy_key()aftermbedtls_pk_free()at theexitlabel.I expanded the test coverage table requested by @mpg in #515 and checked against what would be available in
test_suite_pk.datathe the top of this PR and I got the following:Non-wrapping context:
ECC
RSA 1.5
Wrapping context
RSA 1.5
RSA 2.1
ECC (ECDSA normal/deterministic)
Of course, I might have missed something, so I ask the 2nd reviewer to fix/integrate as necessary.
I forgot to add one general question on the implementation before submitting the previous review. Sorry
@ -1239,0 +1290,4 @@status = psa_sign_hash(ctx->priv_id, sig_alg,hash, hash_len, sig, sig_size, sig_len);return PSA_PK_RSA_TO_MBEDTLS_ERR(status);This comment is not related to this specific line, but to the entire block that follows. Why do we need to implement all this non-restartable code block in a function that ends with
_restartable()?IMO it would make more sense to have it all under
mbedtls_pk_sign()and then lettingmbedtls_pk_sign_restartable()to callmbedtls_pk_sign()when the operation is not restartable (for any reason), rather than the other way around as it is now.It's not blocking, but it would be cleaner to me.
This is left over from debug and has now been removed.
@ -1201,6 +1213,16 @@ int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx,return MBEDTLS_ERR_PK_BAD_INPUT_DATA;}Should now updated.
@ -1160,25 +1160,34 @@ exit:}Should now be updated.
@ -1204,2 +1211,2 @@ret = mbedtls_pk_sign_restartable(&prv, md_alg, hash->x, hash->len,sig, sizeof(sig), &slen,if (pub_key_test) {ret = mbedtls_pk_sign_restartable(&pub, md_alg, hash->x, hash->len,It should now be removed.
@ -1245,3 +1261,4 @@sig, sig_length, &slen,&rs_ctx);TEST_ASSERT(ret == MBEDTLS_ERR_ECP_IN_PROGRESS);}Should now be removed.
@ -1204,2 +1211,2 @@ret = mbedtls_pk_sign_restartable(&prv, md_alg, hash->x, hash->len,sig, sizeof(sig), &slen,if (pub_key_test) {ret = mbedtls_pk_sign_restartable(&pub, md_alg, hash->x, hash->len,Yes, I agree this is not technically correct. Although functionally it is currently and probably in the future the same. If I've understood correctly what you're after ret should be of type in, as this is I believe the standard in mbedtls? However the statement on line 1228 should be if (ret != 0), I've updated this. Hopefully this is what you are after, though let me know if you wanted something else.
@ -134,4 +123,1 @@sig, sig_size, sig_len);}static int rsa_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv)I was looking at issue https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/523 and it turned out that refactoring of
_extfunctions should happen there indeed, so please ignore my comment.OTOH this sets this PR and the companion one about verify functions as "prerequisite" for #523. It's not a strong prerequisite, but there is a high chance of huge conflicts.
@ -134,4 +123,1 @@sig, sig_size, sig_len);}static int rsa_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv)Ok, I'll ignore it then. In terms of the conflicts, assuming none of the changes are too controversial I am hoping to get the comments sorted soon and get it merged. For #521 I've barely started it yet, however it is next on the list. I've noticed you've taken on #523, so see how you get on and how bad the conflicts are. However if there are a lot maybe we delay it till after #521? I've had a quick look at it and a lot of the tests are similar, so hopefully it shouldn't take too long. It all depends on if there's anything else in the backlog and how important it is though?
So, I think the idea is that the function will never reach the end as it will have to be one of the cases. You're right though, for the sake of uniformity it's worth adding. So I've added it, let me know if this is what you are after?
@ -512,37 +512,49 @@ RSA hash_len overflow (size_t vs unsigned int)depends_on:PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY:MBEDTLS_HAVE_INT64Now removed.
Now removed.
@ -1612,0 +1635,4 @@if (no_sign_usage_test) {TEST_EQUAL(mbedtls_pk_sign_ext(key_pk_type, &pk, md_alg, hash, hash_len,sig, sizeof(sig), &sig_len), MBEDTLS_ERR_RSA_BAD_INPUT_DATA);goto exit;Now moved.
@valeriosetti, I can't reply to the comment on test cases. So I've added a response here:
Positive: check deterministic ECDSA against test vectors, I've discussed this with Gilles and we decided we only need to test 1 curve and the ECDSA, 256 Bits (Prime Field) is covered by existing tests:
here
github.com/bjwtaylor/TF-PSA-Crypto@5df23a947a/tests/suites/test_suite_pk.data (L521)Negative: trying to sign with a public key: this was covered by
github.com/bjwtaylor/TF-PSA-Crypto@f832f63ac8/tests/suites/test_suite_pk.data (L515)Negative: the output buffer is too small (ECC), covered by
github.com/bjwtaylor/TF-PSA-Crypto@f832f63ac8/tests/suites/test_suite_pk.data (L551)andgithub.com/bjwtaylor/TF-PSA-Crypto@f832f63ac8/tests/suites/test_suite_pk.data (L555)Negative: the key's usage bits don't allow signing (RSA 1.5)
github.com/bjwtaylor/TF-PSA-Crypto@f832f63ac8/tests/suites/test_suite_pk.data (L643)I'll add test cases for if we think they are necessary:
Negative: the output buffer is too small (RSA1.5/RSA2.1)
Negative: the key's usage bits don't allow signing (RSA 2.1)
Negative: the key's usage bits don't allow signing (ECC)
@ -1239,0 +1290,4 @@status = psa_sign_hash(ctx->priv_id, sig_alg,hash, hash_len, sig, sig_size, sig_len);return PSA_PK_RSA_TO_MBEDTLS_ERR(status);So this is probably a question for @mpg, as he implemented this code. I suspect there was a reason he did it this way?
@ -1239,0 +1290,4 @@status = psa_sign_hash(ctx->priv_id, sig_alg,hash, hash_len, sig, sig_size, sig_len);return PSA_PK_RSA_TO_MBEDTLS_ERR(status);Yes, I considered this. The point of keeping this inside the
restartablefunction was to avoid duplicating the first two paragraphs (parameters check and call topk_hashlen_helper()). However that's probably a weak justification for having a function that does two entirely different things.I can think of two approaches:
sign()andsign_restartable(), considering that's a small price to pay for readability. Thensign_restartable()callssign()in the non-restartable case.sign_internal(). Thensign()keeps callingsign_restartable()which does the checks/adjustments, then either goes the restartable path or callssign_internal(). (And in the future, the restartable path would be to callsign_restartable_internal()when we inline that part.)Wdyt? I agree we should take this opportunity to make the code clean and readable, and that the current status (single function implementing both restartable and non-restartable one after the other) is not what we want.
@ -134,4 +123,1 @@sig, sig_size, sig_len);}static int rsa_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv)So, as discussed in standup I think the current plan now is to drop the verify and split this into two. Test and implement. Let me know if there is any impact on what you are doing and maybe some coordination will be required.
@ -1239,0 +1290,4 @@status = psa_sign_hash(ctx->priv_id, sig_alg,hash, hash_len, sig, sig_size, sig_len);return PSA_PK_RSA_TO_MBEDTLS_ERR(status);So, to potentially add an option 3. We could rename the function and we could then keep restartable/non-restartable as is. I think if we start splitting it out we are going back towards the original position with the function pointers, which is not ideal either. If @mpg and @valeriosetti you have a strong preference for either, I'm happy to go with it though.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.