mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-18 19:27:41 +00:00
Merge pull request #6456 from gabor-mezei-arm/6237_test_update_cond_assign_swap
Update tests to use conditional assign and swap
This commit is contained in:
commit
433f1f1809
@ -345,14 +345,18 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_core_cond_assign( data_t * input_X,
|
||||
data_t * input_Y,
|
||||
void mpi_core_cond_assign( char * input_X,
|
||||
char * input_Y,
|
||||
int input_bytes )
|
||||
{
|
||||
mbedtls_mpi_uint *X = NULL;
|
||||
mbedtls_mpi_uint *Y = NULL;
|
||||
size_t limbs_X = CHARS_TO_LIMBS( input_X->len );
|
||||
size_t limbs_Y = CHARS_TO_LIMBS( input_Y->len );
|
||||
size_t limbs_X;
|
||||
size_t limbs_Y;
|
||||
|
||||
TEST_EQUAL( mbedtls_test_read_mpi_core( &X, &limbs_X, input_X ), 0 );
|
||||
TEST_EQUAL( mbedtls_test_read_mpi_core( &Y, &limbs_Y, input_Y ), 0 );
|
||||
|
||||
size_t limbs = limbs_X;
|
||||
size_t copy_limbs = CHARS_TO_LIMBS( input_bytes );
|
||||
size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
|
||||
@ -361,15 +365,6 @@ void mpi_core_cond_assign( data_t * input_X,
|
||||
TEST_EQUAL( limbs_X, limbs_Y );
|
||||
TEST_ASSERT( copy_limbs <= limbs );
|
||||
|
||||
ASSERT_ALLOC( X, limbs );
|
||||
ASSERT_ALLOC( Y, limbs );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_core_read_be( X, limbs, input_X->x, input_X->len )
|
||||
== 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_core_read_be( Y, limbs, input_Y->x, input_Y->len )
|
||||
== 0 );
|
||||
|
||||
/* condition is false */
|
||||
TEST_CF_SECRET( X, bytes );
|
||||
TEST_CF_SECRET( Y, bytes );
|
||||
@ -394,6 +389,9 @@ void mpi_core_cond_assign( data_t * input_X,
|
||||
than the length of the given MPIs. */
|
||||
if( copy_limbs < limbs )
|
||||
{
|
||||
TEST_CF_PUBLIC( X, bytes );
|
||||
TEST_CF_PUBLIC( Y, bytes );
|
||||
|
||||
ASSERT_COMPARE( X, copy_bytes, Y, copy_bytes );
|
||||
TEST_ASSERT( memcmp( X, Y, bytes ) != 0 );
|
||||
}
|
||||
@ -407,16 +405,20 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_core_cond_swap( data_t * input_X,
|
||||
data_t * input_Y,
|
||||
void mpi_core_cond_swap( char * input_X,
|
||||
char * input_Y,
|
||||
int input_bytes )
|
||||
{
|
||||
mbedtls_mpi_uint *tmp_X = NULL;
|
||||
mbedtls_mpi_uint *tmp_Y = NULL;
|
||||
mbedtls_mpi_uint *X = NULL;
|
||||
mbedtls_mpi_uint *Y = NULL;
|
||||
size_t limbs_X = CHARS_TO_LIMBS( input_X->len );
|
||||
size_t limbs_Y = CHARS_TO_LIMBS( input_Y->len );
|
||||
size_t limbs_X;
|
||||
size_t limbs_Y;
|
||||
|
||||
TEST_EQUAL( mbedtls_test_read_mpi_core( &tmp_X, &limbs_X, input_X ), 0 );
|
||||
TEST_EQUAL( mbedtls_test_read_mpi_core( &tmp_Y, &limbs_Y, input_Y ), 0 );
|
||||
|
||||
size_t limbs = limbs_X;
|
||||
size_t copy_limbs = CHARS_TO_LIMBS( input_bytes );
|
||||
size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
|
||||
@ -425,18 +427,9 @@ void mpi_core_cond_swap( data_t * input_X,
|
||||
TEST_EQUAL( limbs_X, limbs_Y );
|
||||
TEST_ASSERT( copy_limbs <= limbs );
|
||||
|
||||
ASSERT_ALLOC( tmp_X, limbs );
|
||||
ASSERT_ALLOC( tmp_Y, limbs );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_core_read_be( tmp_X, limbs,
|
||||
input_X->x, input_X->len )
|
||||
== 0 );
|
||||
ASSERT_ALLOC( X, limbs );
|
||||
memcpy( X, tmp_X, bytes );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_core_read_be( tmp_Y, limbs,
|
||||
input_Y->x, input_Y->len )
|
||||
== 0 );
|
||||
ASSERT_ALLOC( Y, limbs );
|
||||
memcpy( Y, tmp_Y, bytes );
|
||||
|
||||
|
@ -110,16 +110,20 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_mod_raw_cond_assign( data_t * input_X,
|
||||
data_t * input_Y,
|
||||
void mpi_mod_raw_cond_assign( char * input_X,
|
||||
char * input_Y,
|
||||
int input_bytes )
|
||||
{
|
||||
mbedtls_mpi_uint *X = NULL;
|
||||
mbedtls_mpi_uint *Y = NULL;
|
||||
mbedtls_mpi_uint *buff_m = NULL;
|
||||
mbedtls_mpi_mod_modulus m;
|
||||
size_t limbs_X = CHARS_TO_LIMBS( input_X->len );
|
||||
size_t limbs_Y = CHARS_TO_LIMBS( input_Y->len );
|
||||
size_t limbs_X;
|
||||
size_t limbs_Y;
|
||||
|
||||
TEST_EQUAL( mbedtls_test_read_mpi_core( &X, &limbs_X, input_X ), 0 );
|
||||
TEST_EQUAL( mbedtls_test_read_mpi_core( &Y, &limbs_Y, input_Y ), 0 );
|
||||
|
||||
size_t limbs = limbs_X;
|
||||
size_t copy_limbs = CHARS_TO_LIMBS( input_bytes );
|
||||
size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
|
||||
@ -130,24 +134,12 @@ void mpi_mod_raw_cond_assign( data_t * input_X,
|
||||
TEST_EQUAL( limbs_X, limbs_Y );
|
||||
TEST_ASSERT( copy_limbs <= limbs );
|
||||
|
||||
ASSERT_ALLOC( X, limbs );
|
||||
ASSERT_ALLOC( Y, limbs );
|
||||
|
||||
ASSERT_ALLOC( buff_m, limbs );
|
||||
memset( buff_m, 0xFF, copy_bytes );
|
||||
TEST_ASSERT( mbedtls_mpi_mod_modulus_setup(
|
||||
ASSERT_ALLOC( buff_m, copy_limbs );
|
||||
memset( buff_m, 0xFF, copy_limbs );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_modulus_setup(
|
||||
&m, buff_m, copy_limbs,
|
||||
MBEDTLS_MPI_MOD_EXT_REP_BE,
|
||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY )
|
||||
== 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_core_read_be( X, limbs,
|
||||
input_X->x, input_X->len )
|
||||
== 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_core_read_be( Y, limbs,
|
||||
input_Y->x, input_Y->len )
|
||||
== 0 );
|
||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY ), 0 );
|
||||
|
||||
/* condition is false */
|
||||
TEST_CF_SECRET( X, bytes );
|
||||
@ -189,8 +181,8 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_mod_raw_cond_swap( data_t * input_X,
|
||||
data_t * input_Y,
|
||||
void mpi_mod_raw_cond_swap( char * input_X,
|
||||
char * input_Y,
|
||||
int input_bytes )
|
||||
{
|
||||
mbedtls_mpi_uint *tmp_X = NULL;
|
||||
@ -199,8 +191,12 @@ void mpi_mod_raw_cond_swap( data_t * input_X,
|
||||
mbedtls_mpi_uint *Y = NULL;
|
||||
mbedtls_mpi_uint *buff_m = NULL;
|
||||
mbedtls_mpi_mod_modulus m;
|
||||
size_t limbs_X = CHARS_TO_LIMBS( input_X->len );
|
||||
size_t limbs_Y = CHARS_TO_LIMBS( input_Y->len );
|
||||
size_t limbs_X;
|
||||
size_t limbs_Y;
|
||||
|
||||
TEST_EQUAL( mbedtls_test_read_mpi_core( &tmp_X, &limbs_X, input_X ), 0 );
|
||||
TEST_EQUAL( mbedtls_test_read_mpi_core( &tmp_Y, &limbs_Y, input_Y ), 0 );
|
||||
|
||||
size_t limbs = limbs_X;
|
||||
size_t copy_limbs = CHARS_TO_LIMBS( input_bytes );
|
||||
size_t bytes = limbs * sizeof( mbedtls_mpi_uint );
|
||||
@ -211,24 +207,16 @@ void mpi_mod_raw_cond_swap( data_t * input_X,
|
||||
TEST_EQUAL( limbs_X, limbs_Y );
|
||||
TEST_ASSERT( copy_limbs <= limbs );
|
||||
|
||||
ASSERT_ALLOC( tmp_X, limbs );
|
||||
ASSERT_ALLOC( tmp_Y, limbs );
|
||||
|
||||
ASSERT_ALLOC( buff_m, copy_limbs );
|
||||
memset( buff_m, 0xFF, copy_bytes );
|
||||
TEST_ASSERT( mbedtls_mpi_mod_modulus_setup(
|
||||
memset( buff_m, 0xFF, copy_limbs );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_modulus_setup(
|
||||
&m, buff_m, copy_limbs,
|
||||
MBEDTLS_MPI_MOD_EXT_REP_BE,
|
||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY )
|
||||
== 0 );
|
||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY ), 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_core_read_be( tmp_X, limbs, input_X->x, input_X->len )
|
||||
== 0 );
|
||||
ASSERT_ALLOC( X, limbs );
|
||||
memcpy( X, tmp_X, bytes );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_core_read_be( tmp_Y, limbs, input_Y->x, input_Y->len )
|
||||
== 0 );
|
||||
ASSERT_ALLOC( Y, bytes );
|
||||
memcpy( Y, tmp_Y, bytes );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user