Adapt uses of mbedtls_rsa_complete to removed PRNG argument

This commit is contained in:
Hanno Becker 2017-10-10 16:56:22 +01:00
parent f9e184b9df
commit 7f25f850ac
9 changed files with 19 additions and 25 deletions

View File

@ -540,7 +540,7 @@ static int pk_get_rsapubkey( unsigned char **p,
*p += len; *p += len;
if( ( ret = mbedtls_rsa_complete( rsa, NULL, NULL ) ) != 0 ) if( ( ret = mbedtls_rsa_complete( rsa ) ) != 0 )
return( MBEDTLS_ERR_PK_INVALID_PUBKEY ); return( MBEDTLS_ERR_PK_INVALID_PUBKEY );
if( *p != end ) if( *p != end )
@ -745,7 +745,7 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa,
p += len; p += len;
/* Complete the RSA private key */ /* Complete the RSA private key */
if( ( ret = mbedtls_rsa_complete( rsa, NULL, NULL ) ) != 0 ) if( ( ret = mbedtls_rsa_complete( rsa ) ) != 0 )
goto cleanup; goto cleanup;
/* Check optional parameters */ /* Check optional parameters */

View File

@ -2549,7 +2549,7 @@ int mbedtls_rsa_self_test( int verbose )
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_E ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_E ) );
MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, NULL, NULL, NULL, NULL, &K ) ); MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, NULL, NULL, NULL, NULL, &K ) );
MBEDTLS_MPI_CHK( mbedtls_rsa_complete( &rsa, NULL, NULL ) ); MBEDTLS_MPI_CHK( mbedtls_rsa_complete( &rsa ) );
if( verbose != 0 ) if( verbose != 0 )
mbedtls_printf( " RSA key validation: " ); mbedtls_printf( " RSA key validation: " );

View File

@ -149,8 +149,7 @@ int main( void )
goto exit; goto exit;
} }
if( ( ret = mbedtls_rsa_complete( &rsa, mbedtls_ctr_drbg_random, if( ( ret = mbedtls_rsa_complete( &rsa ) ) != 0 )
&ctr_drbg ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_rsa_complete returned %d\n\n", mbedtls_printf( " failed\n ! mbedtls_rsa_complete returned %d\n\n",
ret ); ret );

View File

@ -142,8 +142,7 @@ int main( int argc, char *argv[] )
goto exit; goto exit;
} }
if( ( return_val = mbedtls_rsa_complete( &rsa, mbedtls_ctr_drbg_random, if( ( return_val = mbedtls_rsa_complete( &rsa ) ) != 0 )
&ctr_drbg ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_rsa_complete returned %d\n\n", mbedtls_printf( " failed\n ! mbedtls_rsa_complete returned %d\n\n",
return_val ); return_val );

View File

@ -115,7 +115,7 @@ int main( int argc, char *argv[] )
goto exit; goto exit;
} }
if( ( ret = mbedtls_rsa_complete( &rsa, NULL, NULL ) ) != 0 ) if( ( ret = mbedtls_rsa_complete( &rsa ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_rsa_complete returned %d\n\n", mbedtls_printf( " failed\n ! mbedtls_rsa_complete returned %d\n\n",
ret ); ret );

View File

@ -361,7 +361,7 @@ void pk_rsa_decrypt_test_vec( char *cipher_hex, int mod,
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 ); TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
TEST_ASSERT( mbedtls_rsa_import( rsa, &N, &P, &Q, NULL, &E ) == 0 ); TEST_ASSERT( mbedtls_rsa_import( rsa, &N, &P, &Q, NULL, &E ) == 0 );
TEST_ASSERT( mbedtls_rsa_get_len( rsa ) == (size_t) ( mod / 8 ) ); TEST_ASSERT( mbedtls_rsa_get_len( rsa ) == (size_t) ( mod / 8 ) );
TEST_ASSERT( mbedtls_rsa_complete( rsa, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( rsa ) == 0 );
/* decryption test */ /* decryption test */
memset( output, 0, sizeof( output ) ); memset( output, 0, sizeof( output ) );

View File

@ -86,7 +86,7 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char *input_P,
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 ); TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) ); TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
TEST_ASSERT( mbedtls_rsa_complete( &ctx, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 ); TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
unhexify( message_str, message_hex_string ); unhexify( message_str, message_hex_string );
@ -142,7 +142,7 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char *input_P, int radix_Q,
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 ); TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) ); TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
TEST_ASSERT( mbedtls_rsa_complete( &ctx, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 ); TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
msg_len = unhexify( message_str, message_hex_string ); msg_len = unhexify( message_str, message_hex_string );

View File

@ -87,7 +87,7 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 ); TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) ); TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
TEST_ASSERT( mbedtls_rsa_complete( &ctx, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 ); TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
unhexify( message_str, message_hex_string ); unhexify( message_str, message_hex_string );
@ -143,7 +143,7 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char *input_P, int radix_Q,
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 ); TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) ); TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
TEST_ASSERT( mbedtls_rsa_complete( &ctx, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 ); TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
msg_len = unhexify( message_str, message_hex_string ); msg_len = unhexify( message_str, message_hex_string );

View File

@ -47,7 +47,7 @@ void mbedtls_rsa_pkcs1_sign( char *message_hex_string, int padding_mode, int dig
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 ); TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) ); TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
TEST_ASSERT( mbedtls_rsa_complete( &ctx, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 ); TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
msg_len = unhexify( message_str, message_hex_string ); msg_len = unhexify( message_str, message_hex_string );
@ -146,7 +146,7 @@ void rsa_pkcs1_sign_raw( char *message_hex_string, char *hash_result_string,
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 ); TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) ); TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
TEST_ASSERT( mbedtls_rsa_complete( &ctx, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 ); TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
unhexify( message_str, message_hex_string ); unhexify( message_str, message_hex_string );
@ -363,7 +363,7 @@ void mbedtls_rsa_pkcs1_decrypt( char *message_hex_string, int padding_mode, int
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 ); TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) ); TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
TEST_ASSERT( mbedtls_rsa_complete( &ctx, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 ); TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
unhexify( message_str, message_hex_string ); unhexify( message_str, message_hex_string );
@ -471,7 +471,7 @@ void mbedtls_rsa_private( char *message_hex_string, int mod, int radix_P, char *
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 ); TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) ); TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
TEST_ASSERT( mbedtls_rsa_complete( &ctx, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 ); TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
unhexify( message_str, message_hex_string ); unhexify( message_str, message_hex_string );
@ -916,9 +916,7 @@ void mbedtls_rsa_import( int radix_N, char *input_N,
have_E ? &E : NULL ) == 0 ); have_E ? &E : NULL ) == 0 );
} }
TEST_ASSERT( mbedtls_rsa_complete( &ctx, TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == result );
mbedtls_ctr_drbg_random,
&ctr_drbg ) == result );
/* On expected success, perform some public and private /* On expected success, perform some public and private
* key operations to check if the key is working properly. */ * key operations to check if the key is working properly. */
@ -1029,7 +1027,7 @@ void mbedtls_rsa_export( int radix_N, char *input_N,
strlen( input_D ) ? &D : NULL, strlen( input_D ) ? &D : NULL,
strlen( input_E ) ? &E : NULL ) == 0 ); strlen( input_E ) ? &E : NULL ) == 0 );
TEST_ASSERT( mbedtls_rsa_complete( &ctx, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
/* /*
* Export parameters and compare to original ones. * Export parameters and compare to original ones.
@ -1220,7 +1218,7 @@ void mbedtls_rsa_export_raw( char *input_N, char *input_P,
have_D ? bufD : NULL, lenD, have_D ? bufD : NULL, lenD,
have_E ? bufE : NULL, lenE ) == 0 ); have_E ? bufE : NULL, lenE ) == 0 );
TEST_ASSERT( mbedtls_rsa_complete( &ctx, NULL, NULL ) == 0 ); TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == 0 );
/* /*
* Export parameters and compare to original ones. * Export parameters and compare to original ones.
@ -1382,9 +1380,7 @@ void mbedtls_rsa_import_raw( char *input_N,
( lenE > 0 ) ? bufE : NULL, lenE ) == 0 ); ( lenE > 0 ) ? bufE : NULL, lenE ) == 0 );
} }
TEST_ASSERT( mbedtls_rsa_complete( &ctx, TEST_ASSERT( mbedtls_rsa_complete( &ctx ) == result );
mbedtls_ctr_drbg_random,
&ctr_drbg ) == result );
/* On expected success, perform some public and private /* On expected success, perform some public and private
* key operations to check if the key is working properly. */ * key operations to check if the key is working properly. */