From 7164dc52cec7eb489aaf1b7dba269d4bea486d02 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 11 Oct 2024 14:50:34 +0100 Subject: [PATCH] Fix intermittent test failure Ecp key data length should not be measured by mbedtls_mpi_size(), as this does not count leading zeros, which are still part of the key. This resulted intermittently in the code attempting to import a wrongly sized key as the first byte was all zero. Signed-off-by: Paul Elliott --- tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.c b/tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.c index 498072a299..57131d3413 100644 --- a/tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.c +++ b/tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.c @@ -634,7 +634,7 @@ psa_status_t mbedtls_psa_generate_key_complete( operation->num_ops = 1; - *key_len = mbedtls_mpi_size(&operation->ecp.d); + *key_len = operation->ecp.d.n * sizeof(mbedtls_mpi_uint); if (*key_len > key_output_size) { return PSA_ERROR_BUFFER_TOO_SMALL; }