mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-28 19:21:08 +00:00
Streamline mbedtls_mpi_core_lt_ct unit test
Use mbedtls_test_read_mpi_core() to read the test data. Among other benefits, X and Y are now allocated to their exact size, so analyzers (Asan, Valgrind, Coverity, ...) have a chance of complaining if the tested function overflows the buffer. Remove TEST_CF_PUBLIC calls which are no longer necessary. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
3aae4e815e
commit
5bbdfce44c
@ -607,10 +607,10 @@ mbedtls_mpi_core_lt_ct: x=y (0 limbs)
|
||||
mpi_core_lt_ct:"":"":0
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x>y (63 bit x, y first byte greater)
|
||||
mpi_core_lt_ct:"7FFFFFFFFFFFFFFF":"FF":0
|
||||
mpi_core_lt_ct:"7FFFFFFFFFFFFFFF":"00000000000000FF":0
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x<y (63 bit y, x first byte greater)
|
||||
mpi_core_lt_ct:"FF":"7FFFFFFFFFFFFFFF":1
|
||||
mpi_core_lt_ct:"00000000000000FF":"7FFFFFFFFFFFFFFF":1
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x>y (64 bit x, y=x-1)
|
||||
mpi_core_lt_ct:"8000000000000000":"7FFFFFFFFFFFFFFF":0
|
||||
@ -619,28 +619,28 @@ mbedtls_mpi_core_lt_ct: x<y (64 bit y, x=y-1)
|
||||
mpi_core_lt_ct:"7FFFFFFFFFFFFFFF":"8000000000000000":1
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x>y (64 bit x, y=1)
|
||||
mpi_core_lt_ct:"8000000000000000":"01":0
|
||||
mpi_core_lt_ct:"8000000000000000":"0000000000000001":0
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x<y (64 bit y, x=1)
|
||||
mpi_core_lt_ct:"01":"8000000000000000":1
|
||||
mpi_core_lt_ct:"0000000000000001":"8000000000000000":1
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x>y (64 bit x, y=0)
|
||||
mpi_core_lt_ct:"8000000000000000":"00":0
|
||||
mpi_core_lt_ct:"8000000000000000":"0000000000000000":0
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x<y (64 bit y, x=0)
|
||||
mpi_core_lt_ct:"00":"8000000000000000":1
|
||||
mpi_core_lt_ct:"0000000000000000":"8000000000000000":1
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x>y (64 bit x, first bytes equal)
|
||||
mpi_core_lt_ct:"FFFFFFFFFFFFFFFF":"FF":0
|
||||
mpi_core_lt_ct:"FFFFFFFFFFFFFFFF":"00000000000000FF":0
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x<y (64 bit y, first bytes equal)
|
||||
mpi_core_lt_ct:"FF":"FFFFFFFFFFFFFFFF":1
|
||||
mpi_core_lt_ct:"00000000000000FF":"FFFFFFFFFFFFFFFF":1
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x>y (31 bit x, y first byte greater)
|
||||
mpi_core_lt_ct:"7FFFFFFF":"FF":0
|
||||
mpi_core_lt_ct:"7FFFFFFF":"000000FF":0
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x<y (31 bit y, x first byte greater)
|
||||
mpi_core_lt_ct:"FF":"7FFFFFFF":1
|
||||
mpi_core_lt_ct:"000000FF":"7FFFFFFF":1
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x>y (32 bit x, y=x-1)
|
||||
mpi_core_lt_ct:"80000000":"7FFFFFFF":0
|
||||
@ -649,22 +649,22 @@ mbedtls_mpi_core_lt_ct: x<y (32 bit y, x=y-1)
|
||||
mpi_core_lt_ct:"7FFFFFFF":"80000000":1
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x>y (32 bit x, y=1)
|
||||
mpi_core_lt_ct:"80000000":"01":0
|
||||
mpi_core_lt_ct:"80000000":"00000001":0
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x<y (32 bit y, x=1)
|
||||
mpi_core_lt_ct:"01":"80000000":1
|
||||
mpi_core_lt_ct:"00000001":"80000000":1
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x>y (32 bit x, y=0)
|
||||
mpi_core_lt_ct:"80000000":"00":0
|
||||
mpi_core_lt_ct:"80000000":"00000000":0
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x<y (32 bit y, x=0)
|
||||
mpi_core_lt_ct:"00":"80000000":1
|
||||
mpi_core_lt_ct:"00000000":"80000000":1
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x>y (32 bit x, first bytes equal)
|
||||
mpi_core_lt_ct:"FFFFFFFF":"FF":0
|
||||
mpi_core_lt_ct:"FFFFFFFF":"000000FF":0
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x<y (32 bit y, first bytes equal)
|
||||
mpi_core_lt_ct:"FF":"FFFFFFFF":1
|
||||
mpi_core_lt_ct:"000000FF":"FFFFFFFF":1
|
||||
|
||||
mbedtls_mpi_core_lt_ct: x<y, zero vs non-zero MS limb
|
||||
mpi_core_lt_ct:"00FFFFFFFFFFFFFFFF":"01FFFFFFFFFFFFFFFF":1
|
||||
|
@ -728,38 +728,29 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_core_lt_ct( data_t * input_X, data_t * input_Y, int input_ret )
|
||||
void mpi_core_lt_ct( data_t * input_X, data_t * input_Y, int exp_ret )
|
||||
{
|
||||
#define MAX_LEN 64
|
||||
mbedtls_mpi_uint X[MAX_LEN];
|
||||
mbedtls_mpi_uint Y[MAX_LEN];
|
||||
unsigned exp_ret = input_ret;
|
||||
unsigned ret;
|
||||
size_t len = CHARS_TO_LIMBS(
|
||||
input_X->len > input_Y->len ? input_X->len : input_Y->len );
|
||||
mbedtls_mpi_uint *X = NULL;
|
||||
size_t X_limbs;
|
||||
mbedtls_mpi_uint *Y = NULL;
|
||||
size_t Y_limbs;
|
||||
int ret;
|
||||
|
||||
TEST_LE_U( len, MAX_LEN );
|
||||
TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &X, &X_limbs, input_X ) );
|
||||
TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &Y, &Y_limbs, input_Y ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_core_read_be( X, len, input_X->x, input_X->len )
|
||||
== 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_core_read_be( Y, len, input_Y->x, input_Y->len )
|
||||
== 0 );
|
||||
/* We need two same-length limb arrays */
|
||||
TEST_EQUAL( X_limbs, Y_limbs );
|
||||
|
||||
TEST_CF_SECRET( X, len * sizeof( mbedtls_mpi_uint ) );
|
||||
TEST_CF_SECRET( Y, len * sizeof( mbedtls_mpi_uint ) );
|
||||
|
||||
ret = mbedtls_mpi_core_lt_ct( X, Y, len );
|
||||
|
||||
TEST_CF_PUBLIC( X, len * sizeof( mbedtls_mpi_uint ) );
|
||||
TEST_CF_PUBLIC( Y, len * sizeof( mbedtls_mpi_uint ) );
|
||||
TEST_CF_PUBLIC( &ret, sizeof( ret ) );
|
||||
TEST_CF_SECRET( X, X_limbs * sizeof( mbedtls_mpi_uint ) );
|
||||
TEST_CF_SECRET( Y, X_limbs * sizeof( mbedtls_mpi_uint ) );
|
||||
|
||||
ret = mbedtls_mpi_core_lt_ct( X, Y, X_limbs );
|
||||
TEST_EQUAL( ret, exp_ret );
|
||||
|
||||
exit:
|
||||
;
|
||||
|
||||
#undef MAX_LEN
|
||||
mbedtls_free( X );
|
||||
mbedtls_free( Y );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user