Skip to content

Commit 5c307b9

Browse files
Use mbedtls_mpi_sint not mbedtls_mpi_uint in mpi_mod_int test
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
1 parent c2c6fcb commit 5c307b9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/suites/test_suite_bignum.function

+13-3
Original file line numberDiff line numberDiff line change
@@ -1194,11 +1194,21 @@ void mbedtls_mpi_mod_int( char * input_X, char * input_Y,
11941194
TEST_EQUAL( Y.n, 1 );
11951195
TEST_EQUAL( A.n, 1 );
11961196

1197-
/* Convert the MPIs for Y and A to signed mbedtls_mpi_uints */
1198-
mbedtls_mpi_uint y = Y.p[0];
1197+
/* Convert the MPIs for Y and A to (signed) mbedtls_mpi_sints */
1198+
1199+
/* Since we're converting sign+magnitude to two's complement, we lose one
1200+
* bit of value in the output. This means there are some values we can't
1201+
* represent, e.g. (hex) -A0000000 on 32-bit systems. These are technically
1202+
* invalid test cases, so could be considered "won't happen", but they are
1203+
* easy to test for, and this helps guard against human error. */
1204+
1205+
mbedtls_mpi_sint y = (mbedtls_mpi_sint) Y.p[0];
1206+
TEST_ASSERT( y >= 0 ); /* If y < 0 here, we can't make negative y */
11991207
if( Y.s == -1 )
12001208
y = -y;
1201-
mbedtls_mpi_uint a = A.p[0];
1209+
1210+
mbedtls_mpi_sint a = (mbedtls_mpi_sint) A.p[0];
1211+
TEST_ASSERT( a >= 0 ); /* Same goes for a */
12021212
if( A.s == -1 )
12031213
a = -a;
12041214

0 commit comments

Comments
 (0)