Commit d84895dc authored by Manuel Pégourié-Gonnard's avatar Manuel Pégourié-Gonnard
Browse files

Supress 'format' argument to ecp_read_binary.

And adjust error codes for ecp_*_binary while at it.
parent 00794059
......@@ -256,7 +256,6 @@ int ecp_write_binary( const ecp_group *grp, const ecp_point *P, int format,
*
* \param grp Group to which the point should belong
* \param P Point to import
* \param format Point format, must be POLARSSL_ECP_PF_UNCOMPRESSED for now
* \param buf Input buffer
* \param ilen Actual length of input
*
......@@ -268,7 +267,7 @@ int ecp_write_binary( const ecp_group *grp, const ecp_point *P, int format,
* belongs to the given group, see ecp_check_pubkey() for
* that.
*/
int ecp_read_binary( const ecp_group *grp, ecp_point *P, int format,
int ecp_read_binary( const ecp_group *grp, ecp_point *P,
const unsigned char *buf, size_t ilen );
/**
......
......@@ -240,25 +240,22 @@ cleanup:
/*
* Import a point from unsigned binary data (SEC1 2.3.4)
*/
int ecp_read_binary( const ecp_group *grp, ecp_point *P, int format,
int ecp_read_binary( const ecp_group *grp, ecp_point *pt,
const unsigned char *buf, size_t ilen ) {
int ret;
size_t plen;
if( format != POLARSSL_ECP_PF_UNCOMPRESSED )
return( POLARSSL_ERR_ECP_GENERIC );
if( ilen == 1 && buf[0] == 0x00 )
return( ecp_set_zero( P ) );
return( ecp_set_zero( pt ) );
plen = mpi_size( &grp-> P );
plen = mpi_size( &grp->P );
if( ilen != 2 * plen + 1 || buf[0] != 0x04 )
return( POLARSSL_ERR_ECP_GENERIC );
return( POLARSSL_ERR_ECP_BAD_INPUT_DATA );
MPI_CHK( mpi_read_binary( &P->X, buf + 1, plen ) );
MPI_CHK( mpi_read_binary( &P->Y, buf + 1 + plen, plen ) );
MPI_CHK( mpi_lset( &P->Z, 1 ) );
MPI_CHK( mpi_read_binary( &pt->X, buf + 1, plen ) );
MPI_CHK( mpi_read_binary( &pt->Y, buf + 1 + plen, plen ) );
MPI_CHK( mpi_lset( &pt->Z, 1 ) );
cleanup:
return( ret );
......@@ -285,8 +282,7 @@ int ecp_tls_read_point( const ecp_group *grp, ecp_point *pt,
if( data_len < 1 || data_len > buf_len - 1 )
return( POLARSSL_ERR_ECP_BAD_INPUT_DATA );
return ecp_read_binary( grp, pt, POLARSSL_ECP_PF_UNCOMPRESSED,
buf, data_len );
return ecp_read_binary( grp, pt, buf, data_len );
}
/*
......
......@@ -134,55 +134,52 @@ ECP small check pubkey #10
ecp_small_check_pub:10:25:1:POLARSSL_ERR_ECP_GENERIC
ECP write binary #0 (zero, bad format)
ecp_write_binary:SECP192R1:"01":"01":"00":UNKNOWN:"00":1:POLARSSL_ERR_ECP_GENERIC
ecp_write_binary:SECP192R1:"01":"01":"00":UNKNOWN:"00":1:POLARSSL_ERR_ECP_BAD_INPUT_DATA
ECP write binary #1 (zero, uncompressed, buffer just fits)
ecp_write_binary:SECP192R1:"01":"01":"00":UNCOMPRESSED:"00":1:0
ECP write binary #2 (zero, buffer too small)
ecp_write_binary:SECP192R1:"01":"01":"00":UNCOMPRESSED:"00":0:POLARSSL_ERR_ECP_GENERIC
ecp_write_binary:SECP192R1:"01":"01":"00":UNCOMPRESSED:"00":0:POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
ECP write binary #3 (non-zero, uncompressed, buffer just fits)
ecp_write_binary:SECP192R1:"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"6ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"01":UNCOMPRESSED:"0448d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc99336ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":49:0
ECP write binary #4 (non-zero, uncompressed, buffer too small)
ecp_write_binary:SECP192R1:"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"6ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"01":UNCOMPRESSED:"0448d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc99336ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":48:POLARSSL_ERR_ECP_GENERIC
ecp_write_binary:SECP192R1:"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"6ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"01":UNCOMPRESSED:"0448d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc99336ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":48:POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
ECP write binary #5 (zero, compressed, buffer just fits)
ecp_write_binary:SECP192R1:"01":"01":"00":COMPRESSED:"00":1:0
ECP write binary #6 (zero, buffer too small)
ecp_write_binary:SECP192R1:"01":"01":"00":COMPRESSED:"00":0:POLARSSL_ERR_ECP_GENERIC
ecp_write_binary:SECP192R1:"01":"01":"00":COMPRESSED:"00":0:POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
ECP write binary #7 (even, compressed, buffer just fits)
ecp_write_binary:SECP192R1:"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"6ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"01":COMPRESSED:"0248d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":25:0
ECP write binary #8 (even, compressed, buffer too small)
ecp_write_binary:SECP192R1:"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"6ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"01":COMPRESSED:"0248d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":24:POLARSSL_ERR_ECP_GENERIC
ecp_write_binary:SECP192R1:"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"6ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"01":COMPRESSED:"0248d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":24:POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
ECP write binary #7 (odd, compressed, buffer just fits)
ecp_write_binary:SECP192R1:"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"93112b28345b7d1d7799611e49bea9d8290cb2d7afe1f9f3":"01":COMPRESSED:"0348d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":25:0
ECP read binary #0 (invalid format)
ecp_read_binary:SECP192R1:"00":UNKNOWN:"01":"01":"00":POLARSSL_ERR_ECP_GENERIC
ECP read binary #1 (zero, invalid ilen)
ecp_read_binary:SECP192R1:"0000":UNCOMPRESSED:"01":"01":"00":POLARSSL_ERR_ECP_GENERIC
ecp_read_binary:SECP192R1:"0000":"01":"01":"00":POLARSSL_ERR_ECP_BAD_INPUT_DATA
ECP read binary #2 (zero, invalid first byte)
ecp_read_binary:SECP192R1:"01":UNCOMPRESSED:"01":"01":"00":POLARSSL_ERR_ECP_GENERIC
ecp_read_binary:SECP192R1:"01":"01":"01":"00":POLARSSL_ERR_ECP_BAD_INPUT_DATA
ECP read binary #3 (zero, OK)
ecp_read_binary:SECP192R1:"00":UNCOMPRESSED:"01":"01":"00":0
ecp_read_binary:SECP192R1:"00":"01":"01":"00":0
ECP read binary #4 (non-zero, invalid ilen)
ecp_read_binary:SECP192R1:"04001122":UNCOMPRESSED:"01":"01":"00":POLARSSL_ERR_ECP_GENERIC
ecp_read_binary:SECP192R1:"04001122":"01":"01":"00":POLARSSL_ERR_ECP_BAD_INPUT_DATA
ECP read binary #5 (non-zero, invalid first byte)
ecp_read_binary:SECP192R1:"0548d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc99336ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":UNCOMPRESSED:"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"6ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"01":POLARSSL_ERR_ECP_GENERIC
ecp_read_binary:SECP192R1:"0548d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc99336ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"6ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"01":POLARSSL_ERR_ECP_BAD_INPUT_DATA
ECP read binary #6 (non-zero, OK)
ecp_read_binary:SECP192R1:"0448d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc99336ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":UNCOMPRESSED:"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"6ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"01":0
ecp_read_binary:SECP192R1:"0448d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc99336ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"48d8082a3a1e3112bc03a8ef2f6d40d0a77a6f8e00cc9933":"6ceed4d7cba482e288669ee1b6415626d6f34d28501e060c":"01":0
ECP read params #1 (record too short)
ecp_read_params:"0313":POLARSSL_ERR_ECP_BAD_INPUT_DATA:0
......
......@@ -230,7 +230,7 @@ ecp_write_binary:id:x:y:z:format:out:blen:ret
ecp_group grp;
ecp_point P;
unsigned char buf[256], str[512];
size_t olen;
uint8_t olen;
memset( buf, 0, sizeof( buf ) );
memset( str, 0, sizeof( str ) );
......@@ -258,7 +258,7 @@ ecp_write_binary:id:x:y:z:format:out:blen:ret
END_CASE
BEGIN_CASE
ecp_read_binary:id:input:format:x:y:z:ret
ecp_read_binary:id:input:x:y:z:ret
{
ecp_group grp;
ecp_point P;
......@@ -279,9 +279,7 @@ ecp_read_binary:id:input:format:x:y:z:ret
ilen = unhexify( buf, {input} );
#define POLARSSL_ECP_PF_UNKNOWN -1
TEST_ASSERT( ecp_read_binary( &grp, &P, POLARSSL_ECP_PF_{format},
buf, ilen ) == {ret} );
TEST_ASSERT( ecp_read_binary( &grp, &P, buf, ilen ) == {ret} );
if( {ret} == 0 )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment