Skip to content

Conversation

@gaborgvarga
Copy link

@gaborgvarga gaborgvarga commented Jul 21, 2025

When using the PSA Crypto adapter layer, the signature buffer provided
to t_cose_crypto_sign() may be significantly larger than necessary for
the algorithm in use. Passing oversized buffers to psa_sign_hash()
can lead to performance inefficiencies and potential internal errors
in strict environments.

This change queries the expected signature size using
t_cose_crypto_sig_size() and checks it against the actual buffer
length before calling psa_sign_hash(). If the expected size exceeds
the available buffer, t_cose_crypto_sign() returns
with T_COSE_ERR_SIG_BUFFER_SIZE.

This improves robustness and avoids excessive memory usage
during signature generation.

@davidvincze
Copy link

davidvincze commented Jul 23, 2025

Hi @laurencelundblade,
May I ask you to review this small change in the PSA crypto adaptor layer? We try to rely on the upstream version and avoid using patch files in TF-M as much as possible.

I noticed that the v2.0-alpha-3 and v2.0-alpha-4 were tagged on the master branch and not on the dev. Can I ask how the Branch strategy has changed compared to what is written in the contribution guide?

I saw that COSE_Mac is now available on master. Is the dev branch now completely "replaced" by the master (or provides almost the same functionalities at the moment)? Should Gabor retarget his PR against the master branch in the hope that we can bump the t_cose version in TF-M from alpha-2 to v2.0-alpha-4+x in the future?

Thank you!

@laurencelundblade
Copy link
Owner

That v2.0-alpha-4 was from the master branch was a big mistake on my part. I've remade the release from dev.

When using the PSA Crypto adapter layer, the signature buffer provided
to `t_cose_crypto_sign()` may be significantly larger than necessary for
the algorithm in use. Passing oversized buffers to `psa_sign_hash()`
can lead to performance inefficiencies and potential internal errors
in strict environments.

This change queries the expected signature size using
`t_cose_crypto_sig_size()` and checks it against the actual buffer
length before calling `psa_sign_hash()`. If the expected size exceeds
the available buffer, t_cose_crypto_sign() returns
with T_COSE_ERR_SIG_BUFFER_SIZE.

This improves robustness and avoids excessive memory usage
during signature generation.

Signed-off-by: G. Varga, Gabor <[email protected]>
Change-Id: I1f0bda9afe0856a1f5f4571459c270aa8b106cfc
@gaborgvarga
Copy link
Author

Hi @laurencelundblade,

I’ve updated the pull request based on our discussion.
When you have a moment, please take a look and let me know if you’re satisfied with the changes. Thanks for your feedback!

Best,
Gabor

@laurencelundblade laurencelundblade merged commit cf3818f into laurencelundblade:dev Aug 1, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants