mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 12:45:39 +01:00
Fix mutex leak in RSA
mbedtls_rsa_gen_key() was not freeing the RSA object, and specifically not freeing the mutex, in some error cases. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
b9fce3cea1
commit
718972e94e
@ -570,9 +570,6 @@ int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx,
|
|||||||
RSA_VALIDATE_RET( ctx != NULL );
|
RSA_VALIDATE_RET( ctx != NULL );
|
||||||
RSA_VALIDATE_RET( f_rng != NULL );
|
RSA_VALIDATE_RET( f_rng != NULL );
|
||||||
|
|
||||||
if( nbits < 128 || exponent < 3 || nbits % 2 != 0 )
|
|
||||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the modulus is 1024 bit long or shorter, then the security strength of
|
* If the modulus is 1024 bit long or shorter, then the security strength of
|
||||||
* the RSA algorithm is less than or equal to 80 bits and therefore an error
|
* the RSA algorithm is less than or equal to 80 bits and therefore an error
|
||||||
@ -585,6 +582,12 @@ int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx,
|
|||||||
mbedtls_mpi_init( &G );
|
mbedtls_mpi_init( &G );
|
||||||
mbedtls_mpi_init( &L );
|
mbedtls_mpi_init( &L );
|
||||||
|
|
||||||
|
if( nbits < 128 || exponent < 3 || nbits % 2 != 0 )
|
||||||
|
{
|
||||||
|
ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* find primes P and Q with Q < P so that:
|
* find primes P and Q with Q < P so that:
|
||||||
* 1. |P-Q| > 2^( nbits / 2 - 100 )
|
* 1. |P-Q| > 2^( nbits / 2 - 100 )
|
||||||
@ -662,7 +665,9 @@ cleanup:
|
|||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
mbedtls_rsa_free( ctx );
|
mbedtls_rsa_free( ctx );
|
||||||
return( MBEDTLS_ERR_RSA_KEY_GEN_FAILED + ret );
|
if( ( -ret & ~0x7f ) == 0 )
|
||||||
|
ret = MBEDTLS_ERR_RSA_KEY_GEN_FAILED + ret;
|
||||||
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
Loading…
Reference in New Issue
Block a user