tests: psa driver: Align RSA/ECP sign/verify hash dispatch

Align RSA/ECP sign/verify hash dispatch with the
corresponding code of the library. The library
code was modified recently but not the test code
one and these modifications ease the following work.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2021-04-09 15:32:03 +02:00
parent a2dbe66770
commit 4bcccc6956
2 changed files with 70 additions and 70 deletions

View file

@ -2948,8 +2948,7 @@ psa_status_t psa_sign_hash_builtin(
return( PSA_ERROR_INVALID_ARGUMENT ); return( PSA_ERROR_INVALID_ARGUMENT );
} }
} }
else else if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
{ {
if( PSA_ALG_IS_ECDSA( alg ) ) if( PSA_ALG_IS_ECDSA( alg ) )
{ {
@ -3019,8 +3018,7 @@ psa_status_t psa_verify_hash_builtin(
return( PSA_ERROR_INVALID_ARGUMENT ); return( PSA_ERROR_INVALID_ARGUMENT );
} }
} }
else else if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
{ {
if( PSA_ALG_IS_ECDSA( alg ) ) if( PSA_ALG_IS_ECDSA( alg ) )
{ {

View file

@ -58,58 +58,56 @@ psa_status_t sign_hash(
size_t signature_size, size_t signature_size,
size_t *signature_length ) size_t *signature_length )
{ {
#if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || \
defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS)
if( attributes->core.type == PSA_KEY_TYPE_RSA_KEY_PAIR ) if( attributes->core.type == PSA_KEY_TYPE_RSA_KEY_PAIR )
{ {
return( mbedtls_transparent_test_driver_rsa_sign_hash( if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) ||
attributes, PSA_ALG_IS_RSA_PSS( alg) )
key_buffer, key_buffer_size,
alg, hash, hash_length,
signature, signature_size, signature_length ) );
}
else
#endif /* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) ||
* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) */
#if defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) || \
defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA)
if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
{
if(
#if defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA)
PSA_ALG_IS_ECDSA( alg )
#else
PSA_ALG_IS_RANDOMIZED_ECDSA( alg )
#endif
)
{ {
return( mbedtls_transparent_test_driver_ecdsa_sign_hash( #if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || \
defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS)
return( mbedtls_transparent_test_driver_rsa_sign_hash(
attributes, attributes,
key_buffer, key_buffer_size, key_buffer, key_buffer_size,
alg, hash, hash_length, alg, hash, hash_length,
signature, signature_size, signature_length ) ); signature, signature_size, signature_length ) );
#endif /* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) ||
* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) */
} }
else else
{ {
return( PSA_ERROR_INVALID_ARGUMENT ); return( PSA_ERROR_INVALID_ARGUMENT );
} }
} }
else else if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
{
if( PSA_ALG_IS_ECDSA( alg ) )
{
#if defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) || \
defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA)
return( mbedtls_transparent_test_driver_ecdsa_sign_hash(
attributes,
key_buffer, key_buffer_size,
alg, hash, hash_length,
signature, signature_size, signature_length ) );
#endif /* defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) || #endif /* defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) ||
* defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA) */ * defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA) */
{ }
(void)attributes; else
(void)key_buffer; {
(void)key_buffer_size; return( PSA_ERROR_INVALID_ARGUMENT );
(void)alg; }
(void)hash;
(void)hash_length;
(void)signature;
(void)signature_size;
(void)signature_length;
return( PSA_ERROR_NOT_SUPPORTED );
} }
(void)attributes;
(void)key_buffer;
(void)key_buffer_size;
(void)alg;
(void)hash;
(void)hash_length;
(void)signature;
(void)signature_size;
(void)signature_length;
return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t verify_hash( psa_status_t verify_hash(
@ -122,52 +120,56 @@ psa_status_t verify_hash(
const uint8_t *signature, const uint8_t *signature,
size_t signature_length ) size_t signature_length )
{ {
#if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || \
defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS)
if( PSA_KEY_TYPE_IS_RSA( attributes->core.type ) ) if( PSA_KEY_TYPE_IS_RSA( attributes->core.type ) )
{ {
return( mbedtls_transparent_test_driver_rsa_verify_hash( if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) ||
attributes, PSA_ALG_IS_RSA_PSS( alg) )
key_buffer, key_buffer_size,
alg, hash, hash_length,
signature, signature_length ) );
}
else
#endif /* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) ||
* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) */
#if defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) || \
defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA)
if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
{
if( PSA_ALG_IS_ECDSA( alg ) )
{ {
return( mbedtls_transparent_test_driver_ecdsa_verify_hash( #if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || \
defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS)
return( mbedtls_transparent_test_driver_rsa_verify_hash(
attributes, attributes,
key_buffer, key_buffer_size, key_buffer, key_buffer_size,
alg, hash, hash_length, alg, hash, hash_length,
signature, signature_length ) ); signature, signature_length ) );
#endif /* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) ||
* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) */
} }
else else
{ {
return( PSA_ERROR_INVALID_ARGUMENT ); return( PSA_ERROR_INVALID_ARGUMENT );
} }
} }
else else if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
{
if( PSA_ALG_IS_ECDSA( alg ) )
{
#if defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) || \
defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA)
return( mbedtls_transparent_test_driver_ecdsa_verify_hash(
attributes,
key_buffer, key_buffer_size,
alg, hash, hash_length,
signature, signature_length ) );
#endif /* defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) || #endif /* defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) ||
* defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA) */ * defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA) */
{ }
(void)attributes; else
(void)key_buffer; {
(void)key_buffer_size; return( PSA_ERROR_INVALID_ARGUMENT );
(void)alg; }
(void)hash;
(void)hash_length;
(void)signature;
(void)signature_length;
return( PSA_ERROR_NOT_SUPPORTED );
} }
(void)attributes;
(void)key_buffer;
(void)key_buffer_size;
(void)alg;
(void)hash;
(void)hash_length;
(void)signature;
(void)signature_length;
return( PSA_ERROR_NOT_SUPPORTED );
} }
psa_status_t mbedtls_test_transparent_signature_sign_message( psa_status_t mbedtls_test_transparent_signature_sign_message(