Skip to content

Commit

Permalink
- Added initialization for RSA where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Bakker committed Jul 18, 2010
1 parent b924f04 commit 545570e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
10 changes: 9 additions & 1 deletion library/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ void rsa_free( rsa_context *ctx )
#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
*/
Expand All @@ -713,7 +721,7 @@ int rsa_self_test( int verbose )
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 );
Expand Down
28 changes: 18 additions & 10 deletions tests/suites/test_suite_rsa.function
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ BEGIN_HEADER
#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
Expand All @@ -22,7 +30,7 @@ rsa_pkcs1_sign:message_hex_string:padding_mode:digest:mod:radix_P:input_P:radix_
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 );
Expand Down Expand Up @@ -107,7 +115,7 @@ rsa_pkcs1_verify:message_hex_string:padding_mode:digest:mod:radix_N:input_N:radi
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 );
Expand Down Expand Up @@ -178,7 +186,7 @@ rsa_pkcs1_sign_raw:message_hex_string:hash_result_string:padding_mode:mod:radix_
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 );
Expand Down Expand Up @@ -222,7 +230,7 @@ rsa_pkcs1_verify_raw:message_hex_string:hash_result_string:padding_mode:mod:radi
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 );
Expand Down Expand Up @@ -250,7 +258,7 @@ rsa_pkcs1_encrypt:message_hex_string:padding_mode:mod:radix_N:input_N:radix_E:in
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 );
Expand Down Expand Up @@ -284,7 +292,7 @@ rsa_pkcs1_decrypt:message_hex_string:padding_mode:mod:radix_P:input_P:radix_Q:in
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 );
Expand Down Expand Up @@ -328,7 +336,7 @@ rsa_public:message_hex_string:mod:radix_N:input_N:radix_E:input_E:result_hex_str
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 );
Expand Down Expand Up @@ -361,7 +369,7 @@ rsa_private:message_hex_string:mod:radix_P:input_P:radix_Q:input_Q:radix_N:input
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 );
Expand Down Expand Up @@ -411,7 +419,7 @@ rsa_check_pubkey:radix_N:input_N:radix_E:input_E:result
{
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} ) )
{
Expand All @@ -431,7 +439,7 @@ rsa_check_privkey:mod:radix_P:input_P:radix_Q:input_Q:radix_N:input_N:radix_E:in
{
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} ) )
Expand Down

0 comments on commit 545570e

Please sign in to comment.