test_suite_pk: properly size buffers for public keys in pk_psa_sign()

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2024-03-19 19:35:37 +01:00
parent aa9cc49879
commit f71c060cb2

View File

@ -1822,8 +1822,13 @@ void pk_psa_sign(int psa_type, int bits, int rsa_padding)
mbedtls_pk_context pk;
unsigned char hash[32];
unsigned char sig[MBEDTLS_PK_SIGNATURE_MAX_SIZE];
unsigned char legacy_pub_key[PSA_EXPORT_PUBLIC_KEY_MAX_SIZE];
unsigned char opaque_pub_key[PSA_EXPORT_PUBLIC_KEY_MAX_SIZE];
/* These buffers will be used to contain the key in DER format. Unfortunately
* when only EC is supported on the PSA side (i.e. no RSA or DH)
* PSA_EXPORT_PUBLIC_KEY_MAX_SIZE falls to PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(),
* but this is not enough to contain the DER representation of the public key.
* Therefore we pick the RSA size to be safe. */
unsigned char legacy_pub_key[RSA_WRITE_PUBKEY_MAX_SIZE];
unsigned char opaque_pub_key[RSA_WRITE_PUBKEY_MAX_SIZE];
size_t sig_len, legacy_pub_key_len, opaque_pub_key_len;
int ret;
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;