From: Sebastien Pouliot Date: Thu, 5 Jul 2007 15:21:01 +0000 (-0000) Subject: 2007-07-05 Sebastien Pouliot X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=f1ef8e4bc5621b7e418bc2c1df5eeb4ed756dfaa;p=mono.git 2007-07-05 Sebastien Pouliot * PrimalityTests.cs: Added Test method that select which algorithm, SPP or RabinMillerTest, to use based on the prime-candidate size. Removed previous workaround (as this is both a workaround and a good fix ;-). svn path=/trunk/mcs/; revision=81398 --- diff --git a/mcs/class/Mono.Security/Mono.Math.Prime/ChangeLog b/mcs/class/Mono.Security/Mono.Math.Prime/ChangeLog index 9385c06bc4f..7ac31c94324 100644 --- a/mcs/class/Mono.Security/Mono.Math.Prime/ChangeLog +++ b/mcs/class/Mono.Security/Mono.Math.Prime/ChangeLog @@ -1,3 +1,10 @@ +2007-07-05 Sebastien Pouliot + + * PrimalityTests.cs: Added Test method that select which algorithm, + SPP or RabinMillerTest, to use based on the prime-candidate size. + Removed previous workaround (as this is both a workaround and a good + fix ;-). + 2007-07-05 Sebastien Pouliot * PrimalityTests.cs: Rewritten RabinMillerTest to be closer to the diff --git a/mcs/class/Mono.Security/Mono.Math.Prime/PrimalityTests.cs b/mcs/class/Mono.Security/Mono.Math.Prime/PrimalityTests.cs index 12d9a392b7c..d5bf8fa849a 100644 --- a/mcs/class/Mono.Security/Mono.Math.Prime/PrimalityTests.cs +++ b/mcs/class/Mono.Security/Mono.Math.Prime/PrimalityTests.cs @@ -92,6 +92,15 @@ namespace Mono.Math.Prime { } } + public static bool Test (BigInteger n, ConfidenceFactor confidence) + { + // Rabin-Miller fails with smaller primes (at least with our BigInteger code) + if (n.BitCount () < 100) + return SmallPrimeSppTest (n, confidence); + else + return RabinMillerTest (n, confidence); + } + /// /// Probabilistic prime test based on Rabin-Miller's test /// @@ -128,10 +137,7 @@ namespace Mono.Math.Prime { // Applying optimization from HAC section 4.50 (base == 2) // not a really random base but an interesting (and speedy) one - BigInteger y = null; - // FIXME: sadly there a bug that makes this fails for "small" big integers - if (n.BitCount () > 100) - y = mr.Pow (2, r); + BigInteger y = mr.Pow (2, r); // still here ? start at round 1 (round 0 was a == 2) for (int round = 0; round < t; round++) {