2007-07-05 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 5 Jul 2007 15:21:01 +0000 (15:21 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 5 Jul 2007 15:21:01 +0000 (15:21 -0000)
* 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

mcs/class/Mono.Security/Mono.Math.Prime/ChangeLog
mcs/class/Mono.Security/Mono.Math.Prime/PrimalityTests.cs

index 9385c06bc4f41b7004da550f85bbb3fba1a7198d..7ac31c94324e7014c3ccd88a75d8c18522aadcb9 100644 (file)
@@ -1,3 +1,10 @@
+2007-07-05  Sebastien Pouliot  <sebastien@ximian.com> 
+
+       * 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  <sebastien@ximian.com>
 
        * PrimalityTests.cs: Rewritten RabinMillerTest to be closer to the 
index 12d9a392b7c1b33d38dbee7e7a19b9d8377d181e..d5bf8fa849a672dce86399ba41b2333a1608ca59 100644 (file)
@@ -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);
+               }
+
                /// <summary>
                ///     Probabilistic prime test based on Rabin-Miller's test
                /// </summary>
@@ -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++) {