summary refs log tree commit diff
path: root/crypto/test/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/test/src/math')
-rw-r--r--crypto/test/src/math/ec/rfc7748/test/X25519Test.cs18
-rw-r--r--crypto/test/src/math/ec/rfc7748/test/X448Test.cs14
2 files changed, 14 insertions, 18 deletions
diff --git a/crypto/test/src/math/ec/rfc7748/test/X25519Test.cs b/crypto/test/src/math/ec/rfc7748/test/X25519Test.cs
index 0b242a3c0..6ece6ed4b 100644
--- a/crypto/test/src/math/ec/rfc7748/test/X25519Test.cs
+++ b/crypto/test/src/math/ec/rfc7748/test/X25519Test.cs
@@ -49,23 +49,19 @@ namespace Org.BouncyCastle.Math.EC.Rfc7748.Tests
             for (int i = 1; i <= 100; ++i)
             {
                 // Each party generates an ephemeral private key, ...
-                Random.NextBytes(kA);
-                Random.NextBytes(kB);
+                X25519.GeneratePrivateKey(Random, kA);
+                X25519.GeneratePrivateKey(Random, kB);
 
                 // ... publishes their public key, ...
-                X25519.ScalarMultBase(kA, 0, qA, 0);
-                X25519.ScalarMultBase(kB, 0, qB, 0);
+                X25519.GeneratePublicKey(kA, 0, qA, 0);
+                X25519.GeneratePublicKey(kB, 0, qB, 0);
 
                 // ... computes the shared secret, ...
-                X25519.ScalarMult(kA, 0, qB, 0, sA, 0);
-                X25519.ScalarMult(kB, 0, qA, 0, sB, 0);
+                bool rA = X25519.CalculateAgreement(kA, 0, qB, 0, sA, 0);
+                bool rB = X25519.CalculateAgreement(kB, 0, qA, 0, sB, 0);
 
                 // ... which is the same for both parties.
-                //Assert.IsTrue(Arrays.AreEqual(sA, sB), "ECDH #" + i);
-                if (!Arrays.AreEqual(sA, sB))
-                {
-                    Console.WriteLine(" " + i);
-                }
+                Assert.IsTrue(rA == rB && Arrays.AreEqual(sA, sB), "ECDH #" + i);
             }
         }
 
diff --git a/crypto/test/src/math/ec/rfc7748/test/X448Test.cs b/crypto/test/src/math/ec/rfc7748/test/X448Test.cs
index 5737ebe7f..97b9de88e 100644
--- a/crypto/test/src/math/ec/rfc7748/test/X448Test.cs
+++ b/crypto/test/src/math/ec/rfc7748/test/X448Test.cs
@@ -49,19 +49,19 @@ namespace Org.BouncyCastle.Math.EC.Rfc7748.Tests
             for (int i = 1; i <= 100; ++i)
             {
                 // Each party generates an ephemeral private key, ...
-                Random.NextBytes(kA);
-                Random.NextBytes(kB);
+                X448.GeneratePrivateKey(Random, kA);
+                X448.GeneratePrivateKey(Random, kB);
 
                 // ... publishes their public key, ...
-                X448.ScalarMultBase(kA, 0, qA, 0);
-                X448.ScalarMultBase(kB, 0, qB, 0);
+                X448.GeneratePublicKey(kA, 0, qA, 0);
+                X448.GeneratePublicKey(kB, 0, qB, 0);
 
                 // ... computes the shared secret, ...
-                X448.ScalarMult(kA, 0, qB, 0, sA, 0);
-                X448.ScalarMult(kB, 0, qA, 0, sB, 0);
+                bool rA = X448.CalculateAgreement(kA, 0, qB, 0, sA, 0);
+                bool rB = X448.CalculateAgreement(kB, 0, qA, 0, sB, 0);
 
                 // ... which is the same for both parties.
-                Assert.IsTrue(Arrays.AreEqual(sA, sB), "ECDH #" + i);
+                Assert.IsTrue(rA == rB && Arrays.AreEqual(sA, sB), "ECDH #" + i);
             }
         }