summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-10-28 17:36:48 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-10-28 17:36:48 +0700
commitec637154832f0ce8b7e7b6a6a496e6ab5add3e4e (patch)
tree4e831bd4bf3d91db6d5d11bb38005ea3c93c52b2
parentPull a few PORTABLE changes from BouncyCastle-PCL (with fixes) (diff)
downloadBouncyCastle.NET-ed25519-ec637154832f0ce8b7e7b6a6a496e6ab5add3e4e.tar.xz
Mark expensive tests with ExplicitAttribute and add faster alternatives
-rw-r--r--crypto/test/src/math/ec/test/ECAlgorithmsTest.cs98
1 files changed, 62 insertions, 36 deletions
diff --git a/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs b/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs
index b950c8b4b..678b2991c 100644
--- a/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs
+++ b/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs
@@ -22,57 +22,83 @@ namespace Org.BouncyCastle.Math.EC.Tests
         [Test]
         public void TestSumOfMultiplies()
         {
+            X9ECParameters x9 = CustomNamedCurves.GetByName("secp256r1");
+            Assert.NotNull(x9);
+            DoTestSumOfMultiplies(x9);
+        }
+
+        [Test, Explicit]
+        public void TestSumOfMultipliesComplete()
+        {
             foreach (X9ECParameters x9 in GetTestCurves())
             {
-                ECPoint[] points = new ECPoint[SCALE];
-                BigInteger[] scalars = new BigInteger[SCALE];
-                for (int i = 0; i < SCALE; ++i)
-                {
-                    points[i] = GetRandomPoint(x9);
-                    scalars[i] = GetRandomScalar(x9);
-                }
-
-                ECPoint u = x9.Curve.Infinity;
-                for (int i = 0; i < SCALE; ++i)
-                {
-                    u = u.Add(points[i].Multiply(scalars[i]));
-
-                    ECPoint v = ECAlgorithms.SumOfMultiplies(CopyPoints(points, i + 1), CopyScalars(scalars, i + 1));
-
-                    ECPoint[] results = new ECPoint[] { u, v };
-                    x9.Curve.NormalizeAll(results);
-
-                    AssertPointsEqual("ECAlgorithms.SumOfMultiplies is incorrect", results[0], results[1]);
-                }
+                DoTestSumOfMultiplies(x9);
             }
         }
 
         [Test]
         public void TestSumOfTwoMultiplies()
         {
+            X9ECParameters x9 = CustomNamedCurves.GetByName("secp256r1");
+            Assert.NotNull(x9);
+            DoTestSumOfTwoMultiplies(x9);
+        }
+
+        [Test, Explicit]
+        public void TestSumOfTwoMultipliesComplete()
+        {
             foreach (X9ECParameters x9 in GetTestCurves())
             {
-                ECPoint p = GetRandomPoint(x9);
-                BigInteger a = GetRandomScalar(x9);
+                DoTestSumOfTwoMultiplies(x9);
+            }
+        }
+
+        private void DoTestSumOfMultiplies(X9ECParameters x9)
+        {
+            ECPoint[] points = new ECPoint[SCALE];
+            BigInteger[] scalars = new BigInteger[SCALE];
+            for (int i = 0; i < SCALE; ++i)
+            {
+                points[i] = GetRandomPoint(x9);
+                scalars[i] = GetRandomScalar(x9);
+            }
+
+            ECPoint u = x9.Curve.Infinity;
+            for (int i = 0; i < SCALE; ++i)
+            {
+                u = u.Add(points[i].Multiply(scalars[i]));
 
-                for (int i = 0; i < SCALE; ++i)
-                {
-                    ECPoint q = GetRandomPoint(x9);
-                    BigInteger b = GetRandomScalar(x9);
+                ECPoint v = ECAlgorithms.SumOfMultiplies(CopyPoints(points, i + 1), CopyScalars(scalars, i + 1));
+
+                ECPoint[] results = new ECPoint[] { u, v };
+                x9.Curve.NormalizeAll(results);
 
-                    ECPoint u = p.Multiply(a).Add(q.Multiply(b));
-                    ECPoint v = ECAlgorithms.ShamirsTrick(p, a, q, b);
-                    ECPoint w = ECAlgorithms.SumOfTwoMultiplies(p, a, q, b);
+                AssertPointsEqual("ECAlgorithms.SumOfMultiplies is incorrect", results[0], results[1]);
+            }
+        }
+
+        private void DoTestSumOfTwoMultiplies(X9ECParameters x9)
+        {
+            ECPoint p = GetRandomPoint(x9);
+            BigInteger a = GetRandomScalar(x9);
 
-                    ECPoint[] results = new ECPoint[] { u, v, w };
-                    x9.Curve.NormalizeAll(results);
+            for (int i = 0; i < SCALE; ++i)
+            {
+                ECPoint q = GetRandomPoint(x9);
+                BigInteger b = GetRandomScalar(x9);
 
-                    AssertPointsEqual("ECAlgorithms.ShamirsTrick is incorrect", results[0], results[1]);
-                    AssertPointsEqual("ECAlgorithms.SumOfTwoMultiplies is incorrect", results[0], results[2]);
+                ECPoint u = p.Multiply(a).Add(q.Multiply(b));
+                ECPoint v = ECAlgorithms.ShamirsTrick(p, a, q, b);
+                ECPoint w = ECAlgorithms.SumOfTwoMultiplies(p, a, q, b);
 
-                    p = q;
-                    a = b;
-                }
+                ECPoint[] results = new ECPoint[] { u, v, w };
+                x9.Curve.NormalizeAll(results);
+
+                AssertPointsEqual("ECAlgorithms.ShamirsTrick is incorrect", results[0], results[1]);
+                AssertPointsEqual("ECAlgorithms.SumOfTwoMultiplies is incorrect", results[0], results[2]);
+
+                p = q;
+                a = b;
             }
         }