From b2f9397b1f0631e7909468bf19816cceb56180f0 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sun, 17 Sep 2017 18:12:41 +0700 Subject: Sketch out test changes for ECGOST3410-2012 --- crypto/test/src/test/NamedCurveTest.cs | 41 ++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'crypto') diff --git a/crypto/test/src/test/NamedCurveTest.cs b/crypto/test/src/test/NamedCurveTest.cs index 460da233e..f7c831f17 100644 --- a/crypto/test/src/test/NamedCurveTest.cs +++ b/crypto/test/src/test/NamedCurveTest.cs @@ -240,18 +240,39 @@ namespace Org.BouncyCastle.Tests // } } - public void doTestECGost( - string name) + public void doTestECGost(string name) { -// ECGenParameterSpec ecSpec = new ECGenParameterSpec(name); - ECDomainParameters ecSpec = GetCurveParameters(name); + ISigner sgr; + string keyAlgorithm; + + if (name.IndexOf("Tc26-Gost-3410") == 0) + { + // TODO Implement ECGOST3410-2012 in SignerUtilies/GeneratorUtilities etc. + // Current test cases don't work for GOST34.10 2012 + return; + + keyAlgorithm = "ECGOST3410-2012"; + if (name.IndexOf("256") > 0) + { + sgr = SignerUtilities.GetSigner("ECGOST3410-2012-256"); + } + else + { + sgr = SignerUtilities.GetSigner("ECGOST3410-2012-512"); + } + } + else + { + keyAlgorithm = "ECGOST3410"; - IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator("ECGOST3410"); + sgr = SignerUtilities.GetSigner("ECGOST3410"); + } -// g.initialize(ecSpec, new SecureRandom()); + ECDomainParameters ecSpec = GetCurveParameters(name); + + IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator(keyAlgorithm); g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom())); - ISigner sgr = SignerUtilities.GetSigner("ECGOST3410"); AsymmetricCipherKeyPair pair = g.GenerateKeyPair(); AsymmetricKeyParameter sKey = pair.Private; AsymmetricKeyParameter vKey = pair.Public; @@ -280,7 +301,7 @@ namespace Org.BouncyCastle.Tests //// byte[] pubEnc = vKey.getEncoded(); // byte[] pubEnc = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(vKey).GetDerEncoded(); // -//// KeyFactory keyFac = KeyFactory.getInstance("ECGOST3410"); +//// KeyFactory keyFac = KeyFactory.getInstance(keyAlgorithm); //// X509EncodedKeySpec pubX509 = new X509EncodedKeySpec(pubEnc); //// ECPublicKey pubKey = (ECPublicKey)keyFac.generatePublic(pubX509); // ECPublicKeyParameters pubKey = (ECPublicKeyParameters) PublicKeyFactory.CreateKey(pubEnc); @@ -369,10 +390,6 @@ namespace Org.BouncyCastle.Tests foreach (string name in ECGost3410NamedCurves.Names) { - // Current test cases don't work for GOST34.10 2012 - if (name.IndexOf("3410-12") >= 0) - continue; - doTestECGost(name); } } -- cgit 1.4.1