Sort out MD dependencies in RSA tests

When MD is only used to compute a size, use md_internal.h instead.

When it's actually used to compute a hash, mark the test function as
depending on it. This is probably suboptimal in the long run, and we
might want to either adapt the code so that it can use PSA Crypto
instead, or just pre-compute the hash in the test data.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
Manuel Pégourié-Gonnard 2022-07-05 13:11:13 +02:00
parent 3f4778995e
commit e496c6273e
3 changed files with 8 additions and 9 deletions

View file

@ -475,7 +475,7 @@ void mbedtls_pk_check_pair( char * pub_file, char * prv_file, int ret )
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */ /* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_MD_C */
void pk_rsa_verify_test_vec( data_t * message_str, int digest, int mod, void pk_rsa_verify_test_vec( data_t * message_str, int digest, int mod,
int radix_N, char * input_N, int radix_E, int radix_N, char * input_N, int radix_E,
char * input_E, data_t * result_str, char * input_E, data_t * result_str,
@ -526,7 +526,7 @@ exit:
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_RSA_C */ /* BEGIN_CASE depends_on:MBEDTLS_RSA_C:MBEDTLS_MD_C */
void pk_rsa_verify_ext_test_vec( data_t * message_str, int digest, void pk_rsa_verify_ext_test_vec( data_t * message_str, int digest,
int mod, int radix_N, char * input_N, int mod, int radix_N, char * input_N,
int radix_E, char * input_E, int radix_E, char * input_E,
@ -1365,7 +1365,6 @@ void pk_psa_wrap_sign_ext( int pk_type, int parameter, int key_pk_type, int md_a
psa_algorithm_t psa_md_alg = mbedtls_psa_translate_md( md_alg ); psa_algorithm_t psa_md_alg = mbedtls_psa_translate_md( md_alg );
psa_algorithm_t psa_alg; psa_algorithm_t psa_alg;
size_t hash_len = PSA_HASH_LENGTH( psa_md_alg ); size_t hash_len = PSA_HASH_LENGTH( psa_md_alg );
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( md_alg );
void const *options = NULL; void const *options = NULL;
mbedtls_pk_rsassa_pss_options rsassa_pss_options; mbedtls_pk_rsassa_pss_options rsassa_pss_options;
int ret; int ret;
@ -1417,8 +1416,8 @@ void pk_psa_wrap_sign_ext( int pk_type, int parameter, int key_pk_type, int md_a
if( key_pk_type == MBEDTLS_PK_RSASSA_PSS ) if( key_pk_type == MBEDTLS_PK_RSASSA_PSS )
{ {
rsassa_pss_options.mgf1_hash_id = md_alg; rsassa_pss_options.mgf1_hash_id = md_alg;
TEST_ASSERT( md_info != NULL ); TEST_ASSERT( hash_len != 0 );
rsassa_pss_options.expected_salt_len = mbedtls_md_get_size( md_info ); rsassa_pss_options.expected_salt_len = hash_len;
options = (const void*) &rsassa_pss_options; options = (const void*) &rsassa_pss_options;
} }
TEST_EQUAL( mbedtls_pk_verify_ext( key_pk_type, options, &pk, md_alg, TEST_EQUAL( mbedtls_pk_verify_ext( key_pk_type, options, &pk, md_alg,

View file

@ -261,7 +261,7 @@ exit:
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_MD_C */
void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q, void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q,
char * input_Q, int radix_N, char * input_N, char * input_Q, int radix_N, char * input_N,
int radix_E, char * input_E, int digest, int hash, int radix_E, char * input_E, int digest, int hash,
@ -320,7 +320,7 @@ exit:
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_MD_C */
void pkcs1_rsassa_v15_verify( int mod, int radix_N, char * input_N, void pkcs1_rsassa_v15_verify( int mod, int radix_N, char * input_N,
int radix_E, char * input_E, int digest, int radix_E, char * input_E, int digest,
int hash, data_t * message_str, char * salt, int hash, data_t * message_str, char * salt,

View file

@ -76,7 +76,7 @@ void rsa_init_free( int reinit )
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_MD_C */
void mbedtls_rsa_pkcs1_sign( data_t * message_str, int padding_mode, void mbedtls_rsa_pkcs1_sign( data_t * message_str, int padding_mode,
int digest, int mod, int radix_P, char * input_P, int digest, int mod, int radix_P, char * input_P,
int radix_Q, char * input_Q, int radix_N, int radix_Q, char * input_Q, int radix_N,
@ -131,7 +131,7 @@ exit:
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_MD_C */
void mbedtls_rsa_pkcs1_verify( data_t * message_str, int padding_mode, void mbedtls_rsa_pkcs1_verify( data_t * message_str, int padding_mode,
int digest, int mod, int radix_N, int digest, int mod, int radix_N,
char * input_N, int radix_E, char * input_E, char * input_N, int radix_E, char * input_E,