From 7cc4e816c16df362c0723694d1e2941d2166a70c Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 10 Jan 2023 17:14:11 +0000 Subject: [PATCH] Ensure max ops gets set regardless of having built-in implementation Set the psa level global anyway, regardless of having a built in implementation, to match the set function. Also, ensure that value returned is the same as value passed in, irregardless of internal implementation requirements. Signed-off-by: Paul Elliott --- library/psa_crypto.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index f7228bc4b5..efad510357 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -3419,6 +3419,8 @@ static uint32_t mbedtls_psa_interruptible_max_ops = void mbedtls_psa_interruptible_set_max_ops(uint32_t max_ops) { + mbedtls_psa_interruptible_max_ops = max_ops; + #if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \ defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \ defined(MBEDTLS_ECP_RESTARTABLE) @@ -3429,10 +3431,7 @@ void mbedtls_psa_interruptible_set_max_ops(uint32_t max_ops) max_ops = 1; } - mbedtls_psa_interruptible_max_ops = max_ops; mbedtls_ecp_set_max_ops(max_ops); -#else - (void) max_ops; #endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || * defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) && * defined( MBEDTLS_ECP_RESTARTABLE ) */ @@ -3497,8 +3496,9 @@ psa_status_t mbedtls_psa_sign_hash_start( #endif /* Ensure default is set even if - * mbedtls_psa_interruptible_get_max_ops() has not been called. */ - mbedtls_ecp_set_max_ops(mbedtls_psa_interruptible_get_max_ops()); + * mbedtls_psa_interruptible_set_max_ops() has not been called. */ + mbedtls_psa_interruptible_set_max_ops( + mbedtls_psa_interruptible_get_max_ops()); status = mbedtls_psa_ecp_load_representation(attributes->core.type, attributes->core.bits, @@ -3685,8 +3685,9 @@ psa_status_t mbedtls_psa_verify_hash_start( defined(MBEDTLS_ECP_RESTARTABLE) /* Ensure default is set even if - * mbedtls_psa_interruptible_get_max_ops() has not been called. */ - mbedtls_ecp_set_max_ops(mbedtls_psa_interruptible_get_max_ops()); + * mbedtls_psa_interruptible_set_max_ops() has not been called. */ + mbedtls_psa_interruptible_set_max_ops( + mbedtls_psa_interruptible_get_max_ops()); status = mbedtls_psa_ecp_load_representation(attributes->core.type, attributes->core.bits,