Merge pull request #7147 from paul-elliott-arm/interruptible_sign_hash_codestyle_drivers

Remove driver entry points for psa_{get|set}_max_ops()
This commit is contained in:
Gilles Peskine 2023-03-01 10:46:09 +01:00 committed by GitHub
commit 802ff1b116
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 44 deletions

View file

@ -4217,6 +4217,9 @@ uint32_t psa_interruptible_get_max_ops(void);
* \c psa_sign_hash_interruptible_abort() on * \c psa_sign_hash_interruptible_abort() on
* the operation, a value of 0 will be returned. * the operation, a value of 0 will be returned.
* *
* \note This interface is guaranteed re-entrant and
* thus may be called from driver code.
*
* \warning This is a beta API, and thus subject to change * \warning This is a beta API, and thus subject to change
* at any point. It is not bound by the usual * at any point. It is not bound by the usual
* interface stability promises. * interface stability promises.

View file

@ -3156,17 +3156,18 @@ exit:
/* Asymmetric interruptible cryptography */ /* Asymmetric interruptible cryptography */
/****************************************************************/ /****************************************************************/
static uint32_t psa_interruptible_max_ops = PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED;
void psa_interruptible_set_max_ops(uint32_t max_ops) void psa_interruptible_set_max_ops(uint32_t max_ops)
{ {
psa_driver_wrapper_interruptible_set_max_ops(max_ops); psa_interruptible_max_ops = max_ops;
} }
uint32_t psa_interruptible_get_max_ops(void) uint32_t psa_interruptible_get_max_ops(void)
{ {
return psa_driver_wrapper_interruptible_get_max_ops(); return psa_interruptible_max_ops;
} }
uint32_t psa_sign_hash_get_num_ops( uint32_t psa_sign_hash_get_num_ops(
const psa_sign_hash_interruptible_operation_t *operation) const psa_sign_hash_interruptible_operation_t *operation)
{ {
@ -3461,12 +3462,8 @@ psa_status_t psa_verify_hash_abort(
/* implementations */ /* implementations */
/****************************************************************/ /****************************************************************/
static uint32_t mbedtls_psa_interruptible_max_ops =
PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED;
void mbedtls_psa_interruptible_set_max_ops(uint32_t 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) || \ #if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \ defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \
@ -3479,16 +3476,13 @@ void mbedtls_psa_interruptible_set_max_ops(uint32_t max_ops)
} }
mbedtls_ecp_set_max_ops(max_ops); mbedtls_ecp_set_max_ops(max_ops);
#else
(void) max_ops;
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || #endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||
* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) && * defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) &&
* defined( MBEDTLS_ECP_RESTARTABLE ) */ * defined( MBEDTLS_ECP_RESTARTABLE ) */
} }
uint32_t mbedtls_psa_interruptible_get_max_ops(void)
{
return mbedtls_psa_interruptible_max_ops;
}
uint32_t mbedtls_psa_sign_hash_get_num_ops( uint32_t mbedtls_psa_sign_hash_get_num_ops(
const mbedtls_psa_sign_hash_interruptible_operation_t *operation) const mbedtls_psa_sign_hash_interruptible_operation_t *operation)
{ {
@ -3547,11 +3541,6 @@ psa_status_t mbedtls_psa_sign_hash_start(
/* Ensure num_ops is zero'ed in case of context re-use. */ /* Ensure num_ops is zero'ed in case of context re-use. */
operation->num_ops = 0; operation->num_ops = 0;
/* Ensure default is set even if
* 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, status = mbedtls_psa_ecp_load_representation(attributes->core.type,
attributes->core.bits, attributes->core.bits,
key_buffer, key_buffer,
@ -3616,6 +3605,9 @@ psa_status_t mbedtls_psa_sign_hash_complete(
mbedtls_mpi_init(&r); mbedtls_mpi_init(&r);
mbedtls_mpi_init(&s); mbedtls_mpi_init(&s);
/* Ensure max_ops is set to the current value (or default). */
mbedtls_psa_interruptible_set_max_ops(psa_interruptible_get_max_ops());
if (signature_size < 2 * operation->coordinate_bytes) { if (signature_size < 2 * operation->coordinate_bytes) {
status = PSA_ERROR_BUFFER_TOO_SMALL; status = PSA_ERROR_BUFFER_TOO_SMALL;
goto exit; goto exit;
@ -3767,11 +3759,6 @@ psa_status_t mbedtls_psa_verify_hash_start(
/* Ensure num_ops is zero'ed in case of context re-use. */ /* Ensure num_ops is zero'ed in case of context re-use. */
operation->num_ops = 0; operation->num_ops = 0;
/* Ensure default is set even if
* 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, status = mbedtls_psa_ecp_load_representation(attributes->core.type,
attributes->core.bits, attributes->core.bits,
key_buffer, key_buffer,
@ -3856,6 +3843,9 @@ psa_status_t mbedtls_psa_verify_hash_complete(
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
/* Ensure max_ops is set to the current value (or default). */
mbedtls_psa_interruptible_set_max_ops(psa_interruptible_get_max_ops());
status = mbedtls_to_psa_error( status = mbedtls_to_psa_error(
mbedtls_ecdsa_verify_restartable(&operation->ctx->grp, mbedtls_ecdsa_verify_restartable(&operation->ctx->grp,
operation->hash, operation->hash,

View file

@ -70,10 +70,6 @@ psa_status_t psa_driver_wrapper_verify_hash(
* Interruptible Signature functions * Interruptible Signature functions
*/ */
void psa_driver_wrapper_interruptible_set_max_ops(uint32_t max_ops);
uint32_t psa_driver_wrapper_interruptible_get_max_ops(void);
uint32_t psa_driver_wrapper_sign_hash_get_num_ops( uint32_t psa_driver_wrapper_sign_hash_get_num_ops(
psa_sign_hash_interruptible_operation_t *operation); psa_sign_hash_interruptible_operation_t *operation);

View file

@ -433,24 +433,6 @@ psa_status_t psa_driver_wrapper_verify_hash(
} }
} }
void psa_driver_wrapper_interruptible_set_max_ops( uint32_t max_ops )
{
/* TODO - dispatch to drivers dynamically registered for this
* service when registering is implemented. For now, fall
* through to internal implementation. */
mbedtls_psa_interruptible_set_max_ops( max_ops );
}
uint32_t psa_driver_wrapper_interruptible_get_max_ops( void )
{
/* TODO - dispatch to drivers dynamically registered for this
* service when registering is implemented. For now, fall
* through to internal implementation. */
return mbedtls_psa_interruptible_get_max_ops( );
}
uint32_t psa_driver_wrapper_sign_hash_get_num_ops( uint32_t psa_driver_wrapper_sign_hash_get_num_ops(
psa_sign_hash_interruptible_operation_t *operation ) psa_sign_hash_interruptible_operation_t *operation )
{ {