diff --git a/crypto/test/UnitTests.csproj b/crypto/test/UnitTests.csproj
index be8b7d3c5..922507468 100644
--- a/crypto/test/UnitTests.csproj
+++ b/crypto/test/UnitTests.csproj
@@ -328,6 +328,7 @@
<Compile Include="src\math\ec\test\ECPointPerformanceTest.cs" />
<Compile Include="src\math\ec\test\ECPointTest.cs" />
<Compile Include="src\math\ec\test\F2mProofer.cs" />
+ <Compile Include="src\math\ec\test\FixedPointTest.cs" />
<Compile Include="src\math\ec\test\TnafTest.cs" />
<Compile Include="src\math\test\AllTests.cs" />
<Compile Include="src\math\test\BigIntegerTest.cs" />
diff --git a/crypto/test/src/math/ec/test/AllTests.cs b/crypto/test/src/math/ec/test/AllTests.cs
index 0517ac713..3d3f3939b 100644
--- a/crypto/test/src/math/ec/test/AllTests.cs
+++ b/crypto/test/src/math/ec/test/AllTests.cs
@@ -21,6 +21,7 @@ namespace Org.BouncyCastle.Math.EC.Tests
TestSuite suite = new TestSuite("EC Math tests");
suite.Add(new ECAlgorithmsTest());
suite.Add(new ECPointTest());
+ suite.Add(new FixedPointTest());
return suite;
}
}
diff --git a/crypto/test/src/math/ec/test/FixedPointTest.cs b/crypto/test/src/math/ec/test/FixedPointTest.cs
new file mode 100644
index 000000000..83e5fab8f
--- /dev/null
+++ b/crypto/test/src/math/ec/test/FixedPointTest.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Collections;
+
+using NUnit.Framework;
+
+using Org.BouncyCastle.Asn1.X9;
+using Org.BouncyCastle.Crypto.EC;
+using Org.BouncyCastle.Math.EC.Multiplier;
+using Org.BouncyCastle.Security;
+using Org.BouncyCastle.Utilities.Collections;
+
+namespace Org.BouncyCastle.Math.EC.Tests
+{
+ [TestFixture]
+ public class FixedPointTest
+ {
+ private static readonly SecureRandom Random = new SecureRandom();
+
+ private const int TestsPerCurve = 5;
+
+ [Test]
+ public void TestFixedPointMultiplier()
+ {
+ FixedPointCombMultiplier M = new FixedPointCombMultiplier();
+
+ ArrayList names = new ArrayList();
+ CollectionUtilities.AddRange(names, ECNamedCurveTable.Names);
+ CollectionUtilities.AddRange(names, CustomNamedCurves.Names);
+
+ ISet uniqNames = new HashSet(names);
+
+ foreach (string name in uniqNames)
+ {
+ X9ECParameters x9A = ECNamedCurveTable.GetByName(name);
+ X9ECParameters x9B = CustomNamedCurves.GetByName(name);
+
+ X9ECParameters x9 = x9B != null ? x9B : x9A;
+
+ for (int i = 0; i < TestsPerCurve; ++i)
+ {
+ BigInteger k = new BigInteger(x9.N.BitLength, Random);
+ ECPoint pRef = ECAlgorithms.ReferenceMultiply(x9.G, k);
+
+ if (x9A != null)
+ {
+ ECPoint pA = M.Multiply(x9A.G, k);
+ AssertPointsEqual("Standard curve fixed-point failure", pRef, pA);
+ }
+
+ if (x9B != null)
+ {
+ ECPoint pB = M.Multiply(x9B.G, k);
+ AssertPointsEqual("Custom curve fixed-point failure", pRef, pB);
+ }
+ }
+ }
+ }
+
+ private void AssertPointsEqual(string message, ECPoint a, ECPoint b)
+ {
+ // NOTE: We intentionally test points for equality in both directions
+ Assert.AreEqual(a, b, message);
+ Assert.AreEqual(b, a, message);
+ }
+ }
+}
|