summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorRoy Basmacier <roy.basmacier@keyfactor.com>2022-06-24 16:19:02 -0400
committerRoy Basmacier <roy.basmacier@keyfactor.com>2022-06-24 16:19:02 -0400
commit5ce0ecf7d31b462bd14c51a9e1f6514dc188c17c (patch)
tree9236aa449ab6b2c2142f3f8b0065078e125c2603 /crypto/test
parentsphincs plus v3.1 (diff)
parentRefactoring (diff)
downloadBouncyCastle.NET-ed25519-5ce0ecf7d31b462bd14c51a9e1f6514dc188c17c.tar.xz
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/crypto/test/ECGOST3410_2012Test.cs8
-rw-r--r--crypto/test/src/crypto/test/ECTest.cs15
-rw-r--r--crypto/test/src/math/ec/test/ECPointPerformanceTest.cs18
-rw-r--r--crypto/test/src/math/ec/test/ECPointTest.cs9
-rw-r--r--crypto/test/src/math/ec/test/FixedPointTest.cs10
-rw-r--r--crypto/test/src/pqc/crypto/lms/HSSTests.cs2
-rw-r--r--crypto/test/src/pqc/crypto/lms/LMSTests.cs16
-rw-r--r--crypto/test/src/util/test/SimpleTest.cs2
-rw-r--r--crypto/test/src/util/test/TestFailedException.cs15
9 files changed, 45 insertions, 50 deletions
diff --git a/crypto/test/src/crypto/test/ECGOST3410_2012Test.cs b/crypto/test/src/crypto/test/ECGOST3410_2012Test.cs

index 0e7e90611..7e0a84cbe 100644 --- a/crypto/test/src/crypto/test/ECGOST3410_2012Test.cs +++ b/crypto/test/src/crypto/test/ECGOST3410_2012Test.cs
@@ -30,7 +30,7 @@ namespace Org.BouncyCastle.Crypto.Tests public SimpleTestResult EncodeRecodePublicKey() { DerObjectIdentifier oid = ECGost3410NamedCurves.GetOid("Tc26-Gost-3410-12-512-paramSetA"); - ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGost3410NamedCurves.GetByOidX9(oid)); + ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGost3410NamedCurves.GetByOid(oid)); ECGost3410Parameters gostParams = new ECGost3410Parameters(ecp, oid, RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512, null); ECKeyGenerationParameters paramameters = new ECKeyGenerationParameters(gostParams, new SecureRandom()); ECKeyPairGenerator engine = new ECKeyPairGenerator(); @@ -118,7 +118,7 @@ namespace Org.BouncyCastle.Crypto.Tests private SimpleTestResult EncodeRecodePrivateKey() { DerObjectIdentifier oid = ECGost3410NamedCurves.GetOid("Tc26-Gost-3410-12-512-paramSetA"); - ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGost3410NamedCurves.GetByOidX9(oid)); + ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGost3410NamedCurves.GetByOid(oid)); ECGost3410Parameters gostParams = new ECGost3410Parameters(ecp, oid, RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512, null); ECKeyGenerationParameters parameters = new ECKeyGenerationParameters(gostParams, new SecureRandom()); ECKeyPairGenerator engine = new ECKeyPairGenerator(); @@ -338,7 +338,7 @@ namespace Org.BouncyCastle.Crypto.Tests public SimpleTestResult EncodeDecodePrivateLW(string oidStr, DerObjectIdentifier digest) { DerObjectIdentifier oid = ECGost3410NamedCurves.GetOid(oidStr); - ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGost3410NamedCurves.GetByOidX9(oid)); + ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGost3410NamedCurves.GetByOid(oid)); ECGost3410Parameters gostParams = new ECGost3410Parameters(ecp, oid, digest, null); ECKeyGenerationParameters parameters = new ECKeyGenerationParameters(gostParams, new SecureRandom()); ECKeyPairGenerator engine = new ECKeyPairGenerator(); @@ -421,7 +421,7 @@ namespace Org.BouncyCastle.Crypto.Tests public SimpleTestResult EncodeDecodePublicLW(string oidStr, DerObjectIdentifier digest) { DerObjectIdentifier oid = ECGost3410NamedCurves.GetOid(oidStr); - ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGost3410NamedCurves.GetByOidX9(oid)); + ECNamedDomainParameters ecp = new ECNamedDomainParameters(oid, ECGost3410NamedCurves.GetByOid(oid)); ECGost3410Parameters gostParams = new ECGost3410Parameters(ecp, oid, digest, null); ECKeyGenerationParameters parameters = new ECKeyGenerationParameters(gostParams, new SecureRandom()); ECKeyPairGenerator engine = new ECKeyPairGenerator(); diff --git a/crypto/test/src/crypto/test/ECTest.cs b/crypto/test/src/crypto/test/ECTest.cs
index 18abb8df1..58dc75e2f 100644 --- a/crypto/test/src/crypto/test/ECTest.cs +++ b/crypto/test/src/crypto/test/ECTest.cs
@@ -745,8 +745,19 @@ namespace Org.BouncyCastle.Crypto.Tests { SecureRandom random = new SecureRandom(); - X9ECParameters x9 = CustomNamedCurves.GetByName("curve25519"); - ECDomainParameters ec = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H, x9.GetSeed()); + // "curve25519" in short Weierstrass form + BigInteger q = BigInteger.One.ShiftLeft(255).Subtract(BigInteger.ValueOf(19)); + BigInteger a = new BigInteger(1, Hex.DecodeStrict("2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA984914A144")); + BigInteger b = new BigInteger(1, Hex.DecodeStrict("7B425ED097B425ED097B425ED097B425ED097B425ED097B4260B5E9C7710C864")); + BigInteger n = new BigInteger(1, Hex.DecodeStrict("1000000000000000000000000000000014DEF9DEA2F79CD65812631A5CF5D3ED")); + BigInteger h = BigInteger.ValueOf(8); + + ECCurve curve = new FpCurve(q, a, b, n, h); + X9ECPoint G = new X9ECPoint(curve, + Hex.DecodeStrict("042AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD245A20AE19A1B8A086B4E01EDD2C7748D14C923D4D7E6D7C61B229E9C5A27ECED3D9")); + + X9ECParameters x9 = new X9ECParameters(curve, G, n, h); + ECDomainParameters ec = new ECDomainParameters(x9); ECKeyPairGenerator kpg = new ECKeyPairGenerator(); kpg.Init(new ECKeyGenerationParameters(ec, random)); diff --git a/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs b/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs
index e36947b11..059416427 100644 --- a/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs +++ b/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs
@@ -1,17 +1,13 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.Text; using NUnit.Framework; using Org.BouncyCastle.Asn1; -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; using Org.BouncyCastle.Utilities.Date; @@ -98,6 +94,8 @@ namespace Org.BouncyCastle.Math.EC.Tests Console.WriteLine(sb.ToString()); } } + + Console.Out.Flush(); } private double RandMult(SecureRandom random, ECPoint g, BigInteger n) @@ -175,12 +173,12 @@ namespace Org.BouncyCastle.Math.EC.Tests [Test, Explicit] public void TestMultiply() { - ArrayList nameList = new ArrayList(); - CollectionUtilities.AddRange(nameList, ECNamedCurveTable.Names); - CollectionUtilities.AddRange(nameList, CustomNamedCurves.Names); + var names = new List<string>(); + names.AddRange(ECNamedCurveTable.Names); + names.AddRange(CustomNamedCurves.Names); + + names.Sort(); - string[] names = (string[])nameList.ToArray(typeof(string)); - Array.Sort(names); ISet oids = new HashSet(); foreach (string name in names) { diff --git a/crypto/test/src/math/ec/test/ECPointTest.cs b/crypto/test/src/math/ec/test/ECPointTest.cs
index f3fc6e592..4e3fc5832 100644 --- a/crypto/test/src/math/ec/test/ECPointTest.cs +++ b/crypto/test/src/math/ec/test/ECPointTest.cs
@@ -1,11 +1,10 @@ using System; -using System.Collections; +using System.Collections.Generic; 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; using Org.BouncyCastle.Utilities.Collections; @@ -535,9 +534,9 @@ namespace Org.BouncyCastle.Math.EC.Tests [Test] public void TestAddSubtractMultiplyTwiceEncoding() { - ArrayList names = new ArrayList(); - CollectionUtilities.AddRange(names, ECNamedCurveTable.Names); - CollectionUtilities.AddRange(names, CustomNamedCurves.Names); + var names = new List<string>(); + names.AddRange(ECNamedCurveTable.Names); + names.AddRange(CustomNamedCurves.Names); ISet uniqNames = new HashSet(names); diff --git a/crypto/test/src/math/ec/test/FixedPointTest.cs b/crypto/test/src/math/ec/test/FixedPointTest.cs
index 83e5fab8f..433f956da 100644 --- a/crypto/test/src/math/ec/test/FixedPointTest.cs +++ b/crypto/test/src/math/ec/test/FixedPointTest.cs
@@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using NUnit.Framework; @@ -23,9 +23,9 @@ namespace Org.BouncyCastle.Math.EC.Tests { FixedPointCombMultiplier M = new FixedPointCombMultiplier(); - ArrayList names = new ArrayList(); - CollectionUtilities.AddRange(names, ECNamedCurveTable.Names); - CollectionUtilities.AddRange(names, CustomNamedCurves.Names); + var names = new List<string>(); + names.AddRange(ECNamedCurveTable.Names); + names.AddRange(CustomNamedCurves.Names); ISet uniqNames = new HashSet(names); @@ -34,7 +34,7 @@ namespace Org.BouncyCastle.Math.EC.Tests X9ECParameters x9A = ECNamedCurveTable.GetByName(name); X9ECParameters x9B = CustomNamedCurves.GetByName(name); - X9ECParameters x9 = x9B != null ? x9B : x9A; + X9ECParameters x9 = x9B ?? x9A; for (int i = 0; i < TestsPerCurve; ++i) { diff --git a/crypto/test/src/pqc/crypto/lms/HSSTests.cs b/crypto/test/src/pqc/crypto/lms/HSSTests.cs
index 6918da102..d97038d3b 100644 --- a/crypto/test/src/pqc/crypto/lms/HSSTests.cs +++ b/crypto/test/src/pqc/crypto/lms/HSSTests.cs
@@ -470,7 +470,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms byte[] hssPubEnc = null; MemoryStream fixedESBuffer = new MemoryStream(); IList sigVectors = new ArrayList(); - int d = 0, j = 0; + int d = 0; string line; while ((line = sr.ReadLine()) != null) diff --git a/crypto/test/src/pqc/crypto/lms/LMSTests.cs b/crypto/test/src/pqc/crypto/lms/LMSTests.cs
index 4b5d6206f..dbc541674 100644 --- a/crypto/test/src/pqc/crypto/lms/LMSTests.cs +++ b/crypto/test/src/pqc/crypto/lms/LMSTests.cs
@@ -158,20 +158,10 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms ctx.Update((byte)1); Assert.Fail("Digest reuse after signature taken."); } - catch (NullReferenceException npe) + catch (NullReferenceException) { - Assert.True(true); + // Expected } - } - - public void Main(string[] args) - { - TestCoefFunc(); - TestPrivateKeyRound(); - TestLMS(); - TestContextSingleUse(); - } - } -} \ No newline at end of file +} diff --git a/crypto/test/src/util/test/SimpleTest.cs b/crypto/test/src/util/test/SimpleTest.cs
index fc88be103..1695164e5 100644 --- a/crypto/test/src/util/test/SimpleTest.cs +++ b/crypto/test/src/util/test/SimpleTest.cs
@@ -108,7 +108,7 @@ namespace Org.BouncyCastle.Utilities.Test } catch (TestFailedException e) { - return e.GetResult(); + return e.Result; } catch (Exception e) { diff --git a/crypto/test/src/util/test/TestFailedException.cs b/crypto/test/src/util/test/TestFailedException.cs
index 215e1fd20..2ea66087d 100644 --- a/crypto/test/src/util/test/TestFailedException.cs +++ b/crypto/test/src/util/test/TestFailedException.cs
@@ -2,23 +2,20 @@ using System; namespace Org.BouncyCastle.Utilities.Test { -#if !PORTABLE - [Serializable] -#endif public class TestFailedException : Exception { - private ITestResult _result; + private readonly ITestResult m_result; - public TestFailedException( - ITestResult result) + public TestFailedException(ITestResult result) + : base() { - _result = result; + m_result = result; } - public ITestResult GetResult() + public ITestResult Result { - return _result; + get { return m_result; } } } }