diff options
author | Oren Novotny <oren@novotny.org> | 2018-07-19 20:37:04 -0400 |
---|---|---|
committer | Oren Novotny <oren@novotny.org> | 2018-07-19 20:37:04 -0400 |
commit | 27161159797e4c66157ce82bc19154e132543482 (patch) | |
tree | 9e2b1d951a4e5dba772f6890b285b0e719df4ff7 /crypto/test | |
parent | remove unused define (diff) | |
parent | IDEA: Update patent information (diff) | |
download | BouncyCastle.NET-ed25519-27161159797e4c66157ce82bc19154e132543482.tar.xz |
Merge from master
Diffstat (limited to 'crypto/test')
20 files changed, 794 insertions, 223 deletions
diff --git a/crypto/test/src/crypto/test/ECGOST3410Test.cs b/crypto/test/src/crypto/test/ECGOST3410Test.cs index 5efa75169..fa79e58d9 100644 --- a/crypto/test/src/crypto/test/ECGOST3410Test.cs +++ b/crypto/test/src/crypto/test/ECGOST3410Test.cs @@ -56,7 +56,7 @@ namespace Org.BouncyCastle.Crypto.Tests curve.CreatePoint( new BigInteger("2"), // x new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280")), // y - mod_q); + mod_q, BigInteger.One); ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( "ECGOST3410", @@ -127,7 +127,7 @@ namespace Org.BouncyCastle.Crypto.Tests curve.CreatePoint( new BigInteger("2"), // x new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280")), // y - mod_q); + mod_q, BigInteger.One); ECKeyPairGenerator pGen = new ECKeyPairGenerator(); ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( @@ -184,7 +184,7 @@ namespace Org.BouncyCastle.Crypto.Tests curve.CreatePoint( new BigInteger("1"), // x new BigInteger("64033881142927202683649881450433473985931760268884941288852745803908878638612")), // y - mod_q); + mod_q, BigInteger.One); ECKeyPairGenerator pGen = new ECKeyPairGenerator("ECGOST3410"); ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( @@ -234,7 +234,7 @@ namespace Org.BouncyCastle.Crypto.Tests curve.CreatePoint( new BigInteger("1"), // x new BigInteger("28792665814854611296992347458380284135028636778229113005756334730996303888124")), // y - mod_q); + mod_q, BigInteger.One); ECKeyPairGenerator pGen = new ECKeyPairGenerator("ECGOST3410"); ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( @@ -284,7 +284,7 @@ namespace Org.BouncyCastle.Crypto.Tests curve.CreatePoint( new BigInteger("0"), // x new BigInteger("29818893917731240733471273240314769927240550812383695689146495261604565990247")), // y - mod_q); + mod_q, BigInteger.One); ECKeyPairGenerator pGen = new ECKeyPairGenerator("ECGOST3410"); ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( diff --git a/crypto/test/src/crypto/test/ECIESTest.cs b/crypto/test/src/crypto/test/ECIESTest.cs index f17e6957a..4957e7e27 100644 --- a/crypto/test/src/crypto/test/ECIESTest.cs +++ b/crypto/test/src/crypto/test/ECIESTest.cs @@ -46,9 +46,9 @@ namespace Org.BouncyCastle.Crypto.Tests n, BigInteger.One); ECDomainParameters parameters = new ECDomainParameters( - curve, - curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); + curve, + curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G + n, BigInteger.One); ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( "ECDH", @@ -220,9 +220,9 @@ namespace Org.BouncyCastle.Crypto.Tests n, BigInteger.One); ECDomainParameters parameters = new ECDomainParameters( - curve, - curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); + curve, + curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G + n, BigInteger.One); ECKeyPairGenerator eGen = new ECKeyPairGenerator(); KeyGenerationParameters gParam = new ECKeyGenerationParameters(parameters, new SecureRandom()); diff --git a/crypto/test/src/crypto/test/ECNRTest.cs b/crypto/test/src/crypto/test/ECNRTest.cs index 180b33560..ab4800221 100644 --- a/crypto/test/src/crypto/test/ECNRTest.cs +++ b/crypto/test/src/crypto/test/ECNRTest.cs @@ -49,7 +49,7 @@ namespace Org.BouncyCastle.Crypto.Tests ECDomainParameters parameters = new ECDomainParameters( curve, curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - n); + n, BigInteger.One); ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( new BigInteger("876300101507107567501066130761671078357010671067781776716671676178726717"), // d diff --git a/crypto/test/src/crypto/test/ECTest.cs b/crypto/test/src/crypto/test/ECTest.cs index 980d04d6c..f4dd4dce2 100644 --- a/crypto/test/src/crypto/test/ECTest.cs +++ b/crypto/test/src/crypto/test/ECTest.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using Org.BouncyCastle.Asn1.Nist; 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; @@ -52,7 +53,7 @@ namespace Org.BouncyCastle.Crypto.Tests ECDomainParameters parameters = new ECDomainParameters( curve, curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")), // G - n); + n, BigInteger.One); ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( "ECDSA", @@ -98,12 +99,8 @@ namespace Org.BouncyCastle.Crypto.Tests [Test] public void TestDecode() { - FpCurve curve = new FpCurve( - new BigInteger("6277101735386680763835789423207666416083908700390324961279"), // q - new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a - new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16)); // b - - ECPoint p = curve.DecodePoint(Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")).Normalize(); + X9ECParameters x9 = ECNamedCurveTable.GetByName("prime192v1"); + ECPoint p = x9.G; if (!p.AffineXCoord.ToBigInteger().Equals(new BigInteger("188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012", 16))) { @@ -115,7 +112,7 @@ namespace Org.BouncyCastle.Crypto.Tests Fail("y uncompressed incorrectly"); } - byte[] encoding = p.GetEncoded(); + byte[] encoding = p.GetEncoded(true); if (!AreEqual(encoding, Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012"))) { @@ -149,7 +146,7 @@ namespace Org.BouncyCastle.Crypto.Tests ECDomainParameters parameters = new ECDomainParameters( curve, curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - n); + n, BigInteger.One); ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( "ECDSA", @@ -651,7 +648,7 @@ namespace Org.BouncyCastle.Crypto.Tests ECDomainParameters parameters = new ECDomainParameters( curve, curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - n); + n, BigInteger.One); ECKeyPairGenerator pGen = new ECKeyPairGenerator(); ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( @@ -683,7 +680,7 @@ namespace Org.BouncyCastle.Crypto.Tests * Basic Key Agreement Test */ [Test] - public void TestECBasicAgreementTest() + public void TestECDHBasicAgreement() { SecureRandom random = new SecureRandom(); @@ -698,7 +695,7 @@ namespace Org.BouncyCastle.Crypto.Tests ECDomainParameters parameters = new ECDomainParameters( curve, curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - n); + n, BigInteger.One); ECKeyPairGenerator pGen = new ECKeyPairGenerator(); ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(parameters, random); @@ -744,6 +741,35 @@ namespace Org.BouncyCastle.Crypto.Tests } [Test] + public void TestECDHBasicAgreementCofactor() + { + SecureRandom random = new SecureRandom(); + + X9ECParameters x9 = CustomNamedCurves.GetByName("curve25519"); + ECDomainParameters ec = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H, x9.GetSeed()); + + ECKeyPairGenerator kpg = new ECKeyPairGenerator(); + kpg.Init(new ECKeyGenerationParameters(ec, random)); + + AsymmetricCipherKeyPair p1 = kpg.GenerateKeyPair(); + AsymmetricCipherKeyPair p2 = kpg.GenerateKeyPair(); + + IBasicAgreement e1 = new ECDHBasicAgreement(); + IBasicAgreement e2 = new ECDHBasicAgreement(); + + e1.Init(p1.Private); + e2.Init(p2.Private); + + BigInteger k1 = e1.CalculateAgreement(p2.Public); + BigInteger k2 = e2.CalculateAgreement(p1.Public); + + if (!k1.Equals(k2)) + { + Fail("calculated agreement test failed"); + } + } + + [Test] public void TestECMqvTestVector1() { // Test Vector from GEC-2 @@ -843,7 +869,7 @@ namespace Org.BouncyCastle.Crypto.Tests ECDomainParameters parameters = new ECDomainParameters( curve, curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - n); + n, BigInteger.One); ECKeyPairGenerator pGen = new ECKeyPairGenerator(); @@ -909,7 +935,8 @@ namespace Org.BouncyCastle.Crypto.Tests TestECDsa191bitBinary(); TestECDsa239bitBinary(); TestECDsaKeyGenTest(); - TestECBasicAgreementTest(); + TestECDHBasicAgreement(); + TestECDHBasicAgreementCofactor(); TestECDsaP224Sha224(); TestECDsaP224OneByteOver(); diff --git a/crypto/test/src/crypto/test/SM2EngineTest.cs b/crypto/test/src/crypto/test/SM2EngineTest.cs index cc9440e86..f961b0acb 100644 --- a/crypto/test/src/crypto/test/SM2EngineTest.cs +++ b/crypto/test/src/crypto/test/SM2EngineTest.cs @@ -28,10 +28,11 @@ namespace Org.BouncyCastle.Crypto.Tests BigInteger SM2_ECC_A = new BigInteger("787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", 16); BigInteger SM2_ECC_B = new BigInteger("63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", 16); BigInteger SM2_ECC_N = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", 16); + BigInteger SM2_ECC_H = BigInteger.One; BigInteger SM2_ECC_GX = new BigInteger("421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", 16); BigInteger SM2_ECC_GY = new BigInteger("0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", 16); - ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B); + ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY); ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N); @@ -104,11 +105,11 @@ namespace Org.BouncyCastle.Crypto.Tests BigInteger SM2_ECC_A = new BigInteger("00", 16); BigInteger SM2_ECC_B = new BigInteger("E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B", 16); BigInteger SM2_ECC_N = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC972CF7E6B6F900945B3C6A0CF6161D", 16); + BigInteger SM2_ECC_H = BigInteger.ValueOf(4); BigInteger SM2_ECC_GX = new BigInteger("00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD", 16); BigInteger SM2_ECC_GY = new BigInteger("013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E", 16); - BigInteger SM2_ECC_H = BigInteger.ValueOf(4); - ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B); + ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY); ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N, SM2_ECC_H); diff --git a/crypto/test/src/crypto/test/SM2KeyExchangeTest.cs b/crypto/test/src/crypto/test/SM2KeyExchangeTest.cs index 41993218c..6308383a6 100644 --- a/crypto/test/src/crypto/test/SM2KeyExchangeTest.cs +++ b/crypto/test/src/crypto/test/SM2KeyExchangeTest.cs @@ -30,10 +30,11 @@ namespace Org.BouncyCastle.Crypto.Tests BigInteger SM2_ECC_A = new BigInteger("787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", 16); BigInteger SM2_ECC_B = new BigInteger("63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", 16); BigInteger SM2_ECC_N = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", 16); + BigInteger SM2_ECC_H = BigInteger.One; BigInteger SM2_ECC_GX = new BigInteger("421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", 16); BigInteger SM2_ECC_GY = new BigInteger("0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", 16); - ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B); + ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY); ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N); @@ -119,11 +120,11 @@ namespace Org.BouncyCastle.Crypto.Tests BigInteger SM2_ECC_A = new BigInteger("00", 16); BigInteger SM2_ECC_B = new BigInteger("E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B", 16); BigInteger SM2_ECC_N = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC972CF7E6B6F900945B3C6A0CF6161D", 16); + BigInteger SM2_ECC_H = BigInteger.ValueOf(4); BigInteger SM2_ECC_GX = new BigInteger("00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD", 16); BigInteger SM2_ECC_GY = new BigInteger("013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E", 16); - BigInteger SM2_ECC_H = BigInteger.ValueOf(4); - ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B); + ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY); ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N, SM2_ECC_H); diff --git a/crypto/test/src/crypto/test/SM2SignerTest.cs b/crypto/test/src/crypto/test/SM2SignerTest.cs index 795fb6323..a9e6c48e5 100644 --- a/crypto/test/src/crypto/test/SM2SignerTest.cs +++ b/crypto/test/src/crypto/test/SM2SignerTest.cs @@ -29,10 +29,11 @@ namespace Org.BouncyCastle.Crypto.Tests BigInteger SM2_ECC_A = new BigInteger("787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", 16); BigInteger SM2_ECC_B = new BigInteger("63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", 16); BigInteger SM2_ECC_N = new BigInteger("8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", 16); + BigInteger SM2_ECC_H = BigInteger.ValueOf(4); BigInteger SM2_ECC_GX = new BigInteger("421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", 16); BigInteger SM2_ECC_GY = new BigInteger("0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", 16); - ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B); + ECCurve curve = new FpCurve(SM2_ECC_P, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY); ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N); @@ -76,10 +77,11 @@ namespace Org.BouncyCastle.Crypto.Tests BigInteger SM2_ECC_A = new BigInteger("00", 16); BigInteger SM2_ECC_B = new BigInteger("E78BCD09746C202378A7E72B12BCE00266B9627ECB0B5A25367AD1AD4CC6242B", 16); BigInteger SM2_ECC_N = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBC972CF7E6B6F900945B3C6A0CF6161D", 16); + BigInteger SM2_ECC_H = BigInteger.ValueOf(4); BigInteger SM2_ECC_GX = new BigInteger("00CDB9CA7F1E6B0441F658343F4B10297C0EF9B6491082400A62E7A7485735FADD", 16); BigInteger SM2_ECC_GY = new BigInteger("013DE74DA65951C4D76DC89220D5F7777A611B1C38BAE260B175951DC8060C2B3E", 16); - ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B); + ECCurve curve = new F2mCurve(257, 12, SM2_ECC_A, SM2_ECC_B, SM2_ECC_N, SM2_ECC_H); ECPoint g = curve.CreatePoint(SM2_ECC_GX, SM2_ECC_GY); ECDomainParameters domainParams = new ECDomainParameters(curve, g, SM2_ECC_N); diff --git a/crypto/test/src/math/ec/rfc8032/test/Ed25519Test.cs b/crypto/test/src/math/ec/rfc8032/test/Ed25519Test.cs new file mode 100644 index 000000000..43ea23988 --- /dev/null +++ b/crypto/test/src/math/ec/rfc8032/test/Ed25519Test.cs @@ -0,0 +1,231 @@ +using System; + +using NUnit.Framework; + +using Org.BouncyCastle.Security; +using Org.BouncyCastle.Utilities; +using Org.BouncyCastle.Utilities.Encoders; + +namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests +{ + [TestFixture] + public class Ed25519Test + { + private static readonly SecureRandom Random = new SecureRandom(); + + [SetUp] + public void SetUp() + { + Ed25519.Precompute(); + } + + [Test] + public void TestEd25519Consistency() + { + byte[] sk = new byte[Ed25519.SecretKeySize]; + byte[] pk = new byte[Ed25519.PublicKeySize]; + byte[] m = new byte[255]; + byte[] sig1 = new byte[Ed25519.SignatureSize]; + byte[] sig2 = new byte[Ed25519.SignatureSize]; + + Random.NextBytes(m); + + for (int i = 0; i < 10; ++i) + { + Random.NextBytes(sk); + Ed25519.GeneratePublicKey(sk, 0, pk, 0); + + int mLen = Random.Next() & 255; + + Ed25519.Sign(sk, 0, m, 0, mLen, sig1, 0); + Ed25519.Sign(sk, 0, pk, 0, m, 0, mLen, sig2, 0); + + Assert.IsTrue(Arrays.AreEqual(sig1, sig2), "Consistent signatures #" + i); + + bool shouldVerify = Ed25519.Verify(sig1, 0, pk, 0, m, 0, mLen); + + Assert.IsTrue(shouldVerify, "Consistent sign/verify #" + i); + + sig1[Ed25519.PublicKeySize - 1] ^= 0x80; + bool shouldNotVerify = Ed25519.Verify(sig1, 0, pk, 0, m, 0, mLen); + + Assert.IsFalse(shouldNotVerify, "Consistent verification failure #" + i); + } + } + + [Test] + public void TestEd25519Vector1() + { + CheckEd25519Vector( + ("9d61b19deffd5a60ba844af492ec2cc4" + + "4449c5697b326919703bac031cae7f60"), + ("d75a980182b10ab7d54bfed3c964073a" + + "0ee172f3daa62325af021a68f707511a"), + "", + ("e5564300c360ac729086e2cc806e828a" + + "84877f1eb8e5d974d873e06522490155" + + "5fb8821590a33bacc61e39701cf9b46b" + + "d25bf5f0595bbe24655141438e7a100b"), + "Ed25519 Vector #1"); + } + + [Test] + public void TestEd25519Vector2() + { + CheckEd25519Vector( + ("4ccd089b28ff96da9db6c346ec114e0f" + + "5b8a319f35aba624da8cf6ed4fb8a6fb"), + ("3d4017c3e843895a92b70aa74d1b7ebc" + + "9c982ccf2ec4968cc0cd55f12af4660c"), + "72", + ("92a009a9f0d4cab8720e820b5f642540" + + "a2b27b5416503f8fb3762223ebdb69da" + + "085ac1e43e15996e458f3613d0f11d8c" + + "387b2eaeb4302aeeb00d291612bb0c00"), + "Ed25519 Vector #2"); + } + + [Test] + public void TestEd25519Vector3() + { + CheckEd25519Vector( + ("c5aa8df43f9f837bedb7442f31dcb7b1" + + "66d38535076f094b85ce3a2e0b4458f7"), + ("fc51cd8e6218a1a38da47ed00230f058" + + "0816ed13ba3303ac5deb911548908025"), + "af82", + ("6291d657deec24024827e69c3abe01a3" + + "0ce548a284743a445e3680d7db5ac3ac" + + "18ff9b538d16f290ae67f760984dc659" + + "4a7c15e9716ed28dc027beceea1ec40a"), + "Ed25519 Vector #3"); + } + + [Test] + public void TestEd25519Vector1023() + { + string m = + "08b8b2b733424243760fe426a4b54908" + + "632110a66c2f6591eabd3345e3e4eb98" + + "fa6e264bf09efe12ee50f8f54e9f77b1" + + "e355f6c50544e23fb1433ddf73be84d8" + + "79de7c0046dc4996d9e773f4bc9efe57" + + "38829adb26c81b37c93a1b270b20329d" + + "658675fc6ea534e0810a4432826bf58c" + + "941efb65d57a338bbd2e26640f89ffbc" + + "1a858efcb8550ee3a5e1998bd177e93a" + + "7363c344fe6b199ee5d02e82d522c4fe" + + "ba15452f80288a821a579116ec6dad2b" + + "3b310da903401aa62100ab5d1a36553e" + + "06203b33890cc9b832f79ef80560ccb9" + + "a39ce767967ed628c6ad573cb116dbef" + + "efd75499da96bd68a8a97b928a8bbc10" + + "3b6621fcde2beca1231d206be6cd9ec7" + + "aff6f6c94fcd7204ed3455c68c83f4a4" + + "1da4af2b74ef5c53f1d8ac70bdcb7ed1" + + "85ce81bd84359d44254d95629e9855a9" + + "4a7c1958d1f8ada5d0532ed8a5aa3fb2" + + "d17ba70eb6248e594e1a2297acbbb39d" + + "502f1a8c6eb6f1ce22b3de1a1f40cc24" + + "554119a831a9aad6079cad88425de6bd" + + "e1a9187ebb6092cf67bf2b13fd65f270" + + "88d78b7e883c8759d2c4f5c65adb7553" + + "878ad575f9fad878e80a0c9ba63bcbcc" + + "2732e69485bbc9c90bfbd62481d9089b" + + "eccf80cfe2df16a2cf65bd92dd597b07" + + "07e0917af48bbb75fed413d238f5555a" + + "7a569d80c3414a8d0859dc65a46128ba" + + "b27af87a71314f318c782b23ebfe808b" + + "82b0ce26401d2e22f04d83d1255dc51a" + + "ddd3b75a2b1ae0784504df543af8969b" + + "e3ea7082ff7fc9888c144da2af58429e" + + "c96031dbcad3dad9af0dcbaaaf268cb8" + + "fcffead94f3c7ca495e056a9b47acdb7" + + "51fb73e666c6c655ade8297297d07ad1" + + "ba5e43f1bca32301651339e22904cc8c" + + "42f58c30c04aafdb038dda0847dd988d" + + "cda6f3bfd15c4b4c4525004aa06eeff8" + + "ca61783aacec57fb3d1f92b0fe2fd1a8" + + "5f6724517b65e614ad6808d6f6ee34df" + + "f7310fdc82aebfd904b01e1dc54b2927" + + "094b2db68d6f903b68401adebf5a7e08" + + "d78ff4ef5d63653a65040cf9bfd4aca7" + + "984a74d37145986780fc0b16ac451649" + + "de6188a7dbdf191f64b5fc5e2ab47b57" + + "f7f7276cd419c17a3ca8e1b939ae49e4" + + "88acba6b965610b5480109c8b17b80e1" + + "b7b750dfc7598d5d5011fd2dcc5600a3" + + "2ef5b52a1ecc820e308aa342721aac09" + + "43bf6686b64b2579376504ccc493d97e" + + "6aed3fb0f9cd71a43dd497f01f17c0e2" + + "cb3797aa2a2f256656168e6c496afc5f" + + "b93246f6b1116398a346f1a641f3b041" + + "e989f7914f90cc2c7fff357876e506b5" + + "0d334ba77c225bc307ba537152f3f161" + + "0e4eafe595f6d9d90d11faa933a15ef1" + + "369546868a7f3a45a96768d40fd9d034" + + "12c091c6315cf4fde7cb68606937380d" + + "b2eaaa707b4c4185c32eddcdd306705e" + + "4dc1ffc872eeee475a64dfac86aba41c" + + "0618983f8741c5ef68d3a101e8a3b8ca" + + "c60c905c15fc910840b94c00a0b9d0"; + + CheckEd25519Vector( + ("f5e5767cf153319517630f226876b86c" + + "8160cc583bc013744c6bf255f5cc0ee5"), + ("278117fc144c72340f67d0f2316e8386" + + "ceffbf2b2428c9c51fef7c597f1d426e"), + m, + ("0aab4c900501b3e24d7cdf4663326a3a" + + "87df5e4843b2cbdb67cbf6e460fec350" + + "aa5371b1508f9f4528ecea23c436d94b" + + "5e8fcd4f681e30a6ac00a9704a188a03"), + "Ed25519 Vector #1023"); + } + + [Test] + public void TestEd25519VectorSHAabc() + { + CheckEd25519Vector( + ("833fe62409237b9d62ec77587520911e" + + "9a759cec1d19755b7da901b96dca3d42"), + ("ec172b93ad5e563bf4932c70e1245034" + + "c35467ef2efd4d64ebf819683467e2bf"), + ("ddaf35a193617abacc417349ae204131" + + "12e6fa4e89a97ea20a9eeee64b55d39a" + + "2192992a274fc1a836ba3c23a3feebbd" + + "454d4423643ce80e2a9ac94fa54ca49f"), + ("dc2a4459e7369633a52b1bf277839a00" + + "201009a3efbf3ecb69bea2186c26b589" + + "09351fc9ac90b3ecfdfbc7c66431e030" + + "3dca179c138ac17ad9bef1177331a704"), + "Ed25519 Vector SHA(abc)"); + } + + private static void CheckEd25519Vector(string sSK, string sPK, string sM, string sSig, string text) + { + byte[] sk = Hex.Decode(sSK); + + byte[] pk = Hex.Decode(sPK); + byte[] pkGen = new byte[Ed25519.PublicKeySize]; + Ed25519.GeneratePublicKey(sk, 0, pkGen, 0); + Assert.IsTrue(Arrays.AreEqual(pk, pkGen), text); + + byte[] m = Hex.Decode(sM); + byte[] sig = Hex.Decode(sSig); + byte[] sigGen = new byte[Ed25519.SignatureSize]; + Ed25519.Sign(sk, 0, m, 0, m.Length, sigGen, 0); + Assert.IsTrue(Arrays.AreEqual(sig, sigGen), text); + + Ed25519.Sign(sk, 0, pk, 0, m, 0, m.Length, sigGen, 0); + Assert.IsTrue(Arrays.AreEqual(sig, sigGen), text); + + bool shouldVerify = Ed25519.Verify(sig, 0, pk, 0, m, 0, m.Length); + Assert.IsTrue(shouldVerify, text); + + sig[Ed25519.SignatureSize - 1] ^= 0x80; + bool shouldNotVerify = Ed25519.Verify(sig, 0, pk, 0, m, 0, m.Length); + Assert.IsFalse(shouldNotVerify, text); + } + } +} diff --git a/crypto/test/src/math/ec/rfc8032/test/Ed448Test.cs b/crypto/test/src/math/ec/rfc8032/test/Ed448Test.cs new file mode 100644 index 000000000..98c487c09 --- /dev/null +++ b/crypto/test/src/math/ec/rfc8032/test/Ed448Test.cs @@ -0,0 +1,400 @@ +using System; + +using NUnit.Framework; + +using Org.BouncyCastle.Security; +using Org.BouncyCastle.Utilities; +using Org.BouncyCastle.Utilities.Encoders; + +namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests +{ + [TestFixture] + public class Ed448Test + { + private static readonly SecureRandom Random = new SecureRandom(); + + [SetUp] + public void SetUp() + { + Ed448.Precompute(); + } + + [Test] + public void TestEd448Consistency() + { + byte[] sk = new byte[Ed448.SecretKeySize]; + byte[] pk = new byte[Ed448.PublicKeySize]; + byte[] ctx = new byte[Random.Next() & 7]; + byte[] m = new byte[255]; + byte[] sig1 = new byte[Ed448.SignatureSize]; + byte[] sig2 = new byte[Ed448.SignatureSize]; + + Random.NextBytes(ctx); + Random.NextBytes(m); + + for (int i = 0; i < 10; ++i) + { + Random.NextBytes(sk); + Ed448.GeneratePublicKey(sk, 0, pk, 0); + + int mLen = Random.Next() & 255; + + Ed448.Sign(sk, 0, ctx, m, 0, mLen, sig1, 0); + Ed448.Sign(sk, 0, pk, 0, ctx, m, 0, mLen, sig2, 0); + + Assert.IsTrue(Arrays.AreEqual(sig1, sig2), "Consistent signatures #" + i); + + bool shouldVerify = Ed448.Verify(sig1, 0, pk, 0, ctx, m, 0, mLen); + + Assert.IsTrue(shouldVerify, "Consistent sign/verify #" + i); + + sig1[Ed448.PublicKeySize - 1] ^= 0x80; + bool shouldNotVerify = Ed448.Verify(sig1, 0, pk, 0, ctx, m, 0, mLen); + + Assert.IsFalse(shouldNotVerify, "Consistent verification failure #" + i); + } + } + + [Test] + public void TestEd448Vector1() + { + CheckEd448Vector( + ( "6c82a562cb808d10d632be89c8513ebf" + + "6c929f34ddfa8c9f63c9960ef6e348a3" + + "528c8a3fcc2f044e39a3fc5b94492f8f" + + "032e7549a20098f95b"), + ( "5fd7449b59b461fd2ce787ec616ad46a" + + "1da1342485a70e1f8a0ea75d80e96778" + + "edf124769b46c7061bd6783df1e50f6c" + + "d1fa1abeafe8256180"), + "", + "", + ( "533a37f6bbe457251f023c0d88f976ae" + + "2dfb504a843e34d2074fd823d41a591f" + + "2b233f034f628281f2fd7a22ddd47d78" + + "28c59bd0a21bfd3980ff0d2028d4b18a" + + "9df63e006c5d1c2d345b925d8dc00b41" + + "04852db99ac5c7cdda8530a113a0f4db" + + "b61149f05a7363268c71d95808ff2e65" + + "2600"), + "Ed448 Vector #1"); + } + + [Test] + public void TestEd448Vector2() + { + CheckEd448Vector( + ( "c4eab05d357007c632f3dbb48489924d" + + "552b08fe0c353a0d4a1f00acda2c463a" + + "fbea67c5e8d2877c5e3bc397a659949e" + + "f8021e954e0a12274e"), + ( "43ba28f430cdff456ae531545f7ecd0a" + + "c834a55d9358c0372bfa0c6c6798c086" + + "6aea01eb00742802b8438ea4cb82169c" + + "235160627b4c3a9480"), + "03", + "", + ( "26b8f91727bd62897af15e41eb43c377" + + "efb9c610d48f2335cb0bd0087810f435" + + "2541b143c4b981b7e18f62de8ccdf633" + + "fc1bf037ab7cd779805e0dbcc0aae1cb" + + "cee1afb2e027df36bc04dcecbf154336" + + "c19f0af7e0a6472905e799f1953d2a0f" + + "f3348ab21aa4adafd1d234441cf807c0" + + "3a00"), + "Ed448 Vector #2"); + } + + [Test] + public void TestEd448Vector3() + { + CheckEd448Vector( + ( "c4eab05d357007c632f3dbb48489924d" + + "552b08fe0c353a0d4a1f00acda2c463a" + + "fbea67c5e8d2877c5e3bc397a659949e" + + "f8021e954e0a12274e"), + ( "43ba28f430cdff456ae531545f7ecd0a" + + "c834a55d9358c0372bfa0c6c6798c086" + + "6aea01eb00742802b8438ea4cb82169c" + + "235160627b4c3a9480"), + "03", + "666f6f", + ( "d4f8f6131770dd46f40867d6fd5d5055" + + "de43541f8c5e35abbcd001b32a89f7d2" + + "151f7647f11d8ca2ae279fb842d60721" + + "7fce6e042f6815ea000c85741de5c8da" + + "1144a6a1aba7f96de42505d7a7298524" + + "fda538fccbbb754f578c1cad10d54d0d" + + "5428407e85dcbc98a49155c13764e66c" + + "3c00"), + "Ed448 Vector #3"); + } + + [Test] + public void TestEd448Vector4() + { + CheckEd448Vector( + ( "cd23d24f714274e744343237b93290f5" + + "11f6425f98e64459ff203e8985083ffd" + + "f60500553abc0e05cd02184bdb89c4cc" + + "d67e187951267eb328"), + ( "dcea9e78f35a1bf3499a831b10b86c90" + + "aac01cd84b67a0109b55a36e9328b1e3" + + "65fce161d71ce7131a543ea4cb5f7e9f" + + "1d8b00696447001400"), + "0c3e544074ec63b0265e0c", + "", + ( "1f0a8888ce25e8d458a21130879b840a" + + "9089d999aaba039eaf3e3afa090a09d3" + + "89dba82c4ff2ae8ac5cdfb7c55e94d5d" + + "961a29fe0109941e00b8dbdeea6d3b05" + + "1068df7254c0cdc129cbe62db2dc957d" + + "bb47b51fd3f213fb8698f064774250a5" + + "028961c9bf8ffd973fe5d5c206492b14" + + "0e00"), + "Ed448 Vector #4"); + } + + [Test] + public void TestEd448Vector5() + { + CheckEd448Vector( + ( "258cdd4ada32ed9c9ff54e63756ae582" + + "fb8fab2ac721f2c8e676a72768513d93" + + "9f63dddb55609133f29adf86ec9929dc" + + "cb52c1c5fd2ff7e21b"), + ( "3ba16da0c6f2cc1f30187740756f5e79" + + "8d6bc5fc015d7c63cc9510ee3fd44adc" + + "24d8e968b6e46e6f94d19b945361726b" + + "d75e149ef09817f580"), + "64a65f3cdedcdd66811e2915", + "", + ( "7eeeab7c4e50fb799b418ee5e3197ff6" + + "bf15d43a14c34389b59dd1a7b1b85b4a" + + "e90438aca634bea45e3a2695f1270f07" + + "fdcdf7c62b8efeaf00b45c2c96ba457e" + + "b1a8bf075a3db28e5c24f6b923ed4ad7" + + "47c3c9e03c7079efb87cb110d3a99861" + + "e72003cbae6d6b8b827e4e6c143064ff" + + "3c00"), + "Ed448 Vector #5"); + } + + [Test] + public void TestEd448Vector6() + { + CheckEd448Vector( + ( "7ef4e84544236752fbb56b8f31a23a10" + + "e42814f5f55ca037cdcc11c64c9a3b29" + + "49c1bb60700314611732a6c2fea98eeb" + + "c0266a11a93970100e"), + ( "b3da079b0aa493a5772029f0467baebe" + + "e5a8112d9d3a22532361da294f7bb381" + + "5c5dc59e176b4d9f381ca0938e13c6c0" + + "7b174be65dfa578e80"), + "64a65f3cdedcdd66811e2915e7", + "", + ( "6a12066f55331b6c22acd5d5bfc5d712" + + "28fbda80ae8dec26bdd306743c5027cb" + + "4890810c162c027468675ecf645a8317" + + "6c0d7323a2ccde2d80efe5a1268e8aca" + + "1d6fbc194d3f77c44986eb4ab4177919" + + "ad8bec33eb47bbb5fc6e28196fd1caf5" + + "6b4e7e0ba5519234d047155ac727a105" + + "3100"), + "Ed448 Vector #6"); + } + + [Test] + public void TestEd448Vector64() + { + string m = + "bd0f6a3747cd561bdddf4640a332461a" + + "4a30a12a434cd0bf40d766d9c6d458e5" + + "512204a30c17d1f50b5079631f64eb31" + + "12182da3005835461113718d1a5ef944"; + + CheckEd448Vector( + ( "d65df341ad13e008567688baedda8e9d" + + "cdc17dc024974ea5b4227b6530e339bf" + + "f21f99e68ca6968f3cca6dfe0fb9f4fa" + + "b4fa135d5542ea3f01"), + ( "df9705f58edbab802c7f8363cfe5560a" + + "b1c6132c20a9f1dd163483a26f8ac53a" + + "39d6808bf4a1dfbd261b099bb03b3fb5" + + "0906cb28bd8a081f00"), + m, + "", + ( "554bc2480860b49eab8532d2a533b7d5" + + "78ef473eeb58c98bb2d0e1ce488a98b1" + + "8dfde9b9b90775e67f47d4a1c3482058" + + "efc9f40d2ca033a0801b63d45b3b722e" + + "f552bad3b4ccb667da350192b61c508c" + + "f7b6b5adadc2c8d9a446ef003fb05cba" + + "5f30e88e36ec2703b349ca229c267083" + + "3900"), + "Ed448 Vector #64"); + } + + [Test] + public void TestEd448Vector256() + { + string m = + "15777532b0bdd0d1389f636c5f6b9ba7" + + "34c90af572877e2d272dd078aa1e567c" + + "fa80e12928bb542330e8409f31745041" + + "07ecd5efac61ae7504dabe2a602ede89" + + "e5cca6257a7c77e27a702b3ae39fc769" + + "fc54f2395ae6a1178cab4738e543072f" + + "c1c177fe71e92e25bf03e4ecb72f47b6" + + "4d0465aaea4c7fad372536c8ba516a60" + + "39c3c2a39f0e4d832be432dfa9a706a6" + + "e5c7e19f397964ca4258002f7c0541b5" + + "90316dbc5622b6b2a6fe7a4abffd9610" + + "5eca76ea7b98816af0748c10df048ce0" + + "12d901015a51f189f3888145c03650aa" + + "23ce894c3bd889e030d565071c59f409" + + "a9981b51878fd6fc110624dcbcde0bf7" + + "a69ccce38fabdf86f3bef6044819de11"; + + CheckEd448Vector( + ( "2ec5fe3c17045abdb136a5e6a913e32a" + + "b75ae68b53d2fc149b77e504132d3756" + + "9b7e766ba74a19bd6162343a21c8590a" + + "a9cebca9014c636df5"), + ( "79756f014dcfe2079f5dd9e718be4171" + + "e2ef2486a08f25186f6bff43a9936b9b" + + "fe12402b08ae65798a3d81e22e9ec80e" + + "7690862ef3d4ed3a00"), + m, + "", + ( "c650ddbb0601c19ca11439e1640dd931" + + "f43c518ea5bea70d3dcde5f4191fe53f" + + "00cf966546b72bcc7d58be2b9badef28" + + "743954e3a44a23f880e8d4f1cfce2d7a" + + "61452d26da05896f0a50da66a239a8a1" + + "88b6d825b3305ad77b73fbac0836ecc6" + + "0987fd08527c1a8e80d5823e65cafe2a" + + "3d00"), + "Ed448 Vector #256"); + } + + [Test] + public void TestEd448Vector1023() + { + string m = + "6ddf802e1aae4986935f7f981ba3f035" + + "1d6273c0a0c22c9c0e8339168e675412" + + "a3debfaf435ed651558007db4384b650" + + "fcc07e3b586a27a4f7a00ac8a6fec2cd" + + "86ae4bf1570c41e6a40c931db27b2faa" + + "15a8cedd52cff7362c4e6e23daec0fbc" + + "3a79b6806e316efcc7b68119bf46bc76" + + "a26067a53f296dafdbdc11c77f7777e9" + + "72660cf4b6a9b369a6665f02e0cc9b6e" + + "dfad136b4fabe723d2813db3136cfde9" + + "b6d044322fee2947952e031b73ab5c60" + + "3349b307bdc27bc6cb8b8bbd7bd32321" + + "9b8033a581b59eadebb09b3c4f3d2277" + + "d4f0343624acc817804728b25ab79717" + + "2b4c5c21a22f9c7839d64300232eb66e" + + "53f31c723fa37fe387c7d3e50bdf9813" + + "a30e5bb12cf4cd930c40cfb4e1fc6225" + + "92a49588794494d56d24ea4b40c89fc0" + + "596cc9ebb961c8cb10adde976a5d602b" + + "1c3f85b9b9a001ed3c6a4d3b1437f520" + + "96cd1956d042a597d561a596ecd3d173" + + "5a8d570ea0ec27225a2c4aaff26306d1" + + "526c1af3ca6d9cf5a2c98f47e1c46db9" + + "a33234cfd4d81f2c98538a09ebe76998" + + "d0d8fd25997c7d255c6d66ece6fa56f1" + + "1144950f027795e653008f4bd7ca2dee" + + "85d8e90f3dc315130ce2a00375a318c7" + + "c3d97be2c8ce5b6db41a6254ff264fa6" + + "155baee3b0773c0f497c573f19bb4f42" + + "40281f0b1f4f7be857a4e59d416c06b4" + + "c50fa09e1810ddc6b1467baeac5a3668" + + "d11b6ecaa901440016f389f80acc4db9" + + "77025e7f5924388c7e340a732e554440" + + "e76570f8dd71b7d640b3450d1fd5f041" + + "0a18f9a3494f707c717b79b4bf75c984" + + "00b096b21653b5d217cf3565c9597456" + + "f70703497a078763829bc01bb1cbc8fa" + + "04eadc9a6e3f6699587a9e75c94e5bab" + + "0036e0b2e711392cff0047d0d6b05bd2" + + "a588bc109718954259f1d86678a579a3" + + "120f19cfb2963f177aeb70f2d4844826" + + "262e51b80271272068ef5b3856fa8535" + + "aa2a88b2d41f2a0e2fda7624c2850272" + + "ac4a2f561f8f2f7a318bfd5caf969614" + + "9e4ac824ad3460538fdc25421beec2cc" + + "6818162d06bbed0c40a387192349db67" + + "a118bada6cd5ab0140ee273204f628aa" + + "d1c135f770279a651e24d8c14d75a605" + + "9d76b96a6fd857def5e0b354b27ab937" + + "a5815d16b5fae407ff18222c6d1ed263" + + "be68c95f32d908bd895cd76207ae7264" + + "87567f9a67dad79abec316f683b17f2d" + + "02bf07e0ac8b5bc6162cf94697b3c27c" + + "d1fea49b27f23ba2901871962506520c" + + "392da8b6ad0d99f7013fbc06c2c17a56" + + "9500c8a7696481c1cd33e9b14e40b82e" + + "79a5f5db82571ba97bae3ad3e0479515" + + "bb0e2b0f3bfcd1fd33034efc6245eddd" + + "7ee2086ddae2600d8ca73e214e8c2b0b" + + "db2b047c6a464a562ed77b73d2d841c4" + + "b34973551257713b753632efba348169" + + "abc90a68f42611a40126d7cb21b58695" + + "568186f7e569d2ff0f9e745d0487dd2e" + + "b997cafc5abf9dd102e62ff66cba87"; + + CheckEd448Vector( + ( "872d093780f5d3730df7c212664b37b8" + + "a0f24f56810daa8382cd4fa3f77634ec" + + "44dc54f1c2ed9bea86fafb7632d8be19" + + "9ea165f5ad55dd9ce8"), + ( "a81b2e8a70a5ac94ffdbcc9badfc3feb" + + "0801f258578bb114ad44ece1ec0e799d" + + "a08effb81c5d685c0c56f64eecaef8cd" + + "f11cc38737838cf400"), + m, + "", + ( "e301345a41a39a4d72fff8df69c98075" + + "a0cc082b802fc9b2b6bc503f926b65bd" + + "df7f4c8f1cb49f6396afc8a70abe6d8a" + + "ef0db478d4c6b2970076c6a0484fe76d" + + "76b3a97625d79f1ce240e7c576750d29" + + "5528286f719b413de9ada3e8eb78ed57" + + "3603ce30d8bb761785dc30dbc320869e" + + "1a00"), + "Ed448 Vector #1023"); + } + + private static void CheckEd448Vector(string sSK, string sPK, string sM, string sCTX, string sSig, string text) + { + byte[] sk = Hex.Decode(sSK); + + byte[] pk = Hex.Decode(sPK); + byte[] pkGen = new byte[Ed448.PublicKeySize]; + Ed448.GeneratePublicKey(sk, 0, pkGen, 0); + Assert.IsTrue(Arrays.AreEqual(pk, pkGen), text); + + byte[] m = Hex.Decode(sM); + byte[] ctx = Hex.Decode(sCTX); + byte[] sig = Hex.Decode(sSig); + byte[] sigGen = new byte[Ed448.SignatureSize]; + Ed448.Sign(sk, 0, ctx, m, 0, m.Length, sigGen, 0); + Assert.IsTrue(Arrays.AreEqual(sig, sigGen), text); + + Ed448.Sign(sk, 0, pk, 0, ctx, m, 0, m.Length, sigGen, 0); + Assert.IsTrue(Arrays.AreEqual(sig, sigGen), text); + + bool shouldVerify = Ed448.Verify(sig, 0, pk, 0, ctx, m, 0, m.Length); + Assert.IsTrue(shouldVerify, text); + + sig[Ed448.SignatureSize - 1] ^= 0x80; + bool shouldNotVerify = Ed448.Verify(sig, 0, pk, 0, ctx, m, 0, m.Length); + Assert.IsFalse(shouldNotVerify, text); + } + } +} diff --git a/crypto/test/src/math/ec/test/ECPointTest.cs b/crypto/test/src/math/ec/test/ECPointTest.cs index 089fb88b3..a5ca083e2 100644 --- a/crypto/test/src/math/ec/test/ECPointTest.cs +++ b/crypto/test/src/math/ec/test/ECPointTest.cs @@ -442,6 +442,22 @@ namespace Org.BouncyCastle.Math.EC.Tests } } + private void ImplValidityTest(ECCurve c, ECPoint g) + { + Assert.IsTrue(g.IsValid()); + + BigInteger h = c.Cofactor; + if (h != null && h.CompareTo(BigInteger.One) > 0) + { + if (ECAlgorithms.IsF2mCurve(c)) + { + ECPoint order2 = c.CreatePoint(BigInteger.Zero, c.B.Sqrt().ToBigInteger()); + ECPoint bad = g.Add(order2); + Assert.IsFalse(bad.IsValid()); + } + } + } + private void ImplAddSubtractMultiplyTwiceEncodingTestAllCoords(X9ECParameters x9ECParameters) { BigInteger n = x9ECParameters.N; @@ -470,6 +486,8 @@ namespace Org.BouncyCastle.Math.EC.Tests ImplAddSubtractMultiplyTwiceEncodingTest(c, q, n); ImplSqrtTest(c); + + ImplValidityTest(c, g); } } } diff --git a/crypto/test/src/security/test/TestEncodings.cs b/crypto/test/src/security/test/TestEncodings.cs index 557d2dc51..a70d5b5b7 100644 --- a/crypto/test/src/security/test/TestEncodings.cs +++ b/crypto/test/src/security/test/TestEncodings.cs @@ -32,24 +32,19 @@ namespace Org.BouncyCastle.Security.Tests BigInteger ECPubQY = new BigInteger(Base64.Decode("JrlJfxu3WGhqwtL/55BOs/wsUeiDFsvXcGhB8DGx")); BigInteger ECPrivD = new BigInteger(Base64.Decode("GYQmd/NF1B+He1iMkWt3by2Az6Eu07t0ynJ4YCAo")); - FpCurve curve = new FpCurve( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b - - ECDomainParameters ecDomain = - new ECDomainParameters( - curve, - new FpPoint(curve, - curve.FromBigInteger(ECParraGX), - curve.FromBigInteger(ECParraGY)), - ECParraN); - - ECPublicKeyParameters ecPub = new ECPublicKeyParameters( - new FpPoint( - curve, - curve.FromBigInteger(ECPubQX), - curve.FromBigInteger(ECPubQY)), + FpCurve curve = new FpCurve( + new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q + new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a + new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b + ECParraN, ECParraH); + + ECDomainParameters ecDomain = new ECDomainParameters( + curve, + curve.ValidatePoint(ECParraGX, ECParraGY), + ECParraN, ECParraH); + + ECPublicKeyParameters ecPub = new ECPublicKeyParameters( + curve.ValidatePoint(ECPubQX, ECPubQY), ecDomain); ECPrivateKeyParameters ecPriv = new ECPrivateKeyParameters(ECPrivD, ecDomain); diff --git a/crypto/test/src/security/test/TestSignerUtil.cs b/crypto/test/src/security/test/TestSignerUtil.cs index d815d53a5..144ab67b1 100644 --- a/crypto/test/src/security/test/TestSignerUtil.cs +++ b/crypto/test/src/security/test/TestSignerUtil.cs @@ -56,18 +56,16 @@ namespace Org.BouncyCastle.Security.Tests FpCurve curve = new FpCurve( new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b + new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16), // b + ECParraN, ECParraH); - ECDomainParameters ecDomain = new ECDomainParameters(curve, - new FpPoint(curve, - curve.FromBigInteger(ECParraGX), - curve.FromBigInteger(ECParraGY)), - ECParraN); + ECDomainParameters ecDomain = new ECDomainParameters( + curve, + curve.ValidatePoint(ECParraGX, ECParraGY), + ECParraN, ECParraH); ECPublicKeyParameters ecPub = new ECPublicKeyParameters( - new FpPoint(curve, - curve.FromBigInteger(ECPubQX), - curve.FromBigInteger(ECPubQY)), + curve.ValidatePoint(ECPubQX, ECPubQY), ecDomain); ECPrivateKeyParameters ecPriv = new ECPrivateKeyParameters(ECPrivD, ecDomain); diff --git a/crypto/test/src/test/CertTest.cs b/crypto/test/src/test/CertTest.cs index 9a4965297..e3ce9df79 100644 --- a/crypto/test/src/test/CertTest.cs +++ b/crypto/test/src/test/CertTest.cs @@ -1391,15 +1391,9 @@ namespace Org.BouncyCastle.Tests */ internal void checkCreation3() { - ECCurve curve = new FpCurve( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b - - ECDomainParameters spec = new ECDomainParameters( - curve, - curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n + X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1"); + ECCurve curve = x9.Curve; + ECDomainParameters spec = new ECDomainParameters(curve, x9.G, x9.N, x9.H); ECPrivateKeyParameters privKey = new ECPrivateKeyParameters( "ECDSA", @@ -1533,16 +1527,9 @@ namespace Org.BouncyCastle.Tests string algorithm, DerObjectIdentifier algOid) { - FpCurve curve = new FpCurve( - new BigInteger("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151"), // q (or p) - new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", 16), // a - new BigInteger("0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", 16)); // b - - ECDomainParameters spec = new ECDomainParameters( - curve, -// curve.DecodePoint(Hex.Decode("02C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66")), // G - curve.DecodePoint(Hex.Decode("0200C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66")), // G - new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", 16)); // n + X9ECParameters x9 = ECNamedCurveTable.GetByName("secp521r1"); + ECCurve curve = x9.Curve; + ECDomainParameters spec = new ECDomainParameters(curve, x9.G, x9.N, x9.H); ECPrivateKeyParameters privKey = new ECPrivateKeyParameters( "ECDSA", diff --git a/crypto/test/src/test/DHTest.cs b/crypto/test/src/test/DHTest.cs index da31673de..f4eee348b 100644 --- a/crypto/test/src/test/DHTest.cs +++ b/crypto/test/src/test/DHTest.cs @@ -2,6 +2,7 @@ using System; using NUnit.Framework; +using Org.BouncyCastle.Asn1.X9; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; @@ -375,37 +376,22 @@ namespace Org.BouncyCastle.Tests [Test] public void TestECDH() { - doTestECDH("ECDH"); + DoTestECDH("ECDH"); } [Test] public void TestECDHC() { - doTestECDH("ECDHC"); + DoTestECDH("ECDHC"); } - private void doTestECDH( - string algorithm) + private void DoTestECDH(string algorithm) { IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator(algorithm); -// EllipticCurve curve = new EllipticCurve( -// new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q -// new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a -// new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b - ECCurve curve = new FpCurve( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b - - ECDomainParameters ecSpec = new ECDomainParameters( - curve, -// ECPointUtil.DecodePoint(curve, Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n - BigInteger.One); //1); // h - -// g.initialize(ecSpec, new SecureRandom()); + X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1"); + ECDomainParameters ecSpec = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H); + g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom())); // @@ -429,11 +415,6 @@ namespace Org.BouncyCastle.Tests // // agreement // -// aKeyAgreeBasic.doPhase(bKeyPair.Public, true); -// bKeyAgreeBasic.doPhase(aKeyPair.Public, true); -// -// BigInteger k1 = new BigInteger(aKeyAgreeBasic.generateSecret()); -// BigInteger k2 = new BigInteger(bKeyAgreeBasic.generateSecret()); BigInteger k1 = aKeyAgreeBasic.CalculateAgreement(bKeyPair.Public); BigInteger k2 = bKeyAgreeBasic.CalculateAgreement(aKeyPair.Public); diff --git a/crypto/test/src/test/DSATest.cs b/crypto/test/src/test/DSATest.cs index d7382d256..fb483dca7 100644 --- a/crypto/test/src/test/DSATest.cs +++ b/crypto/test/src/test/DSATest.cs @@ -252,15 +252,9 @@ namespace Org.BouncyCastle.Tests SecureRandom k = FixedSecureRandom.From(kData); - ECCurve curve = new FpCurve( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b - - ECDomainParameters spec = new ECDomainParameters( - curve, - curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n + X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1"); + ECCurve curve = x9.Curve; + ECDomainParameters spec = new ECDomainParameters(curve, x9.G, x9.N, x9.H); ECPrivateKeyParameters priKey = new ECPrivateKeyParameters( "ECDSA", @@ -330,17 +324,9 @@ namespace Org.BouncyCastle.Tests SecureRandom k = FixedSecureRandom.From(kData); - ECCurve curve = new F2mCurve( - 239, // m - 36, // k - new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16), // a - new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16)); // b - - ECDomainParameters parameters = new ECDomainParameters( - curve, - curve.DecodePoint(Hex.Decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G - new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"), // n - BigInteger.ValueOf(4)); // h + X9ECParameters x9 = ECNamedCurveTable.GetByName("c2tnb239v1"); + ECCurve curve = x9.Curve; + ECDomainParameters parameters = new ECDomainParameters(curve, x9.G, x9.N, x9.H); ECPrivateKeyParameters sKey = new ECPrivateKeyParameters( "ECDSA", @@ -435,17 +421,9 @@ namespace Org.BouncyCastle.Tests SecureRandom k = FixedSecureRandom.From(kData); - ECCurve curve = new F2mCurve( - 239, // m - 36, // k - new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16), // a - new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16)); // b - - ECDomainParameters parameters = new ECDomainParameters( - curve, - curve.DecodePoint(Hex.Decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G - new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"), // n - BigInteger.ValueOf(4)); // h + X9ECParameters x9 = ECNamedCurveTable.GetByName("c2tnb239v1"); + ECCurve curve = x9.Curve; + ECDomainParameters parameters = new ECDomainParameters(curve, x9.G, x9.N, x9.H); ECPrivateKeyParameters sKey = new ECPrivateKeyParameters( new BigInteger("145642755521911534651321230007534120304391871461646461466464667494947990"), // d @@ -554,15 +532,9 @@ namespace Org.BouncyCastle.Tests // s = SignerUtilities.GetSigner("ECDSA"); - ECCurve curve = new FpCurve( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b - - ECDomainParameters ecSpec = new ECDomainParameters( - curve, - curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n + X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1"); + ECCurve curve = x9.Curve; + ECDomainParameters ecSpec = new ECDomainParameters(curve, x9.G, x9.N, x9.H); g = GeneratorUtilities.GetKeyPairGenerator("ECDSA"); g.Init(new ECKeyGenerationParameters(ecSpec, rand)); @@ -594,17 +566,9 @@ namespace Org.BouncyCastle.Tests // s = SignerUtilities.GetSigner("ECDSA"); - curve = new F2mCurve( - 239, // m - 36, // k - new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16), // a - new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16)); // b - - ecSpec = new ECDomainParameters( - curve, - curve.DecodePoint(Hex.Decode("0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305")), // G - new BigInteger("220855883097298041197912187592864814557886993776713230936715041207411783"), // n - BigInteger.ValueOf(4)); // h + x9 = ECNamedCurveTable.GetByName("c2tnb239v1"); + curve = x9.Curve; + ecSpec = new ECDomainParameters(curve, x9.G, x9.N, x9.H); g = GeneratorUtilities.GetKeyPairGenerator("ECDSA"); g.Init(new ECKeyGenerationParameters(ecSpec, rand)); diff --git a/crypto/test/src/test/GOST3410Test.cs b/crypto/test/src/test/GOST3410Test.cs index 931332cfb..17a079470 100644 --- a/crypto/test/src/test/GOST3410Test.cs +++ b/crypto/test/src/test/GOST3410Test.cs @@ -29,19 +29,21 @@ namespace Org.BouncyCastle.Tests SecureRandom k = FixedSecureRandom.From(kData); - BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041"); //p + BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041"); + BigInteger mod_q = new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619"); ECCurve curve = new FpCurve( - mod_p, // p + mod_p, new BigInteger("7"), // a - new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414")); // b + new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414"), // b + mod_q, BigInteger.One); ECDomainParameters spec = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("2"), new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280")), - new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619")); // q + mod_q, BigInteger.One); ECPrivateKeyParameters sKey = new ECPrivateKeyParameters( "ECGOST3410", @@ -193,19 +195,21 @@ namespace Org.BouncyCastle.Tests s = SignerUtilities.GetSigner("ECGOST3410"); g = GeneratorUtilities.GetKeyPairGenerator("ECGOST3410"); - BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041"); //p + BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041"); + BigInteger mod_q = new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619"); ECCurve curve = new FpCurve( - mod_p, // p + mod_p, new BigInteger("7"), // a - new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414")); // b + new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414"), // b + mod_q, BigInteger.One); ECDomainParameters ecSpec = new ECDomainParameters( curve, curve.CreatePoint( new BigInteger("2"), new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280")), - new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619")); // q + mod_q, BigInteger.One); g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom())); diff --git a/crypto/test/src/test/IESTest.cs b/crypto/test/src/test/IESTest.cs index 812b05f97..fee2d7817 100644 --- a/crypto/test/src/test/IESTest.cs +++ b/crypto/test/src/test/IESTest.cs @@ -32,15 +32,8 @@ namespace Org.BouncyCastle.Tests { IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator("ECIES"); - ECCurve curve = new FpCurve( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b - - ECDomainParameters ecSpec = new ECDomainParameters( - curve, - curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n + X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1"); + ECDomainParameters ecSpec = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H); g.Init( new ECKeyGenerationParameters( diff --git a/crypto/test/src/test/MqvTest.cs b/crypto/test/src/test/MqvTest.cs index ec5c610ca..401fb3922 100644 --- a/crypto/test/src/test/MqvTest.cs +++ b/crypto/test/src/test/MqvTest.cs @@ -2,6 +2,7 @@ using System; using NUnit.Framework; +using Org.BouncyCastle.Asn1.X9; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; @@ -31,24 +32,10 @@ namespace Org.BouncyCastle.Tests { IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator("ECMQV"); -// EllipticCurve curve = new EllipticCurve( -// new ECFieldFp(new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839")), // q -// new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a -// new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b - ECCurve curve = new FpCurve( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b + X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1"); + ECDomainParameters ecSpec = new ECDomainParameters(x9.Curve, x9.G, x9.N, x9.H); - ECDomainParameters ecSpec = new ECDomainParameters( - curve, -// ECPointUtil.DecodePoint(curve, Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307"), // n - BigInteger.One); //1); // h - -// g.initialize(ecSpec, new SecureRandom()); - g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom())); + g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom())); // // U side diff --git a/crypto/test/src/test/PKCS10CertRequestTest.cs b/crypto/test/src/test/PKCS10CertRequestTest.cs index 7c96baea1..df10cad3f 100644 --- a/crypto/test/src/test/PKCS10CertRequestTest.cs +++ b/crypto/test/src/test/PKCS10CertRequestTest.cs @@ -126,16 +126,9 @@ namespace Org.BouncyCastle.Tests string algorithm, DerObjectIdentifier algOid) { - FpCurve curve = new FpCurve( - new BigInteger("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151"), // q (or p) - new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", 16), // a - new BigInteger("0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", 16)); // b - - ECDomainParameters spec = new ECDomainParameters( - curve, -// curve.DecodePoint(Hex.Decode("02C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66")), // G - curve.DecodePoint(Hex.Decode("0200C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66")), // G - new BigInteger("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", 16)); // n + X9ECParameters x9 = ECNamedCurveTable.GetByName("secp521r1"); + ECCurve curve = x9.Curve; + ECDomainParameters spec = new ECDomainParameters(curve, x9.G, x9.N, x9.H); ECPrivateKeyParameters privKey = new ECPrivateKeyParameters( new BigInteger("5769183828869504557786041598510887460263120754767955773309066354712783118202294874205844512909370791582896372147797293913785865682804434049019366394746072023"), // d @@ -413,15 +406,9 @@ namespace Org.BouncyCastle.Tests // elliptic curve openSSL IAsymmetricCipherKeyPairGenerator g = GeneratorUtilities.GetKeyPairGenerator("ECDSA"); - ECCurve curve = new FpCurve( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b - - ECDomainParameters ecSpec = new ECDomainParameters( - curve, - curve.DecodePoint(Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G - new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n + X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1"); + ECCurve curve = x9.Curve; + ECDomainParameters ecSpec = new ECDomainParameters(curve, x9.G, x9.N, x9.H); // g.initialize(ecSpec, new SecureRandom()); g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom())); diff --git a/crypto/test/src/x509/test/TestCertificateGen.cs b/crypto/test/src/x509/test/TestCertificateGen.cs index 019c2a460..670bf75c2 100644 --- a/crypto/test/src/x509/test/TestCertificateGen.cs +++ b/crypto/test/src/x509/test/TestCertificateGen.cs @@ -5,6 +5,7 @@ using System.Text; using NUnit.Framework; using Org.BouncyCastle.Asn1.X509; +using Org.BouncyCastle.Asn1.X9; using Org.BouncyCastle.Crypto.Digests; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Crypto.Signers; @@ -222,20 +223,14 @@ namespace Org.BouncyCastle.X509.Tests BigInteger ECPubQX = new BigInteger(Base64.Decode("HWWi17Yb+Bm3PYr/DMjLOYNFhyOwX1QY7ZvqqM+l")); BigInteger ECPubQY = new BigInteger(Base64.Decode("JrlJfxu3WGhqwtL/55BOs/wsUeiDFsvXcGhB8DGx")); BigInteger ECPrivD = new BigInteger(Base64.Decode("GYQmd/NF1B+He1iMkWt3by2Az6Eu07t0ynJ4YCAo")); - FpCurve curve = new FpCurve( - new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q - new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a - new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b - ECDomainParameters ecDomain = - new ECDomainParameters(curve, new FpPoint(curve, curve.FromBigInteger(ECParraGX), curve.FromBigInteger(ECParraGY)), ECParraN); - ECPublicKeyParameters ecPub = new ECPublicKeyParameters( - "ECDSA", - new FpPoint(curve, - curve.FromBigInteger(ECPubQX), - curve.FromBigInteger(ECPubQY)), - ecDomain); - ECPrivateKeyParameters ecPriv = new ECPrivateKeyParameters("ECDSA", ECPrivD, ecDomain); + X9ECParameters x9 = ECNamedCurveTable.GetByName("prime239v1"); + ECCurve curve = x9.Curve; + ECDomainParameters ecDomain = new ECDomainParameters(curve, curve.ValidatePoint(ECParraGX, ECParraGY), ECParraN, ECParraH); + + ECPublicKeyParameters ecPub = new ECPublicKeyParameters("ECDSA", + curve.ValidatePoint(ECPubQX, ECPubQY), ecDomain); + ECPrivateKeyParameters ecPriv = new ECPrivateKeyParameters("ECDSA", ECPrivD, ecDomain); IDictionary attrs = new Hashtable(); attrs[X509Name.C] = "AU"; |