From 711507a72609dc2df0b4c876f6d7505443dd719a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 22 Nov 2013 17:35:28 +0100 Subject: [PATCH] gen_prime: ensure X = 3 mod 4 always (2x speed-up) --- library/bignum.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/bignum.c b/library/bignum.c index 2a97a5902..7fac5fafb 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -1969,9 +1969,9 @@ int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag, if( ret != POLARSSL_ERR_MPI_NOT_ACCEPTABLE ) goto cleanup; - MPI_CHK( mpi_add_int( &Y, X, 1 ) ); - MPI_CHK( mpi_add_int( X, X, 2 ) ); - MPI_CHK( mpi_shift_r( &Y, 1 ) ); + /* Keep X = 3 mod 4 */ + MPI_CHK( mpi_add_int( X, X, 4 ) ); + MPI_CHK( mpi_add_int( &Y, &Y, 2 ) ); } }