mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-11 03:46:38 +00:00
Bignum Mod: io_neg test pass data directly
Pass buffer directly instead of constructing it in the function. Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
parent
96070a53a8
commit
566c91db27
@ -57,19 +57,19 @@ Test mbedtls_mpi_residue_setup #8 r > m
|
||||
mpi_residue_setup:"fe":"ff":-4
|
||||
|
||||
Test mbedtls_mpi_mod_io_neg #1 input_r < modulo m
|
||||
mpi_mod_io_neg:"fe":"01":1:253:0
|
||||
mpi_mod_io_neg:"fe":"01":"fd":0
|
||||
|
||||
Test mbedtls_mpi_mod_io_neg #2 input_r == modulo m
|
||||
mpi_mod_io_neg:"fe":"01":1:254:-4
|
||||
mpi_mod_io_neg:"fe":"01":"fe":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Test mbedtls_mpi_mod_io_neg #3 input_r >= modulo m
|
||||
mpi_mod_io_neg:"fe":"01":1:255:-4
|
||||
Test mbedtls_mpi_mod_io_neg #3 input_r > modulo m
|
||||
mpi_mod_io_neg:"fe":"01":"ff":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Test mbedtls_mpi_mod_io_neg #4 input_r too large to fit
|
||||
mpi_mod_io_neg:"fe":"01":1024:255:-8
|
||||
mpi_mod_io_neg:"fe":"01":"ffffffffffffffffff":MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL
|
||||
|
||||
Test mbedtls_mpi_mod_io_neg #5 Sucesfull read / output buffer too small
|
||||
mpi_mod_io_neg:"7ffffffffffffffffffffffffffffff1":"7ffffffffffffffffffffffffffffff0":2:255:0
|
||||
mpi_mod_io_neg:"7ffffffffffffffffffffffffffffff1":"7ffffffffffffffffffffffffffffff0":"ffff":0
|
||||
|
||||
Test mbedtls_mpi_mod_io #1 N: "11" A: "119".
|
||||
mpi_mod_io:"000000000000000b":"0000000000000000":MBEDTLS_MPI_MOD_EXT_REP_BE
|
||||
|
@ -114,11 +114,10 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_mod_io_neg( char * input_N, char * input_R, int buff_bytes, int buff_byte_val, int ret )
|
||||
void mpi_mod_io_neg( char * input_N, char * input_R, data_t * buf, int ret )
|
||||
{
|
||||
mbedtls_mpi_uint *N = NULL;
|
||||
mbedtls_mpi_uint *R = NULL;
|
||||
unsigned char *r_buff = NULL;
|
||||
size_t n_limbs, r_limbs;
|
||||
|
||||
mbedtls_mpi_mod_modulus m;
|
||||
@ -128,20 +127,15 @@ void mpi_mod_io_neg( char * input_N, char * input_R, int buff_bytes, int buff_by
|
||||
|
||||
mbedtls_mpi_mod_modulus_init( &m );
|
||||
|
||||
/* Allocate the memory for intermediate data structures */
|
||||
ASSERT_ALLOC( r_buff, buff_bytes );
|
||||
/* Fill the buffer with the value passed in */
|
||||
memset( r_buff, buff_byte_val, buff_bytes );
|
||||
|
||||
TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &n_limbs, input_N ) );
|
||||
TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &R, &r_limbs, input_R ) );
|
||||
|
||||
/* modulo->p == NULL || residue->p == NULL ( m has not been set-up ) */
|
||||
TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
|
||||
mbedtls_mpi_mod_read( &r, &m, r_buff, buff_bytes, endian ) );
|
||||
mbedtls_mpi_mod_read( &r, &m, buf->x, buf->len, endian ) );
|
||||
|
||||
TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
|
||||
mbedtls_mpi_mod_write( &r, &m, r_buff, buff_bytes, endian ) );
|
||||
mbedtls_mpi_mod_write( &r, &m, buf->x, buf->len, endian ) );
|
||||
|
||||
TEST_EQUAL( 0, mbedtls_mpi_mod_modulus_setup( &m, N, n_limbs,
|
||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY ) );
|
||||
@ -149,30 +143,29 @@ void mpi_mod_io_neg( char * input_N, char * input_R, int buff_bytes, int buff_by
|
||||
|
||||
/* modulo->p == NULL || residue->p == NULL ( m has been set-up ) */
|
||||
TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
|
||||
mbedtls_mpi_mod_read( &rn, &m, r_buff, buff_bytes, endian ) );
|
||||
mbedtls_mpi_mod_read( &rn, &m, buf->x, buf->len, endian ) );
|
||||
TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
|
||||
mbedtls_mpi_mod_write( &rn, &m, r_buff, buff_bytes, endian ) );
|
||||
mbedtls_mpi_mod_write( &rn, &m, buf->x, buf->len, endian ) );
|
||||
|
||||
/* Fail for r_limbs > m->limbs */
|
||||
r.limbs = m.limbs + 1;
|
||||
TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
|
||||
mbedtls_mpi_mod_read( &r, &m, r_buff, buff_bytes, endian ) );
|
||||
mbedtls_mpi_mod_read( &r, &m, buf->x, buf->len, endian ) );
|
||||
TEST_EQUAL( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
|
||||
mbedtls_mpi_mod_write( &r, &m, r_buff, buff_bytes, endian ) );
|
||||
mbedtls_mpi_mod_write( &r, &m, buf->x, buf->len, endian ) );
|
||||
r.limbs = r_limbs;
|
||||
|
||||
/* Test the read */
|
||||
TEST_EQUAL( ret, mbedtls_mpi_mod_read( &r, &m, r_buff, buff_bytes, endian ) );
|
||||
TEST_EQUAL( ret, mbedtls_mpi_mod_read( &r, &m, buf->x, buf->len, endian ) );
|
||||
|
||||
/* Test write overflow only when the representation is large and read is successful */
|
||||
if (r.limbs > 1 && ret == 0)
|
||||
TEST_EQUAL( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL,
|
||||
mbedtls_mpi_mod_write( &r, &m, r_buff, 1, endian ) );
|
||||
mbedtls_mpi_mod_write( &r, &m, buf->x, 1, endian ) );
|
||||
exit:
|
||||
mbedtls_mpi_mod_modulus_free( &m );
|
||||
mbedtls_free( N );
|
||||
mbedtls_free( R );
|
||||
mbedtls_free( r_buff );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user