pk_wrap: test if a valid md_alg is passed to ecdsa_verify_wrap

Adjust tests to pass a valid algorithm
This commit is contained in:
Andrzej Kurek 2018-11-08 05:04:53 -05:00
parent 2f69b1a059
commit 510ee70501
2 changed files with 7 additions and 2 deletions

View File

@ -677,12 +677,16 @@ static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
unsigned char buf[buf_len];
unsigned char *p = (unsigned char*) sig;
mbedtls_pk_info_t pk_info = mbedtls_eckey_info;
psa_algorithm_t psa_sig_md = PSA_ALG_ECDSA( translate_md_to_psa( md_alg ) );
psa_algorithm_t psa_sig_md = translate_md_to_psa( md_alg );
psa_ecc_curve_t curve = mbedtls_ecc_group_to_psa ( ( (mbedtls_ecdsa_context *) ctx )->grp.id );
if( curve == 0 )
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
if( psa_sig_md == 0 )
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
psa_sig_md = PSA_ALG_ECDSA( psa_sig_md );
memset( &signature, 0, sizeof( mbedtls_asn1_buf ) );
key.pk_info = &pk_info;
key.pk_ctx = ctx;

View File

@ -246,7 +246,8 @@ void pk_ec_test_vec( int type, int id, data_t * key, data_t * hash,
TEST_ASSERT( mbedtls_ecp_point_read_binary( &eckey->grp, &eckey->Q,
key->x, key->len ) == 0 );
TEST_ASSERT( mbedtls_pk_verify( &pk, MBEDTLS_MD_NONE,
// MBEDTLS_MD_SHA1 is a dummy - it is ignored, but has to be other than MBEDTLS_MD_NONE.
TEST_ASSERT( mbedtls_pk_verify( &pk, MBEDTLS_MD_SHA1,
hash->x, hash->len, sig->x, sig->len ) == ret );
exit: