From b94081bfc18e0e53678d615213a17978eafe335c Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Wed, 5 Jan 2011 15:53:06 +0000
Subject: [PATCH] - Make A only smaller if it is larger than |X| - 1
---
library/bignum.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/library/bignum.c b/library/bignum.c
index 78e9384dd..55188b785 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -1746,8 +1746,11 @@ int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng )
for( j = 0; j < A.n * ciL; j++ )
*p++ = (unsigned char) f_rng( p_rng );
- j = mpi_msb( &A ) - mpi_msb( &W );
- MPI_CHK( mpi_shift_r( &A, j + 1 ) );
+ if( mpi_cmp_mpi( &A, &W ) >= 0 )
+ {
+ j = mpi_msb( &A ) - mpi_msb( &W );
+ MPI_CHK( mpi_shift_r( &A, j + 1 ) );
+ }
A.p[0] |= 3;
/*