diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2016-02-02 18:29:42 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2016-02-02 18:29:42 +0700 |
commit | 1106f4b37f9845c5a834dc9e1f61fd89cda93392 (patch) | |
tree | 830ab36d96c94719fa3e3db69946ac22683f7be3 /crypto | |
parent | Additional temp values in reduction (diff) | |
download | BouncyCastle.NET-ed25519-1106f4b37f9845c5a834dc9e1f61fd89cda93392.tar.xz |
Refactoring
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/test/src/math/ec/test/ECAlgorithmsTest.cs | 19 | ||||
-rw-r--r-- | crypto/test/src/math/ec/test/ECPointTest.cs | 24 |
2 files changed, 15 insertions, 28 deletions
diff --git a/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs b/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs index 0b3a203dd..2a05c82ce 100644 --- a/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs +++ b/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs @@ -5,10 +5,7 @@ using NUnit.Framework; using Org.BouncyCastle.Asn1.X9; using Org.BouncyCastle.Crypto.EC; -using Org.BouncyCastle.Math; -using Org.BouncyCastle.Math.EC; using Org.BouncyCastle.Security; -using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.Collections; namespace Org.BouncyCastle.Math.EC.Tests @@ -16,8 +13,8 @@ namespace Org.BouncyCastle.Math.EC.Tests [TestFixture] public class ECAlgorithmsTest { - private const int SCALE = 4; - private static readonly SecureRandom RND = new SecureRandom(); + private const int Scale = 4; + private static readonly SecureRandom Random = new SecureRandom(); [Test] public void TestSumOfMultiplies() @@ -55,16 +52,16 @@ namespace Org.BouncyCastle.Math.EC.Tests private void DoTestSumOfMultiplies(X9ECParameters x9) { - ECPoint[] points = new ECPoint[SCALE]; - BigInteger[] scalars = new BigInteger[SCALE]; - for (int i = 0; i < SCALE; ++i) + 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) + for (int i = 0; i < Scale; ++i) { u = u.Add(points[i].Multiply(scalars[i])); @@ -82,7 +79,7 @@ namespace Org.BouncyCastle.Math.EC.Tests ECPoint p = GetRandomPoint(x9); BigInteger a = GetRandomScalar(x9); - for (int i = 0; i < SCALE; ++i) + for (int i = 0; i < Scale; ++i) { ECPoint q = GetRandomPoint(x9); BigInteger b = GetRandomScalar(x9); @@ -128,7 +125,7 @@ namespace Org.BouncyCastle.Math.EC.Tests private BigInteger GetRandomScalar(X9ECParameters x9) { - return new BigInteger(x9.N.BitLength, RND); + return new BigInteger(x9.N.BitLength, Random); } private IList GetTestCurves() diff --git a/crypto/test/src/math/ec/test/ECPointTest.cs b/crypto/test/src/math/ec/test/ECPointTest.cs index 57f838f9f..089fb88b3 100644 --- a/crypto/test/src/math/ec/test/ECPointTest.cs +++ b/crypto/test/src/math/ec/test/ECPointTest.cs @@ -3,11 +3,8 @@ using System.Collections; using NUnit.Framework; -using Org.BouncyCastle.Asn1.Sec; using Org.BouncyCastle.Asn1.X9; using Org.BouncyCastle.Crypto.EC; -using Org.BouncyCastle.Math; -using Org.BouncyCastle.Math.EC; using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.Collections; @@ -26,11 +23,7 @@ namespace Org.BouncyCastle.Math.EC.Tests /** * Random source used to generate random points */ - private SecureRandom secRand = new SecureRandom(); - -// private ECPointTest.Fp fp = null; - -// private ECPointTest.F2m f2m = null; + private SecureRandom Random = new SecureRandom(); /** * Nested class containing sample literature values for <code>Fp</code>. @@ -113,12 +106,9 @@ namespace Org.BouncyCastle.Math.EC.Tests } [SetUp] - public void setUp() + public void SetUp() { -// fp = new ECPointTest.Fp(); Fp.CreatePoints(); - -// f2m = new ECPointTest.F2m(); F2m.CreatePoints(); } @@ -301,7 +291,7 @@ namespace Org.BouncyCastle.Math.EC.Tests */ private void ImplTestMultiply(ECPoint p, int numBits) { - BigInteger k = new BigInteger(numBits, secRand); + BigInteger k = new BigInteger(numBits, Random); ECPoint reff = ECAlgorithms.ReferenceMultiply(p, k); ECPoint q = p.Multiply(k); AssertPointsEqual("ECPoint.Multiply is incorrect", reff, q); @@ -428,7 +418,7 @@ namespace Org.BouncyCastle.Math.EC.Tests int count = 0; while (count < 10) { - BigInteger nonSquare = BigIntegers.CreateRandomInRange(BigInteger.Two, pMinusOne, secRand); + BigInteger nonSquare = BigIntegers.CreateRandomInRange(BigInteger.Two, pMinusOne, Random); if (!nonSquare.ModPow(legendreExponent, p).Equals(BigInteger.One)) { ECFieldElement root = c.FromBigInteger(nonSquare).Sqrt(); @@ -440,7 +430,7 @@ namespace Org.BouncyCastle.Math.EC.Tests else if (ECAlgorithms.IsF2mCurve(c)) { int m = c.FieldSize; - BigInteger x = new BigInteger(m, secRand); + BigInteger x = new BigInteger(m, Random); ECFieldElement fe = c.FromBigInteger(x); for (int i = 0; i < 100; ++i) { @@ -474,7 +464,7 @@ namespace Org.BouncyCastle.Math.EC.Tests } // The generator is multiplied by random b to get random q - BigInteger b = new BigInteger(n.BitLength, secRand); + BigInteger b = new BigInteger(n.BitLength, Random); ECPoint q = g.Multiply(b).Normalize(); ImplAddSubtractMultiplyTwiceEncodingTest(c, q, n); @@ -517,7 +507,7 @@ namespace Org.BouncyCastle.Math.EC.Tests Assert.AreEqual(x9A.N, x9B.N); AssertOptionalValuesAgree(x9A.GetSeed(), x9B.GetSeed()); - BigInteger k = new BigInteger(x9A.N.BitLength, secRand); + BigInteger k = new BigInteger(x9A.N.BitLength, Random); ECPoint pA = x9A.G.Multiply(k); ECPoint pB = x9B.G.Multiply(k); AssertPointsEqual("Custom curve multiplication inconsistency", pA, pB); |