mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-30 00:24:16 +01:00
Address issues found by coverity
1) The MPI test for prime generation missed a return value check for a call to `mbedtls_mpi_shift_r`. This is neither critical nor new but should be fixed. 2) The RSA keygeneration example program contained code initializing an RSA context after a potentially failing call to CTR DRBG initialization, leaving the corresponding RSA context free call in the cleanup section orphaned. The commit fixes this by moving the initializtion of the RSA context prior to the first potentially failing call.
This commit is contained in:
parent
33df5b34f6
commit
b70ba9fec7
@ -70,6 +70,7 @@ int main( void )
|
||||
const char *pers = "rsa_genkey";
|
||||
|
||||
mbedtls_ctr_drbg_init( &ctr_drbg );
|
||||
mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
|
||||
mbedtls_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
@ -86,8 +87,6 @@ int main( void )
|
||||
mbedtls_printf( " ok\n . Generating the RSA key [ %d-bit ]...", KEY_SIZE );
|
||||
fflush( stdout );
|
||||
|
||||
mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
|
||||
if( ( ret = mbedtls_rsa_gen_key( &rsa, mbedtls_ctr_drbg_random, &ctr_drbg, KEY_SIZE,
|
||||
EXPONENT ) ) != 0 )
|
||||
{
|
||||
|
@ -826,7 +826,8 @@ void mbedtls_mpi_gen_prime( int bits, int safe, int ref_ret )
|
||||
TEST_ASSERT( mbedtls_mpi_is_prime( &X, rnd_std_rand, NULL ) == 0 );
|
||||
if( safe )
|
||||
{
|
||||
mbedtls_mpi_shift_r( &X, 1 ); /* X = ( X - 1 ) / 2 */
|
||||
/* X = ( X - 1 ) / 2 */
|
||||
TEST_ASSERT( mbedtls_mpi_shift_r( &X, 1 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_is_prime( &X, rnd_std_rand, NULL ) == 0 );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user