From 6e1e3ca37cddf5928f61e30d312ef35be7ac9e16 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Wed, 13 Nov 2024 15:28:51 +0000 Subject: [PATCH] Add PSA interruptible key generation get num ops API Signed-off-by: Waleed Elmelegy --- tf-psa-crypto/core/psa_crypto.c | 5 +++-- tf-psa-crypto/core/psa_crypto_core.h | 17 +++++++++++++++++ .../drivers/builtin/src/psa_crypto_ecp.c | 6 ++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tf-psa-crypto/core/psa_crypto.c b/tf-psa-crypto/core/psa_crypto.c index 30dd8292dc5f..2c1f6d7d5b96 100644 --- a/tf-psa-crypto/core/psa_crypto.c +++ b/tf-psa-crypto/core/psa_crypto.c @@ -8121,8 +8121,7 @@ static psa_status_t psa_generate_key_iop_abort_internal( uint32_t psa_generate_key_iop_get_num_ops( psa_generate_key_iop_t *operation) { - (void) operation; - return 0; + return operation->num_ops; } psa_status_t psa_generate_key_iop_setup( @@ -8197,6 +8196,8 @@ psa_status_t psa_generate_key_iop_complete( goto exit; } + operation->num_ops = mbedtls_psa_generate_key_get_num_ops(&operation->ctx); + status = psa_import_key(&operation->attributes, key_data + (sizeof(key_data) - key_len), key_len, diff --git a/tf-psa-crypto/core/psa_crypto_core.h b/tf-psa-crypto/core/psa_crypto_core.h index 14c74dc01778..62d0ab9e36c0 100644 --- a/tf-psa-crypto/core/psa_crypto_core.h +++ b/tf-psa-crypto/core/psa_crypto_core.h @@ -435,6 +435,23 @@ psa_status_t psa_generate_key_internal(const psa_key_attributes_t *attributes, size_t key_buffer_size, size_t *key_buffer_length); + +/** + * \brief Get the total number of ops that a key generation operation has taken + * Since it's start. + * + * \note The signature of this function is that of a PSA driver + * generate_key_get_num_ops entry point. This function behaves as an + * generate_key_get_num_ops entry point as defined in the PSA driver + * interface specification for transparent drivers. + * + * \param[in] operation The \c mbedtls_psa_generate_key_iop_t to use. + * This must be initialized first. + * \return Total number of operations. + */ +uint32_t mbedtls_psa_generate_key_get_num_ops( + mbedtls_psa_generate_key_iop_t *operation); + /** * \brief Setup a new interruptible key generation operation. * 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 4500196ef0bb..44edbe385a6a 100644 --- a/tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.c +++ b/tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.c @@ -596,6 +596,12 @@ psa_status_t mbedtls_psa_key_agreement_ecdh( #if defined(MBEDTLS_ECP_RESTARTABLE) +uint32_t mbedtls_psa_generate_key_get_num_ops( + mbedtls_psa_generate_key_iop_t *operation) +{ + return operation->num_ops; +} + psa_status_t mbedtls_psa_generate_key_iop_setup( mbedtls_psa_generate_key_iop_t *operation, const psa_key_attributes_t *attributes)