diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-24 15:31:13 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-24 15:31:13 +0700 |
commit | 4fd68a3d37b113ef9809228e80f5aeb45208813f (patch) | |
tree | 58fdce1b52765c6b41c3bbf6d6525c3d246fefeb | |
parent | Implementation of homogeneous coordinates for Fp (diff) | |
download | BouncyCastle.NET-ed25519-4fd68a3d37b113ef9809228e80f5aeb45208813f.tar.xz |
Run point test on all supported coordinate systems
-rw-r--r-- | crypto/test/src/math/ec/test/ECPointTest.cs | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/crypto/test/src/math/ec/test/ECPointTest.cs b/crypto/test/src/math/ec/test/ECPointTest.cs index b4cabec78..faaca7f19 100644 --- a/crypto/test/src/math/ec/test/ECPointTest.cs +++ b/crypto/test/src/math/ec/test/ECPointTest.cs @@ -426,17 +426,10 @@ namespace Org.BouncyCastle.Math.EC.Tests AssertPointsEqual("Error decoding compressed point", p, decComp); } - private void ImplAddSubtractMultiplyTwiceEncodingTest(X9ECParameters x9ECParameters) + private void ImplAddSubtractMultiplyTwiceEncodingTest(ECCurve curve, ECPoint q, BigInteger n) { - BigInteger n = x9ECParameters.N; - - // The generator is multiplied by random b to get random q - BigInteger b = new BigInteger(n.BitLength, secRand); - ECPoint g = x9ECParameters.G; - ECPoint q = g.Multiply(b).Normalize(); - // Get point at infinity on the curve - ECPoint infinity = x9ECParameters.Curve.Infinity; + ECPoint infinity = curve.Infinity; ImplTestAddSubtract(q, infinity); ImplTestMultiply(q, n.BitLength); @@ -444,6 +437,36 @@ namespace Org.BouncyCastle.Math.EC.Tests ImplTestEncoding(q); } + private void ImplAddSubtractMultiplyTwiceEncodingTestAllCoords(X9ECParameters x9ECParameters) + { + BigInteger n = x9ECParameters.N; + ECPoint G = x9ECParameters.G; + ECCurve C = x9ECParameters.Curve; + + int[] coords = ECCurve.GetAllCoordinateSystems(); + for (int i = 0; i < coords.Length; ++i) + { + int coord = coords[i]; + if (C.SupportsCoordinateSystem(coord)) + { + ECCurve c = C; + ECPoint g = G; + + if (c.CoordinateSystem != coord) + { + c = C.Configure().SetCoordinateSystem(coord).Create(); + g = c.ImportPoint(G); + } + + // The generator is multiplied by random b to get random q + BigInteger b = new BigInteger(n.BitLength, secRand); + ECPoint q = g.Multiply(b).Normalize(); + + ImplAddSubtractMultiplyTwiceEncodingTest(c, q, n); + } + } + } + /** * Calls <code>implTestAddSubtract()</code>, * <code>implTestMultiply</code> and <code>implTestEncoding</code> for @@ -452,15 +475,15 @@ namespace Org.BouncyCastle.Math.EC.Tests [Test] public void TestAddSubtractMultiplyTwiceEncoding() { - foreach (string name in SecNamedCurves.Names) + foreach (string name in ECNamedCurveTable.Names) { - X9ECParameters x9ECParameters = SecNamedCurves.GetByName(name); - ImplAddSubtractMultiplyTwiceEncodingTest(x9ECParameters); + X9ECParameters x9ECParameters = ECNamedCurveTable.GetByName(name); + ImplAddSubtractMultiplyTwiceEncodingTestAllCoords(x9ECParameters); x9ECParameters = CustomNamedCurves.GetByName(name); if (x9ECParameters != null) { - ImplAddSubtractMultiplyTwiceEncodingTest(x9ECParameters); + ImplAddSubtractMultiplyTwiceEncodingTestAllCoords(x9ECParameters); } } } |