mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-24 18:18:13 +00:00
Add tests for (and fix bug in) ecp_tls_write_group
This commit is contained in:
parent
420f1eb675
commit
46106a9d75
3 changed files with 48 additions and 12 deletions
|
@ -69,6 +69,8 @@ void ecp_group_init( ecp_group *grp )
|
|||
if( grp == NULL )
|
||||
return;
|
||||
|
||||
grp->id = 0;
|
||||
|
||||
mpi_init( &grp->P );
|
||||
mpi_init( &grp->B );
|
||||
ecp_point_init( &grp->G );
|
||||
|
@ -632,7 +634,7 @@ int ecp_tls_write_group( const ecp_group *grp, size_t *olen,
|
|||
* Next two bytes are the namedcurve value
|
||||
*/
|
||||
buf[0] = grp->id >> 8;
|
||||
buf[1] = grp->id && 0xFF;
|
||||
buf[1] = grp->id & 0xFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -187,20 +187,26 @@ ecp_tls_write_read_point:SECP192R1
|
|||
ECP tls write-read point #2
|
||||
ecp_tls_write_read_point:SECP521R1
|
||||
|
||||
ECP read params #1 (record too short)
|
||||
ecp_read_params:"0313":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
||||
ECP tls read group #1 (record too short)
|
||||
ecp_tls_read_group:"0313":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
||||
|
||||
ECP read params #2 (bad curve_type)
|
||||
ecp_read_params:"010013":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
||||
ECP tls read group #2 (bad curve_type)
|
||||
ecp_tls_read_group:"010013":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
||||
|
||||
ECP read params #3 (unknown curve)
|
||||
ecp_read_params:"030010":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
||||
ECP tls read group #3 (unknown curve)
|
||||
ecp_tls_read_group:"030010":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
||||
|
||||
ECP read params #4 (OK, buffer just fits)
|
||||
ecp_read_params:"030017":0:256
|
||||
ECP tls read group #4 (OK, buffer just fits)
|
||||
ecp_tls_read_group:"030017":0:256
|
||||
|
||||
ECP read params #5 (OK, buffer continues)
|
||||
ecp_read_params:"030018DEAD":0:384
|
||||
ECP tls read group #5 (OK, buffer continues)
|
||||
ecp_tls_read_group:"030018DEAD":0:384
|
||||
|
||||
ECP tls write-read group #1
|
||||
ecp_tls_write_read_group:SECP192R1
|
||||
|
||||
ECP tls write-read group #2
|
||||
ecp_tls_write_read_group:SECP521R1
|
||||
|
||||
ECP gen keypair
|
||||
ecp_gen_keypair:SECP192R1
|
||||
|
|
|
@ -337,7 +337,7 @@ ecp_tls_write_read_point:id
|
|||
END_CASE
|
||||
|
||||
BEGIN_CASE
|
||||
ecp_read_params:record:ret:bits
|
||||
ecp_tls_read_group:record:ret:bits
|
||||
{
|
||||
ecp_group grp;
|
||||
unsigned char buf[10];
|
||||
|
@ -358,6 +358,34 @@ ecp_read_params:record:ret:bits
|
|||
}
|
||||
END_CASE
|
||||
|
||||
BEGIN_CASE
|
||||
ecp_tls_write_read_group:id
|
||||
{
|
||||
ecp_group grp1, grp2;
|
||||
unsigned char buf[10];
|
||||
size_t len;
|
||||
int ret;
|
||||
|
||||
ecp_group_init( &grp1 );
|
||||
ecp_group_init( &grp2 );
|
||||
memset( buf, 0x00, sizeof( buf ) );
|
||||
|
||||
TEST_ASSERT( ecp_use_known_dp( &grp1, POLARSSL_ECP_DP_{id} ) == 0 );
|
||||
|
||||
TEST_ASSERT( ecp_tls_write_group( &grp1, &len, buf, 10 ) == 0 );
|
||||
TEST_ASSERT( ( ret = ecp_tls_read_group( &grp2, buf, len ) ) == 0 );
|
||||
|
||||
if( ret == 0 )
|
||||
{
|
||||
TEST_ASSERT( mpi_cmp_mpi( &grp1.N, &grp2.N ) == 0 );
|
||||
TEST_ASSERT( grp1.id == grp2.id );
|
||||
}
|
||||
|
||||
ecp_group_free( &grp1 );
|
||||
ecp_group_free( &grp2 );
|
||||
}
|
||||
END_CASE
|
||||
|
||||
BEGIN_CASE
|
||||
ecp_gen_keypair:id
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue