Fix the Changelog and extend tests to cover the hash of all-bits zero

Signed-off-by: TRodziewicz <tomasz.rodziewicz@mobica.com>
This commit is contained in:
TRodziewicz 2021-04-06 19:55:17 +02:00
parent 782a7eab14
commit 5feb6702dd
2 changed files with 78 additions and 50 deletions

View File

@ -1,4 +1,4 @@
Bugfix
* Fix a bug in ECDSA that would cause it to fail when the payload is all-bits
* Fix a bug in ECDSA that would cause it to fail when the hash is all-bits
zero.
Fixes #1792

View File

@ -212,6 +212,7 @@ void ecdsa_prim_random( int id )
mbedtls_mpi d, r, s;
mbedtls_test_rnd_pseudo_info rnd_info;
unsigned char buf[MBEDTLS_MD_MAX_SIZE];
int test_runs = 2;
mbedtls_ecp_group_init( &grp );
mbedtls_ecp_point_init( &Q );
@ -219,9 +220,20 @@ void ecdsa_prim_random( int id )
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
memset( buf, 0, sizeof( buf ) );
while ( test_runs-- )
{
/* prepare material for signature */
if ( test_runs == 1 )
{
TEST_ASSERT( mbedtls_test_rnd_pseudo_rand( &rnd_info,
buf, sizeof( buf ) ) == 0 );
buf, sizeof( buf ) )
== 0 );
} else {
TEST_ASSERT( mbedtls_test_rnd_zero_rand( NULL,
buf, sizeof( buf ) )
== 0 );
}
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
TEST_ASSERT( mbedtls_ecp_gen_keypair( &grp, &d, &Q,
&mbedtls_test_rnd_pseudo_rand,
@ -230,7 +242,9 @@ void ecdsa_prim_random( int id )
TEST_ASSERT( mbedtls_ecdsa_sign( &grp, &r, &s, &d, buf, sizeof( buf ),
&mbedtls_test_rnd_pseudo_rand,
&rnd_info ) == 0 );
TEST_ASSERT( mbedtls_ecdsa_verify( &grp, buf, sizeof( buf ), &Q, &r, &s ) == 0 );
TEST_ASSERT( mbedtls_ecdsa_verify( &grp, buf, sizeof( buf ), &Q, &r, &s )
== 0 );
}
exit:
mbedtls_ecp_group_free( &grp );
@ -354,15 +368,27 @@ void ecdsa_write_read_random( int id )
unsigned char hash[32];
unsigned char sig[200];
size_t sig_len, i;
int test_runs = 2;
mbedtls_ecdsa_init( &ctx );
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
memset( hash, 0, sizeof( hash ) );
while ( test_runs-- )
{
memset( sig, 0x2a, sizeof( sig ) );
/* prepare material for signature */
if ( test_runs == 1 )
{
TEST_ASSERT( mbedtls_test_rnd_pseudo_rand( &rnd_info,
hash, sizeof( hash ) ) == 0 );
hash, sizeof( hash ) )
== 0 );
} else {
TEST_ASSERT( mbedtls_test_rnd_zero_rand( NULL,
hash, sizeof( hash ) )
== 0 );
}
/* generate signing key */
TEST_ASSERT( mbedtls_ecdsa_genkey( &ctx, id,
@ -374,6 +400,7 @@ void ecdsa_write_read_random( int id )
hash, sizeof( hash ),
sig, &sig_len, &mbedtls_test_rnd_pseudo_rand,
&rnd_info ) == 0 );
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
sig, sig_len ) == 0 );
@ -404,6 +431,7 @@ void ecdsa_write_read_random( int id )
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
sig, sig_len ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
sig[sig_len - 1]--;
}
exit:
mbedtls_ecdsa_free( &ctx );