From ec5ceb65d6702b0636d09619521a9de9d1be2a4e Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Thu, 14 Jul 2016 12:47:07 +0100 Subject: [PATCH] Test invalid bit value in mbedtls_mpi_set_bit() --- tests/suites/test_suite_mpi.data | 15 +++++++++------ tests/suites/test_suite_mpi.function | 12 ++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/suites/test_suite_mpi.data b/tests/suites/test_suite_mpi.data index 3fd7f2d1b..fa65b5f2a 100644 --- a/tests/suites/test_suite_mpi.data +++ b/tests/suites/test_suite_mpi.data @@ -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 diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function index c41ca6937..e5d0850f1 100644 --- a/tests/suites/test_suite_mpi.function +++ b/tests/suites/test_suite_mpi.function @@ -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 );