Skip to content

Commit c2c6fcb

Browse files
Enable mpi_mod_int test case to take full-range MPI integers
Also add commented-out test cases that currently fail Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
1 parent 4637ed2 commit c2c6fcb

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

tests/suites/test_suite_bignum.function

+29-6
Original file line numberDiff line numberDiff line change
@@ -1172,24 +1172,47 @@ exit:
11721172
/* END_CASE */
11731173

11741174
/* BEGIN_CASE */
1175-
void mbedtls_mpi_mod_int( char * input_X, int input_Y,
1176-
int input_A, int div_result )
1175+
void mbedtls_mpi_mod_int( char * input_X, char * input_Y,
1176+
char * input_A, int mod_result )
11771177
{
11781178
mbedtls_mpi X;
1179+
mbedtls_mpi Y;
1180+
mbedtls_mpi A;
11791181
int res;
11801182
mbedtls_mpi_uint r;
1183+
11811184
mbedtls_mpi_init( &X );
1185+
mbedtls_mpi_init( &Y );
1186+
mbedtls_mpi_init( &A );
11821187

1183-
TEST_ASSERT( mbedtls_test_read_mpi( &X, input_X ) == 0 );
1184-
res = mbedtls_mpi_mod_int( &r, &X, input_Y );
1185-
TEST_ASSERT( res == div_result );
1188+
/* We use MPIs to read Y and A since the test framework limits us to
1189+
* ints, so we can't have 64-bit values */
1190+
TEST_EQUAL( mbedtls_test_read_mpi( &X, input_X ), 0 );
1191+
TEST_EQUAL( mbedtls_test_read_mpi( &Y, input_Y ), 0 );
1192+
TEST_EQUAL( mbedtls_test_read_mpi( &A, input_A ), 0 );
1193+
1194+
TEST_EQUAL( Y.n, 1 );
1195+
TEST_EQUAL( A.n, 1 );
1196+
1197+
/* Convert the MPIs for Y and A to signed mbedtls_mpi_uints */
1198+
mbedtls_mpi_uint y = Y.p[0];
1199+
if( Y.s == -1 )
1200+
y = -y;
1201+
mbedtls_mpi_uint a = A.p[0];
1202+
if( A.s == -1 )
1203+
a = -a;
1204+
1205+
res = mbedtls_mpi_mod_int( &r, &X, y );
1206+
TEST_EQUAL( res, mod_result );
11861207
if( res == 0 )
11871208
{
1188-
TEST_ASSERT( r == (mbedtls_mpi_uint) input_A );
1209+
TEST_EQUAL( r, a );
11891210
}
11901211

11911212
exit:
11921213
mbedtls_mpi_free( &X );
1214+
mbedtls_mpi_free( &Y );
1215+
mbedtls_mpi_free( &A );
11931216
}
11941217
/* END_CASE */
11951218

tests/suites/test_suite_bignum.misc.data

+28-12
Original file line numberDiff line numberDiff line change
@@ -1202,40 +1202,56 @@ Test mbedtls_mpi_mod_mpi: 0 (null) % -1
12021202
mbedtls_mpi_mod_mpi:"":"-1":"":MBEDTLS_ERR_MPI_NEGATIVE_VALUE
12031203

12041204
Base test mbedtls_mpi_mod_int #1
1205-
mbedtls_mpi_mod_int:"3e8":13:12:0
1205+
mbedtls_mpi_mod_int:"3e8":"d":"c":0
12061206

12071207
Base test mbedtls_mpi_mod_int #2 (Divide by zero)
1208-
mbedtls_mpi_mod_int:"3e8":0:0:MBEDTLS_ERR_MPI_DIVISION_BY_ZERO
1208+
mbedtls_mpi_mod_int:"3e8":"0":"0":MBEDTLS_ERR_MPI_DIVISION_BY_ZERO
12091209

12101210
Base test mbedtls_mpi_mod_int #3
1211-
mbedtls_mpi_mod_int:"-3e8":13:1:0
1211+
mbedtls_mpi_mod_int:"-3e8":"d":"1":0
12121212

12131213
Base test mbedtls_mpi_mod_int #4 (Negative modulo)
1214-
mbedtls_mpi_mod_int:"3e8":-13:0:MBEDTLS_ERR_MPI_NEGATIVE_VALUE
1214+
mbedtls_mpi_mod_int:"3e8":"-d":"0":MBEDTLS_ERR_MPI_NEGATIVE_VALUE
12151215

12161216
Base test mbedtls_mpi_mod_int #5 (Negative modulo)
1217-
mbedtls_mpi_mod_int:"-3e8":-13:0:MBEDTLS_ERR_MPI_NEGATIVE_VALUE
1217+
mbedtls_mpi_mod_int:"-3e8":"-d":"0":MBEDTLS_ERR_MPI_NEGATIVE_VALUE
12181218

12191219
Base test mbedtls_mpi_mod_int #6 (By 1)
1220-
mbedtls_mpi_mod_int:"3e8":1:0:0
1220+
mbedtls_mpi_mod_int:"3e8":"1":"0":0
12211221

12221222
Base test mbedtls_mpi_mod_int #7 (By 2)
1223-
mbedtls_mpi_mod_int:"3e9":2:1:0
1223+
mbedtls_mpi_mod_int:"3e9":"2":"1":0
12241224

12251225
Base test mbedtls_mpi_mod_int #8 (By 2)
1226-
mbedtls_mpi_mod_int:"3e8":2:0:0
1226+
mbedtls_mpi_mod_int:"3e8":"2":"0":0
12271227

12281228
Test mbedtls_mpi_mod_int: 0 (null) % 1
1229-
mbedtls_mpi_mod_int:"":1:0:0
1229+
mbedtls_mpi_mod_int:"":"1":"0":0
12301230

12311231
Test mbedtls_mpi_mod_int: 0 (null) % 2
1232-
mbedtls_mpi_mod_int:"":2:0:0
1232+
mbedtls_mpi_mod_int:"":"2":"0":0
12331233

12341234
Test mbedtls_mpi_mod_int: 0 (null) % -1
1235-
mbedtls_mpi_mod_int:"":-1:0:MBEDTLS_ERR_MPI_NEGATIVE_VALUE
1235+
mbedtls_mpi_mod_int:"":"-1":"0":MBEDTLS_ERR_MPI_NEGATIVE_VALUE
12361236

12371237
Test mbedtls_mpi_mod_int: 0 (null) % -2
1238-
mbedtls_mpi_mod_int:"":-2:0:MBEDTLS_ERR_MPI_NEGATIVE_VALUE
1238+
mbedtls_mpi_mod_int:"":"-2":"0":MBEDTLS_ERR_MPI_NEGATIVE_VALUE
1239+
1240+
# CURRENTLY FAILS
1241+
#Test mbedtls_mpi_mod_int: 230772460340063000000100500000300000010 % 5178236083361335880 -> 3386266129388798810
1242+
#depends_on:MBEDTLS_HAVE_INT64
1243+
#mbedtls_mpi_mod_int:"AD9D28BF6C4E98FDF156BF0980CEE30A":"47DCCA4847DCCA48":"2EFE6F1A7D28035A":0
1244+
1245+
Test mbedtls_mpi_mod_mpi: 230772460340063000000100500000300000010 % 5178236083361335880 -> 3386266129388798810
1246+
mbedtls_mpi_mod_mpi:"AD9D28BF6C4E98FDF156BF0980CEE30A":"47DCCA4847DCCA48":"2EFE6F1A7D28035A":0
1247+
1248+
# CURRENTLY FAILS WHEN MPIS ARE 32-BIT: WHEN FIXED, REMOVE "depends_on" LINE
1249+
Test mbedtls_mpi_mod_int: 230772460340063000000100500000300000010 % 1205652040 -> 3644370
1250+
depends_on:MBEDTLS_HAVE_INT64
1251+
mbedtls_mpi_mod_int:"AD9D28BF6C4E98FDF156BF0980CEE30A":"47DCCA48":"379BD2":0
1252+
1253+
Test mbedtls_mpi_mod_mpi: 230772460340063000000100500000300000010 % 1205652040 -> 3644370
1254+
mbedtls_mpi_mod_mpi:"AD9D28BF6C4E98FDF156BF0980CEE30A":"47DCCA48":"379BD2":0
12391255

12401256
Base test mbedtls_mpi_exp_mod #1
12411257
mbedtls_mpi_exp_mod:"17":"d":"1d":"18":0

0 commit comments

Comments
 (0)