- Added initialization for RSA where needed
diff --git a/library/rsa.c b/library/rsa.c
index e789fff..a51d4f7 100644
--- a/library/rsa.c
+++ b/library/rsa.c
@@ -701,6 +701,14 @@
#define RSA_PT "\xAA\xBB\xCC\x03\x02\x01\x00\xFF\xFF\xFF\xFF\xFF" \
"\x11\x22\x33\x0A\x0B\x0C\xCC\xDD\xDD\xDD\xDD\xDD"
+static int myrand( void *rng_state )
+{
+ if( rng_state != NULL )
+ rng_state = NULL;
+
+ return( rand() );
+}
+
/*
* Checkup routine
*/
@@ -713,7 +721,7 @@
unsigned char rsa_decrypted[PT_LEN];
unsigned char rsa_ciphertext[KEY_LEN];
- memset( &rsa, 0, sizeof( rsa_context ) );
+ rsa_init( &rsa, RSA_PKCS_V15, 0, &myrand, NULL );
rsa.len = KEY_LEN;
mpi_read_string( &rsa.N , 16, RSA_N );
diff --git a/tests/suites/test_suite_rsa.function b/tests/suites/test_suite_rsa.function
index ed6cbf0..896eebb 100644
--- a/tests/suites/test_suite_rsa.function
+++ b/tests/suites/test_suite_rsa.function
@@ -8,6 +8,14 @@
#include <polarssl/sha2.h>
#include <polarssl/sha4.h>
#include <polarssl/havege.h>
+
+static int myrand( void *rng_state )
+{
+ if( rng_state != NULL )
+ rng_state = NULL;
+
+ return( rand() );
+}
END_HEADER
BEGIN_CASE
@@ -22,7 +30,7 @@
int msg_len;
mpi_init( &P1, &Q1, &H, &G, NULL );
- rsa_init( &ctx, {padding_mode}, 0, NULL, NULL );
+ rsa_init( &ctx, {padding_mode}, 0, &myrand, NULL );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
@@ -107,7 +115,7 @@
rsa_context ctx;
int msg_len;
- rsa_init( &ctx, {padding_mode}, 0, NULL, NULL );
+ rsa_init( &ctx, {padding_mode}, 0, &myrand, NULL );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( result_str, 0x00, 1000 );
@@ -178,7 +186,7 @@
int msg_len, hash_len;
mpi_init( &P1, &Q1, &H, &G, NULL );
- rsa_init( &ctx, {padding_mode}, 0, NULL, NULL );
+ rsa_init( &ctx, {padding_mode}, 0, &myrand, NULL );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
@@ -222,7 +230,7 @@
rsa_context ctx;
int msg_len, hash_len;
- rsa_init( &ctx, {padding_mode}, 0, NULL, NULL );
+ rsa_init( &ctx, {padding_mode}, 0, &myrand, NULL );
memset( message_str, 0x00, 1000 );
memset( hash_result, 0x00, 1000 );
memset( result_str, 0x00, 1000 );
@@ -250,7 +258,7 @@
rsa_context ctx;
int msg_len;
- rsa_init( &ctx, {padding_mode}, 0, NULL, NULL );
+ rsa_init( &ctx, {padding_mode}, 0, &myrand, NULL );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
@@ -284,7 +292,7 @@
int output_len;
mpi_init( &P1, &Q1, &H, &G, NULL );
- rsa_init( &ctx, {padding_mode}, 0, NULL, NULL );
+ rsa_init( &ctx, {padding_mode}, 0, &myrand, NULL );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
@@ -328,7 +336,7 @@
unsigned char output_str[1000];
rsa_context ctx;
- rsa_init( &ctx, RSA_PKCS_V15, 0, NULL, NULL );
+ rsa_init( &ctx, RSA_PKCS_V15, 0, &myrand, NULL );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
memset( output_str, 0x00, 1000 );
@@ -361,7 +369,7 @@
mpi P1, Q1, H, G;
mpi_init( &P1, &Q1, &H, &G, NULL );
- rsa_init( &ctx, RSA_PKCS_V15, 0, NULL, NULL );
+ rsa_init( &ctx, RSA_PKCS_V15, 0, &myrand, NULL );
memset( message_str, 0x00, 1000 );
memset( output, 0x00, 1000 );
@@ -411,7 +419,7 @@
{
rsa_context ctx;
- rsa_init( &ctx, RSA_PKCS_V15, 0, NULL, NULL );
+ rsa_init( &ctx, RSA_PKCS_V15, 0, &myrand, NULL );
if( strlen( {input_N} ) )
{
@@ -431,7 +439,7 @@
{
rsa_context ctx;
- rsa_init( &ctx, RSA_PKCS_V15, 0, NULL, NULL );
+ rsa_init( &ctx, RSA_PKCS_V15, 0, &myrand, NULL );
ctx.len = {mod} / 8;
if( strlen( {input_P} ) )