From 735b8fcb0bba4b02c4c5d106b8ab416fa810d05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 13 Sep 2013 12:57:23 +0200 Subject: [PATCH] Fix blunder in 8a109f1 --- library/rsa.c | 4 ++-- tests/suites/test_suite_rsa.function | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/library/rsa.c b/library/rsa.c index d39a09b23..4929275d6 100644 --- a/library/rsa.c +++ b/library/rsa.c @@ -269,9 +269,9 @@ static int rsa_prepare_blinding( rsa_context *ctx, { /* We already have blinding values, just update them by squaring */ MPI_CHK( mpi_mul_mpi( &ctx->Vi, &ctx->Vi, &ctx->Vi ) ); - MPI_CHK( mpi_mod_mpi( &ctx->Vi, &ctx->Vi, &ctx->P ) ); + MPI_CHK( mpi_mod_mpi( &ctx->Vi, &ctx->Vi, &ctx->N ) ); MPI_CHK( mpi_mul_mpi( &ctx->Vf, &ctx->Vf, &ctx->Vf ) ); - MPI_CHK( mpi_mod_mpi( &ctx->Vf, &ctx->Vf, &ctx->P ) ); + MPI_CHK( mpi_mod_mpi( &ctx->Vf, &ctx->Vf, &ctx->N ) ); return( 0 ); } diff --git a/tests/suites/test_suite_rsa.function b/tests/suites/test_suite_rsa.function index 154b7c4eb..9e3dc118c 100644 --- a/tests/suites/test_suite_rsa.function +++ b/tests/suites/test_suite_rsa.function @@ -374,13 +374,12 @@ void rsa_private( char *message_hex_string, int mod, int radix_P, char *input_P, rsa_context ctx; mpi P1, Q1, H, G; rnd_pseudo_info rnd_info; + int i; mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G ); rsa_init( &ctx, RSA_PKCS_V15, 0 ); memset( message_str, 0x00, 1000 ); - memset( output, 0x00, 1000 ); - memset( output_str, 0x00, 1000 ); memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) ); ctx.len = mod / 8; @@ -402,12 +401,20 @@ void rsa_private( char *message_hex_string, int mod, int radix_P, char *input_P, unhexify( message_str, message_hex_string ); - TEST_ASSERT( rsa_private( &ctx, rnd_pseudo_rand, &rnd_info, message_str, output ) == result ); - if( result == 0 ) + /* repeat three times to test updating of blinding values */ + for( i = 0; i < 3; i++ ) { - hexify( output_str, output, ctx.len ); + memset( output, 0x00, 1000 ); + memset( output_str, 0x00, 1000 ); + TEST_ASSERT( rsa_private( &ctx, rnd_pseudo_rand, &rnd_info, + message_str, output ) == result ); + if( result == 0 ) + { + hexify( output_str, output, ctx.len ); - TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 ); + TEST_ASSERT( strcasecmp( (char *) output_str, + result_hex_str ) == 0 ); + } } mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );