Skip to content

Commit 635888b

Browse files
Ron EldorRon Eldor
authored andcommitted
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.
1 parent 6fd1aa0 commit 635888b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tests/suites/test_suite_pkcs1_v15.function

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N,
1414
data_t * message_str, data_t * rnd_buf,
1515
data_t * result_hex_str, int result )
1616
{
17-
unsigned char output[1000];
17+
unsigned char output[128];
1818
mbedtls_rsa_context ctx;
1919
rnd_buf_info info;
2020
mbedtls_mpi N, E;
@@ -24,7 +24,7 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N,
2424

2525
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
2626
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
27-
memset( output, 0x00, 1000 );
27+
memset( output, 0x00, sizeof( output ) );
2828

2929
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
3030
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,
5454
char * seed, data_t * message_str,
5555
int result )
5656
{
57-
unsigned char output[1000];
57+
unsigned char output[128];
5858
mbedtls_rsa_context ctx;
5959
size_t output_len;
6060
rnd_pseudo_info rnd_info;
@@ -65,7 +65,7 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P,
6565
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
6666
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
6767

68-
memset( output, 0x00, 1000 );
68+
memset( output, 0x00, sizeof( output ) );
6969
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
7070

7171
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
@@ -253,8 +253,8 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q,
253253
data_t * message_str, data_t * rnd_buf,
254254
data_t * result_hex_str, int result )
255255
{
256-
unsigned char hash_result[1000];
257-
unsigned char output[1000];
256+
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
257+
unsigned char output[128];
258258
mbedtls_rsa_context ctx;
259259
mbedtls_mpi N, P, Q, E;
260260
rnd_buf_info info;
@@ -266,8 +266,8 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q,
266266
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
267267
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
268268

269-
memset( hash_result, 0x00, 1000 );
270-
memset( output, 0x00, 1000 );
269+
memset( hash_result, 0x00, sizeof( hash_result ) );
270+
memset( output, 0x00, sizeof( output ) );
271271

272272
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
273273
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
@@ -303,14 +303,14 @@ void pkcs1_rsassa_v15_verify( int mod, int radix_N, char * input_N,
303303
int hash, data_t * message_str, char * salt,
304304
data_t * result_str, int result )
305305
{
306-
unsigned char hash_result[1000];
306+
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
307307
mbedtls_rsa_context ctx;
308308
mbedtls_mpi N, E;
309309
((void) salt);
310310

311311
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
312312
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
313-
memset( hash_result, 0x00, 1000 );
313+
memset( hash_result, 0x00, sizeof( hash_result ) );
314314

315315
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
316316
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );

0 commit comments

Comments
 (0)