summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/UnitTests.csproj5
-rw-r--r--crypto/test/src/asn1/test/PrivateKeyInfoTest.cs60
-rw-r--r--crypto/test/src/asn1/test/RegressionTest.cs1
-rw-r--r--crypto/test/src/crypto/test/Ed25519Test.cs111
-rw-r--r--crypto/test/src/crypto/test/Ed448Test.cs107
-rw-r--r--crypto/test/src/crypto/test/RegressionTest.cs4
-rw-r--r--crypto/test/src/crypto/test/X25519Test.cs69
-rw-r--r--crypto/test/src/crypto/test/X448Test.cs69
-rw-r--r--crypto/test/src/math/ec/rfc8032/test/Ed25519Test.cs10
-rw-r--r--crypto/test/src/math/ec/rfc8032/test/Ed448Test.cs8
-rw-r--r--crypto/test/src/security/test/TestSignerUtil.cs18
11 files changed, 453 insertions, 9 deletions
diff --git a/crypto/test/UnitTests.csproj b/crypto/test/UnitTests.csproj
index 5f0e7af57..bb046c2b6 100644
--- a/crypto/test/UnitTests.csproj
+++ b/crypto/test/UnitTests.csproj
@@ -101,6 +101,7 @@
     <Compile Include="src\asn1\test\ParseTest.cs" />
     <Compile Include="src\asn1\test\ParsingTest.cs" />
     <Compile Include="src\asn1\test\PersonalDataUnitTest.cs" />
+    <Compile Include="src\asn1\test\PrivateKeyInfoTest.cs" />
     <Compile Include="src\asn1\test\ProcurationSyntaxUnitTest.cs" />
     <Compile Include="src\asn1\test\ProfessionInfoUnitTest.cs" />
     <Compile Include="src\asn1\test\QCStatementUnitTest.cs" />
@@ -186,6 +187,8 @@
     <Compile Include="src\crypto\test\ECIESTest.cs" />
     <Compile Include="src\crypto\test\ECNRTest.cs" />
     <Compile Include="src\crypto\test\ECTest.cs" />
+    <Compile Include="src\crypto\test\Ed25519Test.cs" />
+    <Compile Include="src\crypto\test\Ed448Test.cs" />
     <Compile Include="src\crypto\test\ElGamalTest.cs" />
     <Compile Include="src\crypto\test\EqualsHashCodeTest.cs" />
     <Compile Include="src\crypto\test\GCMTest.cs" />
@@ -284,6 +287,8 @@
     <Compile Include="src\crypto\test\VMPCMacTest.cs" />
     <Compile Include="src\crypto\test\VMPCTest.cs" />
     <Compile Include="src\crypto\test\WhirlpoolDigestTest.cs" />
+    <Compile Include="src\crypto\test\X25519Test.cs" />
+    <Compile Include="src\crypto\test\X448Test.cs" />
     <Compile Include="src\crypto\test\X931SignerTest.cs" />
     <Compile Include="src\crypto\test\XSalsa20Test.cs" />
     <Compile Include="src\crypto\test\XTEATest.cs" />
diff --git a/crypto/test/src/asn1/test/PrivateKeyInfoTest.cs b/crypto/test/src/asn1/test/PrivateKeyInfoTest.cs
new file mode 100644
index 000000000..eb17a54c3
--- /dev/null
+++ b/crypto/test/src/asn1/test/PrivateKeyInfoTest.cs
@@ -0,0 +1,60 @@
+using System;
+
+using NUnit.Framework;
+
+using Org.BouncyCastle.Asn1.Pkcs;
+using Org.BouncyCastle.Utilities.Encoders;
+using Org.BouncyCastle.Utilities.Test;
+
+namespace Org.BouncyCastle.Asn1.Tests
+{
+    [TestFixture]
+    public class PrivateKeyInfoTest
+        : SimpleTest
+    {
+        private static readonly byte[] priv = Base64.Decode(
+            "MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC");
+
+        private static readonly byte[] privWithPub = Base64.Decode(
+            "MHICAQEwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC" +
+            "oB8wHQYKKoZIhvcNAQkJFDEPDA1DdXJkbGUgQ2hhaXJzgSEAGb9ECWmEzf6FQbrB" +
+            "Z9w7lshQhqowtrbLDFw4rXAxZuE=");
+
+        public override string Name
+        {
+            get { return "PrivateKeyInfoTest"; }
+        }
+
+        public override void PerformTest()
+        {
+            PrivateKeyInfo privInfo1 = PrivateKeyInfo.GetInstance(priv);
+
+            IsTrue(!privInfo1.HasPublicKey);
+
+            PrivateKeyInfo privInfo2 = new PrivateKeyInfo(privInfo1.PrivateKeyAlgorithm, privInfo1.ParsePrivateKey());
+
+            IsTrue("enc 1 failed", AreEqual(priv, privInfo2.GetEncoded()));
+
+            privInfo1 = PrivateKeyInfo.GetInstance(privWithPub);
+
+            IsTrue(privInfo1.HasPublicKey);
+
+            privInfo2 = new PrivateKeyInfo(privInfo1.PrivateKeyAlgorithm, privInfo1.ParsePrivateKey(), privInfo1.Attributes, privInfo1.PublicKeyData.GetOctets());
+
+            IsTrue("enc 2 failed", AreEqual(privWithPub, privInfo2.GetEncoded()));
+        }
+
+        public static void Main(string[] args)
+        {
+            RunTest(new PrivateKeyInfoTest());
+        }
+
+        [Test]
+        public void TestFunction()
+        {
+            string resultText = Perform().ToString();
+
+            Assert.AreEqual(Name + ": Okay", resultText);
+        }
+    }
+}
diff --git a/crypto/test/src/asn1/test/RegressionTest.cs b/crypto/test/src/asn1/test/RegressionTest.cs
index 873ab4396..eeca9ccd0 100644
--- a/crypto/test/src/asn1/test/RegressionTest.cs
+++ b/crypto/test/src/asn1/test/RegressionTest.cs
@@ -51,6 +51,7 @@ namespace Org.BouncyCastle.Asn1.Tests
 			new Pkcs10Test(),
             new Pkcs12Test(),
 			new PkiFailureInfoTest(),
+            new PrivateKeyInfoTest(),
 			new ProcurationSyntaxUnitTest(),
 			new ProfessionInfoUnitTest(),
 			new QCStatementUnitTest(),
diff --git a/crypto/test/src/crypto/test/Ed25519Test.cs b/crypto/test/src/crypto/test/Ed25519Test.cs
new file mode 100644
index 000000000..82e36d991
--- /dev/null
+++ b/crypto/test/src/crypto/test/Ed25519Test.cs
@@ -0,0 +1,111 @@
+using System;
+
+using NUnit.Framework;
+
+using Org.BouncyCastle.Crypto.Generators;
+using Org.BouncyCastle.Crypto.Parameters;
+using Org.BouncyCastle.Crypto.Signers;
+using Org.BouncyCastle.Math.EC.Rfc8032;
+using Org.BouncyCastle.Security;
+using Org.BouncyCastle.Utilities.Test;
+
+namespace Org.BouncyCastle.Crypto.Tests
+{
+	[TestFixture]
+    public class Ed25519Test
+        : SimpleTest
+    {
+        private static readonly SecureRandom Random = new SecureRandom();
+
+        public override string Name
+        {
+            get { return "Ed25519"; }
+        }
+
+        public static void Main(string[] args)
+        {
+            RunTest(new Ed25519Test());
+        }
+
+        [Test]
+        public void TestFunction()
+        {
+            string resultText = Perform().ToString();
+
+            Assert.AreEqual(Name + ": Okay", resultText);
+        }
+
+        public override void PerformTest()
+        {
+            for (int i = 0; i < 10; ++i)
+            {
+                DoTestConsistency(Ed25519.Algorithm.Ed25519, null);
+
+                byte[] context = RandomContext(Random.NextInt() & 255);
+                DoTestConsistency(Ed25519.Algorithm.Ed25519ctx, context);
+                DoTestConsistency(Ed25519.Algorithm.Ed25519ph, context);
+            }
+        }
+
+        private ISigner CreateSigner(Ed25519.Algorithm algorithm, byte[] context)
+        {
+            switch (algorithm)
+            {
+            case Ed25519.Algorithm.Ed25519:
+                return new Ed25519Signer();
+            case Ed25519.Algorithm.Ed25519ctx:
+                return new Ed25519ctxSigner(context);
+            case Ed25519.Algorithm.Ed25519ph:
+                return new Ed25519phSigner(context);
+            default:
+                throw new ArgumentException("algorithm");
+            }
+        }
+
+        private byte[] RandomContext(int length)
+        {
+            byte[] context = new byte[length];
+            Random.NextBytes(context);
+            return context;
+        }
+
+        private void DoTestConsistency(Ed25519.Algorithm algorithm, byte[] context)
+        {
+            Ed25519KeyPairGenerator kpg = new Ed25519KeyPairGenerator();
+            kpg.Init(new Ed25519KeyGenerationParameters(Random));
+
+            AsymmetricCipherKeyPair kp = kpg.GenerateKeyPair();
+            Ed25519PrivateKeyParameters privateKey = (Ed25519PrivateKeyParameters)kp.Private;
+            Ed25519PublicKeyParameters publicKey = (Ed25519PublicKeyParameters)kp.Public;
+
+            byte[] msg = new byte[Random.NextInt() & 255];
+            Random.NextBytes(msg);
+
+            ISigner signer = CreateSigner(algorithm, context);
+            signer.Init(true, privateKey);
+            signer.BlockUpdate(msg, 0, msg.Length);
+            byte[] signature = signer.GenerateSignature();
+
+            ISigner verifier = CreateSigner(algorithm, context);
+            verifier.Init(false, publicKey);
+            verifier.BlockUpdate(msg, 0, msg.Length);
+            bool shouldVerify = verifier.VerifySignature(signature);
+
+            if (!shouldVerify)
+            {
+                Fail("Ed25519(" + algorithm + ") signature failed to verify");
+            }
+
+            signature[Random.Next() % signature.Length] ^= (byte)(1 << (Random.NextInt() & 7));
+
+            verifier.Init(false, publicKey);
+            verifier.BlockUpdate(msg, 0, msg.Length);
+            bool shouldNotVerify = verifier.VerifySignature(signature);
+
+            if (shouldNotVerify)
+            {
+                Fail("Ed25519(" + algorithm + ") bad signature incorrectly verified");
+            }
+        }
+    }
+}
diff --git a/crypto/test/src/crypto/test/Ed448Test.cs b/crypto/test/src/crypto/test/Ed448Test.cs
new file mode 100644
index 000000000..b035f554e
--- /dev/null
+++ b/crypto/test/src/crypto/test/Ed448Test.cs
@@ -0,0 +1,107 @@
+using System;
+
+using NUnit.Framework;
+
+using Org.BouncyCastle.Crypto.Generators;
+using Org.BouncyCastle.Crypto.Parameters;
+using Org.BouncyCastle.Crypto.Signers;
+using Org.BouncyCastle.Math.EC.Rfc8032;
+using Org.BouncyCastle.Security;
+using Org.BouncyCastle.Utilities.Test;
+
+namespace Org.BouncyCastle.Crypto.Tests
+{
+    [TestFixture]
+    public class Ed448Test
+        : SimpleTest
+    {
+        private static readonly SecureRandom Random = new SecureRandom();
+
+        public override string Name
+        {
+            get { return "Ed448"; }
+        }
+
+        public static void Main(string[] args)
+        {
+            RunTest(new Ed448Test());
+        }
+
+        [Test]
+        public void TestFunction()
+        {
+            string resultText = Perform().ToString();
+
+            Assert.AreEqual(Name + ": Okay", resultText);
+        }
+
+        public override void PerformTest()
+        {
+            for (int i = 0; i < 10; ++i)
+            {
+                byte[] context = RandomContext(Random.NextInt() & 255);
+                DoTestConsistency(Ed448.Algorithm.Ed448, context);
+                DoTestConsistency(Ed448.Algorithm.Ed448ph, context);
+            }
+        }
+
+        private ISigner CreateSigner(Ed448.Algorithm algorithm, byte[] context)
+        {
+            switch (algorithm)
+            {
+                case Ed448.Algorithm.Ed448:
+                    return new Ed448Signer(context);
+                case Ed448.Algorithm.Ed448ph:
+                    return new Ed448phSigner(context);
+                default:
+                    throw new ArgumentException("algorithm");
+            }
+        }
+
+        private byte[] RandomContext(int length)
+        {
+            byte[] context = new byte[length];
+            Random.NextBytes(context);
+            return context;
+        }
+
+        private void DoTestConsistency(Ed448.Algorithm algorithm, byte[] context)
+        {
+            Ed448KeyPairGenerator kpg = new Ed448KeyPairGenerator();
+            kpg.Init(new Ed448KeyGenerationParameters(Random));
+
+            AsymmetricCipherKeyPair kp = kpg.GenerateKeyPair();
+            Ed448PrivateKeyParameters privateKey = (Ed448PrivateKeyParameters)kp.Private;
+            Ed448PublicKeyParameters publicKey = (Ed448PublicKeyParameters)kp.Public;
+
+            byte[] msg = new byte[Random.NextInt() & 255];
+            Random.NextBytes(msg);
+
+            ISigner signer = CreateSigner(algorithm, context);
+            signer.Init(true, privateKey);
+            signer.BlockUpdate(msg, 0, msg.Length);
+            byte[] signature = signer.GenerateSignature();
+
+            ISigner verifier = CreateSigner(algorithm, context);
+            verifier.Init(false, publicKey);
+            verifier.BlockUpdate(msg, 0, msg.Length);
+            bool shouldVerify = verifier.VerifySignature(signature);
+
+            if (!shouldVerify)
+            {
+                Fail("Ed448(" + algorithm + ") signature failed to verify");
+            }
+
+            signature[Random.Next() % signature.Length] ^= (byte)(1 << (Random.NextInt() & 7));
+
+            verifier.Init(false, publicKey);
+            verifier.BlockUpdate(msg, 0, msg.Length);
+            bool shouldNotVerify = verifier.VerifySignature(signature);
+
+            if (shouldNotVerify)
+            {
+                Fail("Ed448(" + algorithm + ") bad signature incorrectly verified");
+            }
+        }
+    }
+}
diff --git a/crypto/test/src/crypto/test/RegressionTest.cs b/crypto/test/src/crypto/test/RegressionTest.cs
index 13fe23ecc..18aa62d97 100644
--- a/crypto/test/src/crypto/test/RegressionTest.cs
+++ b/crypto/test/src/crypto/test/RegressionTest.cs
@@ -133,6 +133,10 @@ namespace Org.BouncyCastle.Crypto.Tests
             new SM2EngineTest(),
             new SM2KeyExchangeTest(),
             new SM2SignerTest(),
+            new X25519Test(),
+            new X448Test(),
+            new Ed25519Test(),
+            new Ed448Test(),
         };
 
         public static void Main(string[] args)
diff --git a/crypto/test/src/crypto/test/X25519Test.cs b/crypto/test/src/crypto/test/X25519Test.cs
new file mode 100644
index 000000000..29466e0c6
--- /dev/null
+++ b/crypto/test/src/crypto/test/X25519Test.cs
@@ -0,0 +1,69 @@
+using System;
+
+using NUnit.Framework;
+
+using Org.BouncyCastle.Crypto.Agreement;
+using Org.BouncyCastle.Crypto.Generators;
+using Org.BouncyCastle.Crypto.Parameters;
+using Org.BouncyCastle.Security;
+using Org.BouncyCastle.Utilities.Test;
+
+namespace Org.BouncyCastle.Crypto.Tests
+{
+	[TestFixture]
+	public class X25519Test
+		: SimpleTest
+    {
+        private static readonly SecureRandom Random = new SecureRandom();
+
+        public override string Name
+        {
+            get { return "X25519"; }
+        }
+
+        public static void Main(string[] args)
+        {
+            RunTest(new X25519Test());
+        }
+
+        [Test]
+        public void TestFunction()
+        {
+            string resultText = Perform().ToString();
+
+            Assert.AreEqual(Name + ": Okay", resultText);
+        }
+
+        public override void PerformTest()
+        {
+            for (int i = 0; i < 10; ++i)
+            {
+                DoTestAgreement();
+            }
+        }
+
+        private void DoTestAgreement()
+        {
+            IAsymmetricCipherKeyPairGenerator kpGen = new X25519KeyPairGenerator();
+            kpGen.Init(new X25519KeyGenerationParameters(Random));
+
+            AsymmetricCipherKeyPair kpA = kpGen.GenerateKeyPair();
+            AsymmetricCipherKeyPair kpB = kpGen.GenerateKeyPair();
+
+            X25519Agreement agreeA = new X25519Agreement();
+            agreeA.Init(kpA.Private);
+            byte[] secretA = new byte[agreeA.AgreementSize];
+            agreeA.CalculateAgreement(kpB.Public, secretA, 0);
+
+            X25519Agreement agreeB = new X25519Agreement();
+            agreeB.Init(kpB.Private);
+            byte[] secretB = new byte[agreeB.AgreementSize];
+            agreeB.CalculateAgreement(kpA.Public, secretB, 0);
+
+            if (!AreEqual(secretA, secretB))
+            {
+                Fail("X25519 agreement failed");
+            }
+        }
+    }
+}
diff --git a/crypto/test/src/crypto/test/X448Test.cs b/crypto/test/src/crypto/test/X448Test.cs
new file mode 100644
index 000000000..5d4b14b63
--- /dev/null
+++ b/crypto/test/src/crypto/test/X448Test.cs
@@ -0,0 +1,69 @@
+using System;
+
+using NUnit.Framework;
+
+using Org.BouncyCastle.Crypto.Agreement;
+using Org.BouncyCastle.Crypto.Generators;
+using Org.BouncyCastle.Crypto.Parameters;
+using Org.BouncyCastle.Security;
+using Org.BouncyCastle.Utilities.Test;
+
+namespace Org.BouncyCastle.Crypto.Tests
+{
+    [TestFixture]
+    public class X448Test
+        : SimpleTest
+    {
+        private static readonly SecureRandom Random = new SecureRandom();
+
+        public override string Name
+        {
+            get { return "X448"; }
+        }
+
+        public static void Main(string[] args)
+        {
+            RunTest(new X448Test());
+        }
+
+        [Test]
+        public void TestFunction()
+        {
+            string resultText = Perform().ToString();
+
+            Assert.AreEqual(Name + ": Okay", resultText);
+        }
+
+        public override void PerformTest()
+        {
+            for (int i = 0; i < 10; ++i)
+            {
+                DoTestAgreement();
+            }
+        }
+
+        private void DoTestAgreement()
+        {
+            IAsymmetricCipherKeyPairGenerator kpGen = new X448KeyPairGenerator();
+            kpGen.Init(new X448KeyGenerationParameters(Random));
+
+            AsymmetricCipherKeyPair kpA = kpGen.GenerateKeyPair();
+            AsymmetricCipherKeyPair kpB = kpGen.GenerateKeyPair();
+
+            X448Agreement agreeA = new X448Agreement();
+            agreeA.Init(kpA.Private);
+            byte[] secretA = new byte[agreeA.AgreementSize];
+            agreeA.CalculateAgreement(kpB.Public, secretA, 0);
+
+            X448Agreement agreeB = new X448Agreement();
+            agreeB.Init(kpB.Private);
+            byte[] secretB = new byte[agreeB.AgreementSize];
+            agreeB.CalculateAgreement(kpA.Public, secretB, 0);
+
+            if (!AreEqual(secretA, secretB))
+            {
+                Fail("X448 agreement failed");
+            }
+        }
+    }
+}
diff --git a/crypto/test/src/math/ec/rfc8032/test/Ed25519Test.cs b/crypto/test/src/math/ec/rfc8032/test/Ed25519Test.cs
index 5a42daeae..8a61609af 100644
--- a/crypto/test/src/math/ec/rfc8032/test/Ed25519Test.cs
+++ b/crypto/test/src/math/ec/rfc8032/test/Ed25519Test.cs
@@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests
 				Random.NextBytes(sk);
                 Ed25519.GeneratePublicKey(sk, 0, pk, 0);
 
-                int mLen = Random.Next() & 255;
+                int mLen = Random.NextInt() & 255;
 
                 Ed25519.Sign(sk, 0, m, 0, mLen, sig1, 0);
                 Ed25519.Sign(sk, 0, pk, 0, m, 0, mLen, sig2, 0);
@@ -59,7 +59,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests
         {
             byte[] sk = new byte[Ed25519.SecretKeySize];
             byte[] pk = new byte[Ed25519.PublicKeySize];
-            byte[] ctx = new byte[Random.Next() & 7];
+            byte[] ctx = new byte[Random.NextInt() & 7];
             byte[] m = new byte[255];
             byte[] sig1 = new byte[Ed25519.SignatureSize];
             byte[] sig2 = new byte[Ed25519.SignatureSize];
@@ -72,7 +72,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests
                 Random.NextBytes(sk);
                 Ed25519.GeneratePublicKey(sk, 0, pk, 0);
 
-                int mLen = Random.Next() & 255;
+                int mLen = Random.NextInt() & 255;
 
                 Ed25519.Sign(sk, 0, ctx, m, 0, mLen, sig1, 0);
                 Ed25519.Sign(sk, 0, pk, 0, ctx, m, 0, mLen, sig2, 0);
@@ -95,7 +95,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests
         {
             byte[] sk = new byte[Ed25519.SecretKeySize];
             byte[] pk = new byte[Ed25519.PublicKeySize];
-            byte[] ctx = new byte[Random.Next() & 7];
+            byte[] ctx = new byte[Random.NextInt() & 7];
             byte[] m = new byte[255];
             byte[] ph = new byte[Ed25519.PrehashSize];
             byte[] sig1 = new byte[Ed25519.SignatureSize];
@@ -109,7 +109,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests
                 Random.NextBytes(sk);
                 Ed25519.GeneratePublicKey(sk, 0, pk, 0);
 
-                int mLen = Random.Next() & 255;
+                int mLen = Random.NextInt() & 255;
 
                 IDigest prehash = Ed25519.CreatePrehash();
                 prehash.BlockUpdate(m, 0, mLen);
diff --git a/crypto/test/src/math/ec/rfc8032/test/Ed448Test.cs b/crypto/test/src/math/ec/rfc8032/test/Ed448Test.cs
index 826f76345..cc8e82de0 100644
--- a/crypto/test/src/math/ec/rfc8032/test/Ed448Test.cs
+++ b/crypto/test/src/math/ec/rfc8032/test/Ed448Test.cs
@@ -25,7 +25,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests
         {
             byte[] sk = new byte[Ed448.SecretKeySize];
             byte[] pk = new byte[Ed448.PublicKeySize];
-            byte[] ctx = new byte[Random.Next() & 7];
+            byte[] ctx = new byte[Random.NextInt() & 7];
             byte[] m = new byte[255];
             byte[] sig1 = new byte[Ed448.SignatureSize];
             byte[] sig2 = new byte[Ed448.SignatureSize];
@@ -38,7 +38,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests
                 Random.NextBytes(sk);
                 Ed448.GeneratePublicKey(sk, 0, pk, 0);
 
-                int mLen = Random.Next() & 255;
+                int mLen = Random.NextInt() & 255;
 
                 Ed448.Sign(sk, 0, ctx, m, 0, mLen, sig1, 0);
                 Ed448.Sign(sk, 0, pk, 0, ctx, m, 0, mLen, sig2, 0);
@@ -61,7 +61,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests
         {
             byte[] sk = new byte[Ed448.SecretKeySize];
             byte[] pk = new byte[Ed448.PublicKeySize];
-            byte[] ctx = new byte[Random.Next() & 7];
+            byte[] ctx = new byte[Random.NextInt() & 7];
             byte[] m = new byte[255];
             byte[] ph = new byte[Ed448.PrehashSize];
             byte[] sig1 = new byte[Ed448.SignatureSize];
@@ -75,7 +75,7 @@ namespace Org.BouncyCastle.Math.EC.Rfc8032.Tests
                 Random.NextBytes(sk);
                 Ed448.GeneratePublicKey(sk, 0, pk, 0);
 
-                int mLen = Random.Next() & 255;
+                int mLen = Random.NextInt() & 255;
 
                 IXof prehash = Ed448.CreatePrehash();
                 prehash.BlockUpdate(m, 0, mLen);
diff --git a/crypto/test/src/security/test/TestSignerUtil.cs b/crypto/test/src/security/test/TestSignerUtil.cs
index f2ee4b048..dc3c1c81b 100644
--- a/crypto/test/src/security/test/TestSignerUtil.cs
+++ b/crypto/test/src/security/test/TestSignerUtil.cs
@@ -94,6 +94,14 @@ namespace Org.BouncyCastle.Security.Tests
 
             AsymmetricCipherKeyPair ecGostPair = ecGostKpg.GenerateKeyPair();
 
+            IAsymmetricCipherKeyPairGenerator ed25519Kpg = GeneratorUtilities.GetKeyPairGenerator("Ed25519");
+            ed25519Kpg.Init(new Ed25519KeyGenerationParameters(new SecureRandom()));
+            AsymmetricCipherKeyPair ed25519Pair = ed25519Kpg.GenerateKeyPair();
+
+            IAsymmetricCipherKeyPairGenerator ed448Kpg = GeneratorUtilities.GetKeyPairGenerator("Ed448");
+            ed448Kpg.Init(new Ed448KeyGenerationParameters(new SecureRandom()));
+            AsymmetricCipherKeyPair ed448Pair = ed448Kpg.GenerateKeyPair();
+
             //
             // GOST3410 parameters
             //
@@ -147,6 +155,16 @@ namespace Org.BouncyCastle.Security.Tests
                     signParams = ecGostPair.Private;
                     verifyParams = ecGostPair.Public;
                 }
+                else if (cipherName == "ED25519")
+                {
+                    signParams = ed25519Pair.Private;
+                    verifyParams = ed25519Pair.Public;
+                }
+                else if (cipherName == "ED448")
+                {
+                    signParams = ed448Pair.Private;
+                    verifyParams = ed448Pair.Public;
+                }
                 else if (cipherName == "GOST3410")
                 {
                     signParams = gostPair.Private;