Reduce stack usage of test_suite_pkcs1_v15

Reduce the stack usage of the `test_suite_pkcs1_v15` by reducing the
size of the buffers used in the tests, to a reasonable big enough size.
This commit is contained in:
Ron Eldor 2018-11-25 15:54:52 +02:00
parent 5d7254a091
commit 3adb981383

View File

@ -14,7 +14,7 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N,
data_t * message_str, data_t * rnd_buf, data_t * message_str, data_t * rnd_buf,
data_t * result_hex_str, int result ) data_t * result_hex_str, int result )
{ {
unsigned char output[1000]; unsigned char output[128];
mbedtls_rsa_context ctx; mbedtls_rsa_context ctx;
rnd_buf_info info; rnd_buf_info info;
mbedtls_mpi N, E; mbedtls_mpi N, E;
@ -24,7 +24,7 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N,
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash ); mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
memset( output, 0x00, 1000 ); memset( output, 0x00, sizeof( output ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
@ -54,7 +54,7 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P,
char * seed, data_t * message_str, char * seed, data_t * message_str,
int result ) int result )
{ {
unsigned char output[1000]; unsigned char output[128];
mbedtls_rsa_context ctx; mbedtls_rsa_context ctx;
size_t output_len; size_t output_len;
rnd_pseudo_info rnd_info; rnd_pseudo_info rnd_info;
@ -65,7 +65,7 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P,
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash ); mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
memset( output, 0x00, 1000 ); memset( output, 0x00, sizeof( output ) );
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) ); memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
@ -248,8 +248,8 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q,
data_t * message_str, data_t * rnd_buf, data_t * message_str, data_t * rnd_buf,
data_t * result_hex_str, int result ) data_t * result_hex_str, int result )
{ {
unsigned char hash_result[1000]; unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
unsigned char output[1000]; unsigned char output[128];
mbedtls_rsa_context ctx; mbedtls_rsa_context ctx;
mbedtls_mpi N, P, Q, E; mbedtls_mpi N, P, Q, E;
rnd_buf_info info; rnd_buf_info info;
@ -261,8 +261,8 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q,
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash ); mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
memset( hash_result, 0x00, 1000 ); memset( hash_result, 0x00, sizeof( hash_result ) );
memset( output, 0x00, 1000 ); memset( output, 0x00, sizeof( output ) );
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
@ -298,14 +298,14 @@ void pkcs1_rsassa_v15_verify( int mod, int radix_N, char * input_N,
int hash, data_t * message_str, char * salt, int hash, data_t * message_str, char * salt,
data_t * result_str, int result ) data_t * result_str, int result )
{ {
unsigned char hash_result[1000]; unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
mbedtls_rsa_context ctx; mbedtls_rsa_context ctx;
mbedtls_mpi N, E; mbedtls_mpi N, E;
((void) salt); ((void) salt);
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash ); mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
memset( hash_result, 0x00, 1000 ); memset( hash_result, 0x00, sizeof( hash_result ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );