Reduce stack usage of test_suite_pkcs1_v21

Reduce the stack usage of the `test_suite_pkcs1_v21` by reducing the
size of the buffers used in the tests, to a reasonable big enough size,
and change the size sent to the API to sizeof output.
This commit is contained in:
Ron Eldor 2018-11-22 15:49:49 +02:00
parent b3d3973264
commit dd4277f70d

View file

@ -14,10 +14,10 @@ void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char *input_N, int radix_E,
char *message_hex_string, char *seed,
char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char output[1000];
unsigned char output_str[1000];
unsigned char rnd_buf[1000];
unsigned char message_str[87];
unsigned char output[256];
unsigned char output_str[513];
unsigned char rnd_buf[20];
mbedtls_rsa_context ctx;
size_t msg_len;
rnd_buf_info info;
@ -28,9 +28,9 @@ void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char *input_N, int radix_E,
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
memset( message_str, 0x00, sizeof( message_str ) );
memset( output, 0x00, sizeof( output ) );
memset( output_str, 0x00, sizeof( output_str ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
@ -61,9 +61,9 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
int hash, char *result_hex_str, char *seed,
char *message_hex_string, int result )
{
unsigned char message_str[1000];
unsigned char output[1000];
unsigned char output_str[1000];
unsigned char message_str[256];
unsigned char output[256];
unsigned char output_str[513];
mbedtls_rsa_context ctx;
size_t output_len;
rnd_pseudo_info rnd_info;
@ -75,9 +75,9 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
memset( message_str, 0x00, sizeof( message_str) );
memset( output, 0x00, sizeof( output ) );
memset( output_str, 0x00, sizeof( output_str) );
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
@ -92,11 +92,12 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
unhexify( message_str, message_hex_string );
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str, output, 1000 ) == result );
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info,
MBEDTLS_RSA_PRIVATE, &output_len,
message_str, output, sizeof( output ) ) == result );
if( result == 0 )
{
hexify( output_str, output, ctx.len );
TEST_ASSERT( strncasecmp( (char *) output_str, result_hex_str, strlen( result_hex_str ) ) == 0 );
}
@ -114,11 +115,11 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char *input_P, int radix_Q,
char *message_hex_string, char *salt,
char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char hash_result[1000];
unsigned char output[1000];
unsigned char output_str[1000];
unsigned char rnd_buf[1000];
unsigned char message_str[255];
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
unsigned char output[256];
unsigned char output_str[513];
unsigned char rnd_buf[20];
mbedtls_rsa_context ctx;
size_t msg_len;
rnd_buf_info info;
@ -131,10 +132,10 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char *input_P, int radix_Q,
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
memset( message_str, 0x00, sizeof( message_str ) );
memset( hash_result, 0x00, sizeof( hash_result ) );
memset( output, 0x00, sizeof( output ) );
memset( output_str, 0x00, sizeof( output_str ) );
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
@ -174,9 +175,9 @@ void pkcs1_rsassa_pss_verify( int mod, int radix_N, char *input_N, int radix_E,
char *message_hex_string, char *salt,
char *result_hex_str, int result )
{
unsigned char message_str[1000];
unsigned char hash_result[1000];
unsigned char result_str[1000];
unsigned char message_str[255];
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
unsigned char result_str[256];
mbedtls_rsa_context ctx;
size_t msg_len;
mbedtls_mpi N, E;
@ -184,9 +185,9 @@ void pkcs1_rsassa_pss_verify( int mod, int radix_N, char *input_N, int radix_E,
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( result_str, 0x00, 1000 );
memset( message_str, 0x00, sizeof( message_str ) );
memset( hash_result, 0x00, sizeof( hash_result ) );
memset( result_str, 0x00, sizeof( result_str ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
@ -222,19 +223,18 @@ void pkcs1_rsassa_pss_verify_ext( int mod,
int result_simple,
int result_full )
{
unsigned char message_str[1000];
unsigned char hash_result[1000];
unsigned char result_str[1000];
unsigned char message_str[163];
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
unsigned char result_str[256];
mbedtls_rsa_context ctx;
size_t msg_len, hash_len;
mbedtls_mpi N, E;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, ctx_hash );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( result_str, 0x00, 1000 );
memset( message_str, 0x00, sizeof( message_str ) );
memset( hash_result, 0x00, sizeof( hash_result ) );
memset( result_str, 0x00, sizeof( result_str ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );