Fix test_suite_pk.function to work on 64-bit ILP32

This change fixes a problem in the tests pk_rsa_alt() and
pk_rsa_overflow() from test_suite_pk.function that would cause a
segmentation fault. The problem is that these tests are only designed
to run in computers where the sizeof(size_t) > sizeof(unsigned int).
This commit is contained in:
Andres Amaya Garcia 2017-05-08 11:15:49 +01:00 committed by Gilles Peskine
parent ca20ced208
commit ce37ab7ada

View File

@ -423,6 +423,9 @@ void pk_rsa_overflow( )
mbedtls_pk_context pk;
size_t hash_len = (size_t)-1;
if( sizeof( size_t ) <= sizeof( unsigned int ) )
return;
mbedtls_pk_init( &pk );
TEST_ASSERT( mbedtls_pk_setup( &pk,
@ -493,9 +496,12 @@ void pk_rsa_alt( )
TEST_ASSERT( mbedtls_pk_sign( &alt, MBEDTLS_MD_NONE, hash, sizeof hash,
sig, &sig_len, rnd_std_rand, NULL ) == 0 );
#if defined(MBEDTLS_HAVE_INT64)
TEST_ASSERT( mbedtls_pk_sign( &alt, MBEDTLS_MD_NONE, hash, (size_t)-1,
NULL, NULL, rnd_std_rand, NULL ) ==
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
if( sizeof( size_t ) > sizeof( unsigned int ) )
{
TEST_ASSERT( mbedtls_pk_sign( &alt, MBEDTLS_MD_NONE, hash, (size_t)-1,
NULL, NULL, rnd_std_rand, NULL ) ==
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
}
#endif /* MBEDTLS_HAVE_INT64 */
TEST_ASSERT( sig_len == RSA_KEY_LEN );
TEST_ASSERT( mbedtls_pk_verify( &rsa, MBEDTLS_MD_NONE,