mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-30 17:21:02 +00:00
Add tests for (and fix bug in) ecp_tls_write_group
This commit is contained in:
parent
420f1eb675
commit
46106a9d75
|
@ -69,6 +69,8 @@ void ecp_group_init( ecp_group *grp )
|
||||||
if( grp == NULL )
|
if( grp == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
grp->id = 0;
|
||||||
|
|
||||||
mpi_init( &grp->P );
|
mpi_init( &grp->P );
|
||||||
mpi_init( &grp->B );
|
mpi_init( &grp->B );
|
||||||
ecp_point_init( &grp->G );
|
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
|
* Next two bytes are the namedcurve value
|
||||||
*/
|
*/
|
||||||
buf[0] = grp->id >> 8;
|
buf[0] = grp->id >> 8;
|
||||||
buf[1] = grp->id && 0xFF;
|
buf[1] = grp->id & 0xFF;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,20 +187,26 @@ ecp_tls_write_read_point:SECP192R1
|
||||||
ECP tls write-read point #2
|
ECP tls write-read point #2
|
||||||
ecp_tls_write_read_point:SECP521R1
|
ecp_tls_write_read_point:SECP521R1
|
||||||
|
|
||||||
ECP read params #1 (record too short)
|
ECP tls read group #1 (record too short)
|
||||||
ecp_read_params:"0313":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
ecp_tls_read_group:"0313":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
||||||
|
|
||||||
ECP read params #2 (bad curve_type)
|
ECP tls read group #2 (bad curve_type)
|
||||||
ecp_read_params:"010013":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
ecp_tls_read_group:"010013":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
||||||
|
|
||||||
ECP read params #3 (unknown curve)
|
ECP tls read group #3 (unknown curve)
|
||||||
ecp_read_params:"030010":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
ecp_tls_read_group:"030010":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
|
||||||
|
|
||||||
ECP read params #4 (OK, buffer just fits)
|
ECP tls read group #4 (OK, buffer just fits)
|
||||||
ecp_read_params:"030017":0:256
|
ecp_tls_read_group:"030017":0:256
|
||||||
|
|
||||||
ECP read params #5 (OK, buffer continues)
|
ECP tls read group #5 (OK, buffer continues)
|
||||||
ecp_read_params:"030018DEAD":0:384
|
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
|
||||||
ecp_gen_keypair:SECP192R1
|
ecp_gen_keypair:SECP192R1
|
||||||
|
|
|
@ -337,7 +337,7 @@ ecp_tls_write_read_point:id
|
||||||
END_CASE
|
END_CASE
|
||||||
|
|
||||||
BEGIN_CASE
|
BEGIN_CASE
|
||||||
ecp_read_params:record:ret:bits
|
ecp_tls_read_group:record:ret:bits
|
||||||
{
|
{
|
||||||
ecp_group grp;
|
ecp_group grp;
|
||||||
unsigned char buf[10];
|
unsigned char buf[10];
|
||||||
|
@ -358,6 +358,34 @@ ecp_read_params:record:ret:bits
|
||||||
}
|
}
|
||||||
END_CASE
|
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
|
BEGIN_CASE
|
||||||
ecp_gen_keypair:id
|
ecp_gen_keypair:id
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue