psa: Prepare sign/verify code for software implementation split

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2021-02-17 10:33:32 +01:00
parent 010d7c72c3
commit 99b8ed7fda

View file

@ -3384,16 +3384,23 @@ psa_status_t psa_sign_hash( mbedtls_svc_key_id_t key,
psa_key_lifetime_is_external( slot->attr.lifetime ) ) psa_key_lifetime_is_external( slot->attr.lifetime ) )
goto exit; goto exit;
psa_key_attributes_t attributes_struct = {
.core = slot->attr
};
psa_key_attributes_t *attributes = &attributes_struct;
const uint8_t *key_buffer = slot->key.data;
size_t key_buffer_size = slot->key.bytes;
/* If the operation was not supported by any accelerator, try fallback. */ /* If the operation was not supported by any accelerator, try fallback. */
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \ #if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
if( slot->attr.type == PSA_KEY_TYPE_RSA_KEY_PAIR ) if( attributes->core.type == PSA_KEY_TYPE_RSA_KEY_PAIR )
{ {
mbedtls_rsa_context *rsa = NULL; mbedtls_rsa_context *rsa = NULL;
status = mbedtls_psa_rsa_load_representation( slot->attr.type, status = mbedtls_psa_rsa_load_representation( attributes->core.type,
slot->key.data, key_buffer,
slot->key.bytes, key_buffer_size,
&rsa ); &rsa );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
goto exit; goto exit;
@ -3410,7 +3417,7 @@ psa_status_t psa_sign_hash( mbedtls_svc_key_id_t key,
else else
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || #endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) ||
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) */ * defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) */
if( PSA_KEY_TYPE_IS_ECC( slot->attr.type ) ) if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
{ {
#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)
@ -3423,10 +3430,10 @@ psa_status_t psa_sign_hash( mbedtls_svc_key_id_t key,
) )
{ {
mbedtls_ecp_keypair *ecp = NULL; mbedtls_ecp_keypair *ecp = NULL;
status = mbedtls_psa_ecp_load_representation( slot->attr.type, status = mbedtls_psa_ecp_load_representation( attributes->core.type,
slot->attr.bits, attributes->core.bits,
slot->key.data, key_buffer,
slot->key.bytes, key_buffer_size,
&ecp ); &ecp );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
goto exit; goto exit;
@ -3496,15 +3503,22 @@ psa_status_t psa_verify_hash( mbedtls_svc_key_id_t key,
psa_key_lifetime_is_external( slot->attr.lifetime ) ) psa_key_lifetime_is_external( slot->attr.lifetime ) )
goto exit; goto exit;
psa_key_attributes_t attributes_struct = {
.core = slot->attr
};
psa_key_attributes_t *attributes = &attributes_struct;
const uint8_t *key_buffer = slot->key.data;
size_t key_buffer_size = slot->key.bytes;
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \ #if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
if( PSA_KEY_TYPE_IS_RSA( slot->attr.type ) ) if( PSA_KEY_TYPE_IS_RSA( attributes->core.type ) )
{ {
mbedtls_rsa_context *rsa = NULL; mbedtls_rsa_context *rsa = NULL;
status = mbedtls_psa_rsa_load_representation( slot->attr.type, status = mbedtls_psa_rsa_load_representation( attributes->core.type,
slot->key.data, key_buffer,
slot->key.bytes, key_buffer_size,
&rsa ); &rsa );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
goto exit; goto exit;
@ -3520,17 +3534,17 @@ psa_status_t psa_verify_hash( mbedtls_svc_key_id_t key,
else else
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || #endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) ||
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) */ * defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) */
if( PSA_KEY_TYPE_IS_ECC( slot->attr.type ) ) if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
{ {
#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)
if( PSA_ALG_IS_ECDSA( alg ) ) if( PSA_ALG_IS_ECDSA( alg ) )
{ {
mbedtls_ecp_keypair *ecp = NULL; mbedtls_ecp_keypair *ecp = NULL;
status = mbedtls_psa_ecp_load_representation( slot->attr.type, status = mbedtls_psa_ecp_load_representation( attributes->core.type,
slot->attr.bits, attributes->core.bits,
slot->key.data, key_buffer,
slot->key.bytes, key_buffer_size,
&ecp ); &ecp );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
goto exit; goto exit;