Fix Changelog, add separate test functions for hash of all-zero bits
Signed-off-by: TRodziewicz <tomasz.rodziewicz@mobica.com>
This commit is contained in:
parent
20ad475cc2
commit
40de3c99c0
@ -1,4 +1,3 @@
|
||||
Bugfix
|
||||
* Fix a bug in ECDSA that would cause it to fail when the hash is all-bits
|
||||
zero.
|
||||
Fixes #1792
|
||||
zero. Fixes #1792
|
||||
|
@ -1,6 +1,26 @@
|
||||
ECDSA Parameter validation
|
||||
ecdsa_invalid_param:
|
||||
|
||||
ECDSA primitive random #1
|
||||
depends_on:MBEDTLS_ECP_DP_SECP192R1_ENABLED
|
||||
ecdsa_prim_zero:MBEDTLS_ECP_DP_SECP192R1
|
||||
|
||||
ECDSA primitive random #2
|
||||
depends_on:MBEDTLS_ECP_DP_SECP224R1_ENABLED
|
||||
ecdsa_prim_zero:MBEDTLS_ECP_DP_SECP224R1
|
||||
|
||||
ECDSA primitive random #3
|
||||
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
ecdsa_prim_zero:MBEDTLS_ECP_DP_SECP256R1
|
||||
|
||||
ECDSA primitive random #4
|
||||
depends_on:MBEDTLS_ECP_DP_SECP384R1_ENABLED
|
||||
ecdsa_prim_zero:MBEDTLS_ECP_DP_SECP384R1
|
||||
|
||||
ECDSA primitive random #5
|
||||
depends_on:MBEDTLS_ECP_DP_SECP521R1_ENABLED
|
||||
ecdsa_prim_zero:MBEDTLS_ECP_DP_SECP521R1
|
||||
|
||||
ECDSA primitive random #1
|
||||
depends_on:MBEDTLS_ECP_DP_SECP192R1_ENABLED
|
||||
ecdsa_prim_random:MBEDTLS_ECP_DP_SECP192R1
|
||||
@ -33,6 +53,26 @@ ECDSA primitive rfc 4754 p521
|
||||
depends_on:MBEDTLS_ECP_DP_SECP521R1_ENABLED
|
||||
ecdsa_prim_test_vectors:MBEDTLS_ECP_DP_SECP521R1:"0065FDA3409451DCAB0A0EAD45495112A3D813C17BFD34BDF8C1209D7DF5849120597779060A7FF9D704ADF78B570FFAD6F062E95C7E0C5D5481C5B153B48B375FA1":"0151518F1AF0F563517EDD5485190DF95A4BF57B5CBA4CF2A9A3F6474725A35F7AFE0A6DDEB8BEDBCD6A197E592D40188901CECD650699C9B5E456AEA5ADD19052A8":"006F3B142EA1BFFF7E2837AD44C9E4FF6D2D34C73184BBAD90026DD5E6E85317D9DF45CAD7803C6C20035B2F3FF63AFF4E1BA64D1C077577DA3F4286C58F0AEAE643":"00C1C2B305419F5A41344D7E4359933D734096F556197A9B244342B8B62F46F9373778F9DE6B6497B1EF825FF24F42F9B4A4BD7382CFC3378A540B1B7F0C1B956C2F":"DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F":"0154FD3836AF92D0DCA57DD5341D3053988534FDE8318FC6AAAAB68E2E6F4339B19F2F281A7E0B22C269D93CF8794A9278880ED7DBB8D9362CAEACEE544320552251":"017705A7030290D1CEB605A9A1BB03FF9CDD521E87A696EC926C8C10C8362DF4975367101F67D1CF9BCCBF2F3D239534FA509E70AAC851AE01AAC68D62F866472660":0
|
||||
|
||||
ECDSA write-read random #1
|
||||
depends_on:MBEDTLS_ECP_DP_SECP192R1_ENABLED
|
||||
ecdsa_write_read_zero:MBEDTLS_ECP_DP_SECP192R1
|
||||
|
||||
ECDSA write-read random #2
|
||||
depends_on:MBEDTLS_ECP_DP_SECP224R1_ENABLED
|
||||
ecdsa_write_read_zero:MBEDTLS_ECP_DP_SECP224R1
|
||||
|
||||
ECDSA write-read random #3
|
||||
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
ecdsa_write_read_zero:MBEDTLS_ECP_DP_SECP256R1
|
||||
|
||||
ECDSA write-read random #4
|
||||
depends_on:MBEDTLS_ECP_DP_SECP384R1_ENABLED
|
||||
ecdsa_write_read_zero:MBEDTLS_ECP_DP_SECP384R1
|
||||
|
||||
ECDSA write-read random #5
|
||||
depends_on:MBEDTLS_ECP_DP_SECP521R1_ENABLED
|
||||
ecdsa_write_read_zero:MBEDTLS_ECP_DP_SECP521R1
|
||||
|
||||
ECDSA write-read random #1
|
||||
depends_on:MBEDTLS_ECP_DP_SECP192R1_ENABLED
|
||||
ecdsa_write_read_random:MBEDTLS_ECP_DP_SECP192R1
|
||||
|
@ -205,14 +205,13 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecdsa_prim_random( int id )
|
||||
void ecdsa_prim_zero( int id )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point Q;
|
||||
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 );
|
||||
@ -220,31 +219,50 @@ 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 );
|
||||
} 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,
|
||||
&rnd_info ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_gen_keypair( &grp, &d, &Q,
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
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_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 );
|
||||
}
|
||||
exit:
|
||||
mbedtls_ecp_group_free( &grp );
|
||||
mbedtls_ecp_point_free( &Q );
|
||||
mbedtls_mpi_free( &d ); mbedtls_mpi_free( &r ); mbedtls_mpi_free( &s );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecdsa_prim_random( int id )
|
||||
{
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point Q;
|
||||
mbedtls_mpi d, r, s;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
unsigned char buf[MBEDTLS_MD_MAX_SIZE];
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecp_point_init( &Q );
|
||||
mbedtls_mpi_init( &d ); mbedtls_mpi_init( &r ); mbedtls_mpi_init( &s );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
|
||||
/* prepare material for signature */
|
||||
TEST_ASSERT( mbedtls_test_rnd_pseudo_rand( &rnd_info,
|
||||
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,
|
||||
&rnd_info ) == 0 );
|
||||
|
||||
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 );
|
||||
|
||||
exit:
|
||||
mbedtls_ecp_group_free( &grp );
|
||||
@ -360,6 +378,68 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
||||
void ecdsa_write_read_zero( int id )
|
||||
{
|
||||
mbedtls_ecdsa_context ctx;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
unsigned char hash[32];
|
||||
unsigned char sig[200];
|
||||
size_t sig_len, i;
|
||||
|
||||
mbedtls_ecdsa_init( &ctx );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
memset( hash, 0, sizeof( hash ) );
|
||||
memset( sig, 0x2a, sizeof( sig ) );
|
||||
|
||||
TEST_ASSERT(0);
|
||||
|
||||
/* generate signing key */
|
||||
TEST_ASSERT( mbedtls_ecdsa_genkey( &ctx, id,
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
|
||||
/* generate and write signature, then read and verify it */
|
||||
TEST_ASSERT( mbedtls_ecdsa_write_signature( &ctx, MBEDTLS_MD_SHA256,
|
||||
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 );
|
||||
|
||||
/* check we didn't write past the announced length */
|
||||
for( i = sig_len; i < sizeof( sig ); i++ )
|
||||
TEST_ASSERT( sig[i] == 0x2a );
|
||||
|
||||
/* try verification with invalid length */
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len - 1 ) != 0 );
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len + 1 ) != 0 );
|
||||
|
||||
/* try invalid sequence tag */
|
||||
sig[0]++;
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) != 0 );
|
||||
sig[0]--;
|
||||
|
||||
/* try modifying r */
|
||||
sig[10]++;
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
|
||||
sig[10]--;
|
||||
|
||||
/* try modifying s */
|
||||
sig[sig_len - 1]++;
|
||||
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 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
||||
void ecdsa_write_read_random( int id )
|
||||
{
|
||||
@ -368,70 +448,56 @@ 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 ) );
|
||||
memset( sig, 0x2a, sizeof( sig ) );
|
||||
|
||||
while ( test_runs-- )
|
||||
{
|
||||
memset( sig, 0x2a, sizeof( sig ) );
|
||||
/* prepare material for signature */
|
||||
TEST_ASSERT( mbedtls_test_rnd_pseudo_rand( &rnd_info,
|
||||
hash, sizeof( hash ) ) == 0 );
|
||||
|
||||
/* prepare material for signature */
|
||||
if ( test_runs == 1 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_test_rnd_pseudo_rand( &rnd_info,
|
||||
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,
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
|
||||
/* generate signing key */
|
||||
TEST_ASSERT( mbedtls_ecdsa_genkey( &ctx, id,
|
||||
&mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
/* generate and write signature, then read and verify it */
|
||||
TEST_ASSERT( mbedtls_ecdsa_write_signature( &ctx, MBEDTLS_MD_SHA256,
|
||||
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 );
|
||||
|
||||
/* generate and write signature, then read and verify it */
|
||||
TEST_ASSERT( mbedtls_ecdsa_write_signature( &ctx, MBEDTLS_MD_SHA256,
|
||||
hash, sizeof( hash ),
|
||||
sig, &sig_len, &mbedtls_test_rnd_pseudo_rand,
|
||||
&rnd_info ) == 0 );
|
||||
/* check we didn't write past the announced length */
|
||||
for( i = sig_len; i < sizeof( sig ); i++ )
|
||||
TEST_ASSERT( sig[i] == 0x2a );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) == 0 );
|
||||
/* try verification with invalid length */
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len - 1 ) != 0 );
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len + 1 ) != 0 );
|
||||
|
||||
/* check we didn't write past the announced length */
|
||||
for( i = sig_len; i < sizeof( sig ); i++ )
|
||||
TEST_ASSERT( sig[i] == 0x2a );
|
||||
/* try invalid sequence tag */
|
||||
sig[0]++;
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) != 0 );
|
||||
sig[0]--;
|
||||
|
||||
/* try verification with invalid length */
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len - 1 ) != 0 );
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len + 1 ) != 0 );
|
||||
/* try modifying r */
|
||||
sig[10]++;
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
|
||||
sig[10]--;
|
||||
|
||||
/* try invalid sequence tag */
|
||||
sig[0]++;
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) != 0 );
|
||||
sig[0]--;
|
||||
|
||||
/* try modifying r */
|
||||
sig[10]++;
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
|
||||
sig[10]--;
|
||||
|
||||
/* try modifying s */
|
||||
sig[sig_len - 1]++;
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
|
||||
sig[sig_len - 1]--;
|
||||
}
|
||||
/* try modifying s */
|
||||
sig[sig_len - 1]++;
|
||||
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 );
|
||||
|
Loading…
Reference in New Issue
Block a user