mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-11 08:55:27 +00:00
Fix odd bitlength RSA key generation
Fix issue that caused a hang up when generating RSA keys of odd bitlength.
This commit is contained in:
parent
4dfecabb97
commit
d61fc6881a
|
@ -7,6 +7,7 @@ Bugfix
|
||||||
arguments where the same (in-place doubling). Found and fixed by Janos
|
arguments where the same (in-place doubling). Found and fixed by Janos
|
||||||
Follath. #309
|
Follath. #309
|
||||||
* Fix issue in Makefile that prevented building using armar. #386
|
* Fix issue in Makefile that prevented building using armar. #386
|
||||||
|
* Fix issue that caused a hang up when generating RSA keys of odd bitlength
|
||||||
|
|
||||||
Changes
|
Changes
|
||||||
* On ARM platforms, when compiling with -O0 with GCC, Clang or armcc5,
|
* On ARM platforms, when compiling with -O0 with GCC, Clang or armcc5,
|
||||||
|
|
|
@ -97,7 +97,8 @@ int rsa_gen_key( rsa_context *ctx,
|
||||||
if( f_rng == NULL || nbits < 128 || exponent < 3 )
|
if( f_rng == NULL || nbits < 128 || exponent < 3 )
|
||||||
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
|
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
|
||||||
|
|
||||||
mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
|
mpi_init( &P1 ); mpi_init( &Q1 );
|
||||||
|
mpi_init( &H ); mpi_init( &G );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* find primes P and Q with Q < P so that:
|
* find primes P and Q with Q < P so that:
|
||||||
|
@ -107,14 +108,15 @@ int rsa_gen_key( rsa_context *ctx,
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
MPI_CHK( mpi_gen_prime( &ctx->P, ( nbits + 1 ) >> 1, 0,
|
MPI_CHK( mpi_gen_prime( &ctx->P, nbits >> 1, 0,
|
||||||
f_rng, p_rng ) );
|
f_rng, p_rng ) );
|
||||||
|
|
||||||
MPI_CHK( mpi_gen_prime( &ctx->Q, ( nbits + 1 ) >> 1, 0,
|
if( nbits % 2 )
|
||||||
|
MPI_CHK( mpi_gen_prime( &ctx->Q, ( nbits >> 1 ) + 1, 0,
|
||||||
|
f_rng, p_rng ) );
|
||||||
|
else
|
||||||
|
MPI_CHK( mpi_gen_prime( &ctx->Q, nbits >> 1, 0,
|
||||||
f_rng, p_rng ) );
|
f_rng, p_rng ) );
|
||||||
|
|
||||||
if( mpi_cmp_mpi( &ctx->P, &ctx->Q ) < 0 )
|
|
||||||
mpi_swap( &ctx->P, &ctx->Q );
|
|
||||||
|
|
||||||
if( mpi_cmp_mpi( &ctx->P, &ctx->Q ) == 0 )
|
if( mpi_cmp_mpi( &ctx->P, &ctx->Q ) == 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue