Author: spouliot
Date: 2007-07-04 08:27:36 -0400 (Wed, 04 Jul 2007)
New Revision: 81329

Modified:
   trunk/mcs/class/Mono.Security/Mono.Math/BigInteger.cs
   trunk/mcs/class/Mono.Security/Mono.Math/ChangeLog
Log:
2007-07-04  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * BigInteger.cs: In some condition the optimized (4 variants) OddPow
        expose a bug, mainly with small numbers. This simpler version, square
        and multiply, doesn't expose as much the bug (almost all new prime 
        tests pass).



Modified: trunk/mcs/class/Mono.Security/Mono.Math/BigInteger.cs
===================================================================
--- trunk/mcs/class/Mono.Security/Mono.Math/BigInteger.cs       2007-07-04 
11:42:16 UTC (rev 81328)
+++ trunk/mcs/class/Mono.Security/Mono.Math/BigInteger.cs       2007-07-04 
12:27:36 UTC (rev 81329)
@@ -1087,6 +1087,24 @@
                                return diff;
                        }
 
+                       public BigInteger Pow (BigInteger a, BigInteger k)
+                       {
+                               BigInteger b = new BigInteger (1);
+                               if (k == 0)
+                                       return b;
+
+                               BigInteger A = a;
+                               if (k.TestBit (0))
+                                       b = a;
+
+                               for (int i = 1; i < k.BitCount (); i++) {
+                                       A = Multiply (A, A);
+                                       if (k.TestBit (i))
+                                               b = Multiply (A, b);
+                               }
+                               return b;
+                       }
+#if false
                        public BigInteger Pow (BigInteger b, BigInteger exp)
                        {
                                if ((mod.data [0] & 1) == 1) return OddPow (b, 
exp);
@@ -1157,7 +1175,7 @@
                                Montgomery.Reduce (resultNum, mod, mPrime);
                                return resultNum;
                        }
-
+#endif
                        #region Pow Small Base
 
                        // TODO: Make tests for this, not really needed b/c 
prime stuff
@@ -1167,6 +1185,11 @@
 #endif 
                        public BigInteger Pow (uint b, BigInteger exp)
                        {
+                               return Pow (new BigInteger (b), exp);
+                       }
+#if false
+                       public BigInteger Pow (uint b, BigInteger exp)
+                       {
 //                             if (b != 2) {
                                        if ((mod.data [0] & 1) == 1)
                                                return OddPow (b, exp);
@@ -1526,7 +1549,8 @@
                                resultNum = Montgomery.Reduce (resultNum, mod, 
mPrime);
                                return resultNum;
                        }
-*/                     
+*/
+#endif
                        #endregion
                }
 

Modified: trunk/mcs/class/Mono.Security/Mono.Math/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Security/Mono.Math/ChangeLog   2007-07-04 11:42:16 UTC 
(rev 81328)
+++ trunk/mcs/class/Mono.Security/Mono.Math/ChangeLog   2007-07-04 12:27:36 UTC 
(rev 81329)
@@ -1,3 +1,10 @@
+2007-07-04  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * BigInteger.cs: In some condition the optimized (4 variants) OddPow
+       expose a bug, mainly with small numbers. This simpler version, square
+       and multiply, doesn't expose as much the bug (almost all new prime 
+       tests pass).
+
 2007-07-03  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * BigInteger.cs: Avoid Miller-Rabin test for small primes (we have a 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to