gen_prime: ensure X = 3 mod 4 always (2x speed-up)

This commit is contained in:
Manuel Pégourié-Gonnard 2013-11-22 17:35:28 +01:00
parent d1bac4ae55
commit 711507a726

View file

@ -1969,9 +1969,9 @@ int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag,
if( ret != POLARSSL_ERR_MPI_NOT_ACCEPTABLE ) if( ret != POLARSSL_ERR_MPI_NOT_ACCEPTABLE )
goto cleanup; goto cleanup;
MPI_CHK( mpi_add_int( &Y, X, 1 ) ); /* Keep X = 3 mod 4 */
MPI_CHK( mpi_add_int( X, X, 2 ) ); MPI_CHK( mpi_add_int( X, X, 4 ) );
MPI_CHK( mpi_shift_r( &Y, 1 ) ); MPI_CHK( mpi_add_int( &Y, &Y, 2 ) );
} }
} }