mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2026-01-06 06:28:56 +01:00
Refactored RSA to have random generator in every RSA operation
Primarily so that rsa_private() receives an RNG for blinding purposes.
This commit is contained in:
parent
ca174fef80
commit
548957dd49
11 changed files with 132 additions and 49 deletions
|
|
@ -69,6 +69,7 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
|
|||
rsa_context ctx;
|
||||
mpi P1, Q1, H, G;
|
||||
size_t output_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
((void) seed);
|
||||
|
||||
mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
|
||||
|
|
@ -77,13 +78,14 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
|
|||
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 + ( ( mod % 8 ) ? 1 : 0 );
|
||||
TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
|
||||
|
||||
|
||||
TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
|
||||
TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
|
||||
TEST_ASSERT( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
|
||||
|
|
@ -97,7 +99,7 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
|
|||
|
||||
unhexify( message_str, message_hex_string );
|
||||
|
||||
TEST_ASSERT( rsa_pkcs1_decrypt( &ctx, RSA_PRIVATE, &output_len, message_str, output, 1000 ) == result );
|
||||
TEST_ASSERT( rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, RSA_PRIVATE, &output_len, message_str, output, 1000 ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
|
@ -203,7 +205,7 @@ void pkcs1_rsassa_pss_verify( int mod, int radix_N, char *input_N, int radix_E,
|
|||
if( md_info_from_type( digest ) != NULL )
|
||||
TEST_ASSERT( md( md_info_from_type( digest ), message_str, msg_len, hash_result ) == 0 );
|
||||
|
||||
TEST_ASSERT( rsa_pkcs1_verify( &ctx, RSA_PUBLIC, digest, 0, hash_result, result_str ) == result );
|
||||
TEST_ASSERT( rsa_pkcs1_verify( &ctx, NULL, NULL, RSA_PUBLIC, digest, 0, hash_result, result_str ) == result );
|
||||
|
||||
rsa_free( &ctx );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue