summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-08-18 10:13:15 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-08-18 10:13:15 +0700
commit0adfd0489e2ea55522ad6bd9ba1b1afe238cdcbe (patch)
treeace64a80946b73d485e66e4740dbf0c6e0e60eda /crypto/test
parentExplicitly set IV to zeros when no ParametersWithIV (diff)
downloadBouncyCastle.NET-ed25519-0adfd0489e2ea55522ad6bd9ba1b1afe238cdcbe.tar.xz
Refactoring in Math.EC
Diffstat (limited to 'crypto/test')
-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);
             }
         }