mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-25 17:35:37 +01:00
Fix ecp_tls_read_point's signature
This commit is contained in:
parent
7c145c6418
commit
98f51815d6
@ -324,7 +324,7 @@ int ecp_tls_write_group( const ecp_group *grp, size_t *olen,
|
||||
*
|
||||
* \param grp ECP group used
|
||||
* \param pt Destination point
|
||||
* \param buf Start of input buffer
|
||||
* \param buf $(Start of input buffer)
|
||||
* \param len Buffer length
|
||||
*
|
||||
* \return O if successful,
|
||||
@ -332,7 +332,7 @@ int ecp_tls_write_group( const ecp_group *grp, size_t *olen,
|
||||
* POLARSSL_ERR_ECP_BAD_INPUT_DATA if input is invalid
|
||||
*/
|
||||
int ecp_tls_read_point( const ecp_group *grp, ecp_point *pt,
|
||||
const unsigned char *buf, size_t len );
|
||||
const unsigned char **buf, size_t len );
|
||||
|
||||
/**
|
||||
* \brief Export a point as a TLS ECPoint record
|
||||
|
@ -271,9 +271,10 @@ cleanup:
|
||||
* } ECPoint;
|
||||
*/
|
||||
int ecp_tls_read_point( const ecp_group *grp, ecp_point *pt,
|
||||
const unsigned char *buf, size_t buf_len )
|
||||
const unsigned char **buf, size_t buf_len )
|
||||
{
|
||||
unsigned char data_len;
|
||||
const unsigned char *buf_start;
|
||||
|
||||
/*
|
||||
* We must have at least two bytes (1 for length, at least of for data)
|
||||
@ -281,11 +282,17 @@ int ecp_tls_read_point( const ecp_group *grp, ecp_point *pt,
|
||||
if( buf_len < 2 )
|
||||
return( POLARSSL_ERR_ECP_BAD_INPUT_DATA );
|
||||
|
||||
data_len = *buf++;
|
||||
data_len = *(*buf)++;
|
||||
if( data_len < 1 || data_len > buf_len - 1 )
|
||||
return( POLARSSL_ERR_ECP_BAD_INPUT_DATA );
|
||||
|
||||
return ecp_point_read_binary( grp, pt, buf, data_len );
|
||||
/*
|
||||
* Save buffer start for read_binary and update buf
|
||||
*/
|
||||
buf_start = *buf;
|
||||
*buf += data_len;
|
||||
|
||||
return ecp_point_read_binary( grp, pt, buf_start, data_len );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -301,6 +301,7 @@ ecp_tls_read_point:id:input:x:y:z:ret
|
||||
mpi X, Y, Z;
|
||||
size_t ilen;
|
||||
unsigned char buf[256];
|
||||
const unsigned char *vbuf = buf;
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
|
||||
@ -315,13 +316,14 @@ ecp_tls_read_point:id:input:x:y:z:ret
|
||||
|
||||
ilen = unhexify( buf, {input} );
|
||||
|
||||
TEST_ASSERT( ecp_tls_read_point( &grp, &P, buf, ilen ) == {ret} );
|
||||
TEST_ASSERT( ecp_tls_read_point( &grp, &P, &vbuf, ilen ) == {ret} );
|
||||
|
||||
if( {ret} == 0 )
|
||||
{
|
||||
TEST_ASSERT( mpi_cmp_mpi( &P.X, &X ) == 0 );
|
||||
TEST_ASSERT( mpi_cmp_mpi( &P.Y, &Y ) == 0 );
|
||||
TEST_ASSERT( mpi_cmp_mpi( &P.Z, &Z ) == 0 );
|
||||
TEST_ASSERT( *vbuf == 0x00 );
|
||||
}
|
||||
|
||||
ecp_group_free( &grp ); ecp_point_free( &P );
|
||||
@ -335,37 +337,45 @@ ecp_tls_write_read_point:id
|
||||
ecp_group grp;
|
||||
ecp_point pt;
|
||||
unsigned char buf[256];
|
||||
const unsigned char *vbuf;
|
||||
size_t olen;
|
||||
|
||||
ecp_group_init( &grp );
|
||||
ecp_point_init( &pt );
|
||||
memset( buf, 0x00, sizeof( buf ) );
|
||||
|
||||
TEST_ASSERT( ecp_use_known_dp( &grp, POLARSSL_ECP_DP_{id} ) == 0 );
|
||||
|
||||
memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
|
||||
TEST_ASSERT( ecp_tls_write_point( &grp, &grp.G,
|
||||
POLARSSL_ECP_PF_COMPRESSED, &olen, buf, 256 ) == 0 );
|
||||
TEST_ASSERT( ecp_tls_read_point( &grp, &pt, buf, olen )
|
||||
TEST_ASSERT( ecp_tls_read_point( &grp, &pt, &vbuf, olen )
|
||||
== POLARSSL_ERR_ECP_BAD_INPUT_DATA );
|
||||
TEST_ASSERT( vbuf == buf + olen );
|
||||
|
||||
memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
|
||||
TEST_ASSERT( ecp_tls_write_point( &grp, &grp.G,
|
||||
POLARSSL_ECP_PF_UNCOMPRESSED, &olen, buf, 256 ) == 0 );
|
||||
TEST_ASSERT( ecp_tls_read_point( &grp, &pt, buf, olen ) == 0 );
|
||||
TEST_ASSERT( ecp_tls_read_point( &grp, &pt, &vbuf, olen ) == 0 );
|
||||
TEST_ASSERT( mpi_cmp_mpi( &grp.G.X, &pt.X ) == 0 );
|
||||
TEST_ASSERT( mpi_cmp_mpi( &grp.G.Y, &pt.Y ) == 0 );
|
||||
TEST_ASSERT( mpi_cmp_mpi( &grp.G.Z, &pt.Z ) == 0 );
|
||||
TEST_ASSERT( vbuf == buf + olen );
|
||||
|
||||
memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
|
||||
TEST_ASSERT( ecp_set_zero( &pt ) == 0 );
|
||||
TEST_ASSERT( ecp_tls_write_point( &grp, &pt,
|
||||
POLARSSL_ECP_PF_COMPRESSED, &olen, buf, 256 ) == 0 );
|
||||
TEST_ASSERT( ecp_tls_read_point( &grp, &pt, buf, olen ) == 0 );
|
||||
TEST_ASSERT( ecp_tls_read_point( &grp, &pt, &vbuf, olen ) == 0 );
|
||||
TEST_ASSERT( ecp_is_zero( &pt ) );
|
||||
TEST_ASSERT( vbuf == buf + olen );
|
||||
|
||||
memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
|
||||
TEST_ASSERT( ecp_set_zero( &pt ) == 0 );
|
||||
TEST_ASSERT( ecp_tls_write_point( &grp, &pt,
|
||||
POLARSSL_ECP_PF_UNCOMPRESSED, &olen, buf, 256 ) == 0 );
|
||||
TEST_ASSERT( ecp_tls_read_point( &grp, &pt, buf, olen ) == 0 );
|
||||
TEST_ASSERT( ecp_tls_read_point( &grp, &pt, &vbuf, olen ) == 0 );
|
||||
TEST_ASSERT( ecp_is_zero( &pt ) );
|
||||
TEST_ASSERT( vbuf == buf + olen );
|
||||
|
||||
ecp_group_free( &grp );
|
||||
ecp_point_free( &pt );
|
||||
|
Loading…
Reference in New Issue
Block a user