Remove dead code from BigInteger since it confuse some people
authorSebastien Pouliot <sebastien@ximian.com>
Mon, 18 Oct 2010 20:37:52 +0000 (16:37 -0400)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 19 Oct 2010 12:57:38 +0000 (08:57 -0400)
* corlib/Mono.Math/BigInteger.cs:
* Mono.Security/Mono.Math/BigInteger.cs:
Remove Montgomery internal inner class since it's buggy, has not
been used for years and confuse some people (seeing ghosts of
CVE-2007-5197)

mcs/class/Mono.Security/Mono.Math/BigInteger.cs
mcs/class/corlib/Mono.Math/BigInteger.cs

index c4bb85b04daf8ddf117795fb0548fed9bcb0648e..3d6987216802b217cf3e19be7234f2ec5d776a81 100644 (file)
@@ -1558,92 +1558,6 @@ namespace Mono.Math {
                        #endregion
                }
 
-               internal sealed class Montgomery {
-
-                       private Montgomery () 
-                       {
-                       }
-
-                       public static uint Inverse (uint n)
-                       {
-                               uint y = n, z;
-
-                               while ((z = n * y) != 1)
-                                       y *= 2 - z;
-
-                               return (uint)-y;
-                       }
-
-                       public static BigInteger ToMont (BigInteger n, BigInteger m)
-                       {
-                               n.Normalize (); m.Normalize ();
-
-                               n <<= (int)m.length * 32;
-                               n %= m;
-                               return n;
-                       }
-
-                       public static unsafe BigInteger Reduce (BigInteger n, BigInteger m, uint mPrime)
-                       {
-                               BigInteger A = n;
-                               fixed (uint* a = A.data, mm = m.data) {
-                                       for (uint i = 0; i < m.length; i++) {
-                                               // The mod here is taken care of by the CPU,
-                                               // since the multiply will overflow.
-                                               uint u_i = a [0] * mPrime /* % 2^32 */;
-
-                                               //
-                                               // A += u_i * m;
-                                               // A >>= 32
-                                               //
-
-                                               // mP = Position in mod
-                                               // aSP = the source of bits from a
-                                               // aDP = destination for bits
-                                               uint* mP = mm, aSP = a, aDP = a;
-
-                                               ulong c = (ulong)u_i * ((ulong)*(mP++)) + *(aSP++);
-                                               c >>= 32;
-                                               uint j = 1;
-
-                                               // Multiply and add
-                                               for (; j < m.length; j++) {
-                                                       c += (ulong)u_i * (ulong)*(mP++) + *(aSP++);
-                                                       *(aDP++) = (uint)c;
-                                                       c >>= 32;
-                                               }
-
-                                               // Account for carry
-                                               // TODO: use a better loop here, we dont need the ulong stuff
-                                               for (; j < A.length; j++) {
-                                                       c += *(aSP++);
-                                                       *(aDP++) = (uint)c;
-                                                       c >>= 32;
-                                                       if (c == 0) {j++; break;}
-                                               }
-                                               // Copy the rest
-                                               for (; j < A.length; j++) {
-                                                       *(aDP++) = *(aSP++);
-                                               }
-
-                                               *(aDP++) = (uint)c;
-                                       }
-
-                                       while (A.length > 1 && a [A.length-1] == 0) A.length--;
-
-                               }
-                               if (A >= m) Kernel.MinusEq (A, m);
-
-                               return A;
-                       }
-#if _NOT_USED_
-                       public static BigInteger Reduce (BigInteger n, BigInteger m)
-                       {
-                               return Reduce (n, m, Inverse (m.data [0]));
-                       }
-#endif
-               }
-
                /// <summary>
                /// Low level functions for the BigInteger
                /// </summary>
index 569200d84ce00f79a4a83199d59f9ec1f4284b7d..0356d0a166487af7ffae6befcd7c59b362d180d0 100644 (file)
@@ -1562,92 +1562,6 @@ namespace Mono.Math {
                        #endregion
                }
 
-               internal sealed class Montgomery {
-
-                       private Montgomery () 
-                       {
-                       }
-
-                       public static uint Inverse (uint n)
-                       {
-                               uint y = n, z;
-
-                               while ((z = n * y) != 1)
-                                       y *= 2 - z;
-
-                               return (uint)-y;
-                       }
-
-                       public static BigInteger ToMont (BigInteger n, BigInteger m)
-                       {
-                               n.Normalize (); m.Normalize ();
-
-                               n <<= (int)m.length * 32;
-                               n %= m;
-                               return n;
-                       }
-
-                       public static unsafe BigInteger Reduce (BigInteger n, BigInteger m, uint mPrime)
-                       {
-                               BigInteger A = n;
-                               fixed (uint* a = A.data, mm = m.data) {
-                                       for (uint i = 0; i < m.length; i++) {
-                                               // The mod here is taken care of by the CPU,
-                                               // since the multiply will overflow.
-                                               uint u_i = a [0] * mPrime /* % 2^32 */;
-
-                                               //
-                                               // A += u_i * m;
-                                               // A >>= 32
-                                               //
-
-                                               // mP = Position in mod
-                                               // aSP = the source of bits from a
-                                               // aDP = destination for bits
-                                               uint* mP = mm, aSP = a, aDP = a;
-
-                                               ulong c = (ulong)u_i * ((ulong)*(mP++)) + *(aSP++);
-                                               c >>= 32;
-                                               uint j = 1;
-
-                                               // Multiply and add
-                                               for (; j < m.length; j++) {
-                                                       c += (ulong)u_i * (ulong)*(mP++) + *(aSP++);
-                                                       *(aDP++) = (uint)c;
-                                                       c >>= 32;
-                                               }
-
-                                               // Account for carry
-                                               // TODO: use a better loop here, we dont need the ulong stuff
-                                               for (; j < A.length; j++) {
-                                                       c += *(aSP++);
-                                                       *(aDP++) = (uint)c;
-                                                       c >>= 32;
-                                                       if (c == 0) {j++; break;}
-                                               }
-                                               // Copy the rest
-                                               for (; j < A.length; j++) {
-                                                       *(aDP++) = *(aSP++);
-                                               }
-
-                                               *(aDP++) = (uint)c;
-                                       }
-
-                                       while (A.length > 1 && a [A.length-1] == 0) A.length--;
-
-                               }
-                               if (A >= m) Kernel.MinusEq (A, m);
-
-                               return A;
-                       }
-#if _NOT_USED_
-                       public static BigInteger Reduce (BigInteger n, BigInteger m)
-                       {
-                               return Reduce (n, m, Inverse (m.data [0]));
-                       }
-#endif
-               }
-
                /// <summary>
                /// Low level functions for the BigInteger
                /// </summary>