Test invalid bit value in mbedtls_mpi_set_bit()

This commit is contained in:
Paul Bakker 2016-07-14 12:47:07 +01:00 committed by Simon Butcher
parent c7d6bd4b5f
commit ec5ceb65d6
2 changed files with 17 additions and 10 deletions

View File

@ -706,22 +706,25 @@ Test bit getting (Value bit 23)
mbedtls_mpi_get_bit:10:"49979687":23:1
Test bit set (Change existing value with a 1)
mbedtls_mpi_set_bit:10:"49979687":24:1:10:"66756903"
mbedtls_mpi_set_bit:10:"49979687":24:1:10:"66756903":0
Test bit set (Change existing value with a 0)
mbedtls_mpi_set_bit:10:"49979687":25:0:10:"16425255"
mbedtls_mpi_set_bit:10:"49979687":25:0:10:"16425255":0
Test bit set (Add above existing limbs with a 0)
mbedtls_mpi_set_bit:10:"49979687":80:0:10:"49979687"
mbedtls_mpi_set_bit:10:"49979687":80:0:10:"49979687":0
Test bit set (Add above existing limbs with a 1)
mbedtls_mpi_set_bit:10:"49979687":80:1:10:"1208925819614629224685863"
mbedtls_mpi_set_bit:10:"49979687":80:1:10:"1208925819614629224685863":0
Test bit set (Bit index larger than 31 with a 0)
mbedtls_mpi_set_bit:16:"FFFFFFFFFFFFFFFF":32:0:16:"FFFFFFFEFFFFFFFF"
mbedtls_mpi_set_bit:16:"FFFFFFFFFFFFFFFF":32:0:16:"FFFFFFFEFFFFFFFF":0
Test bit set (Bit index larger than 31 with a 1)
mbedtls_mpi_set_bit:16:"00":32:1:16:"0100000000"
mbedtls_mpi_set_bit:16:"00":32:1:16:"0100000000":0
Test bit set (Invalid bit value)
mbedtls_mpi_set_bit:16:"00":5:2:16:"00":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
MPI Selftest
depends_on:MBEDTLS_SELF_TEST

View File

@ -189,16 +189,20 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void mbedtls_mpi_set_bit( int radix_X, char *input_X, int pos, int val, int radix_Y,
char *output_Y )
void mbedtls_mpi_set_bit( int radix_X, char *input_X, int pos, int val,
int radix_Y, char *output_Y, int result )
{
mbedtls_mpi X, Y;
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, output_Y ) == 0 );
TEST_ASSERT( mbedtls_mpi_set_bit( &X, pos, val ) == 0 );
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y ) == 0 );
TEST_ASSERT( mbedtls_mpi_set_bit( &X, pos, val ) == result );
if( result == 0 )
{
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y ) == 0 );
}
exit:
mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );