summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-07-31 17:49:43 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-07-31 17:49:43 +0700
commit89cf67c959f4080d67746946101a2375e761e039 (patch)
tree3da37f1e722e867a5e27f87e04f8bb86b16ff2b4
parentAccept only properly-sized BigInteger (no auto-reduction) (diff)
downloadBouncyCastle.NET-ed25519-89cf67c959f4080d67746946101a2375e761e039.tar.xz
Rework some of the ImplSquare methods in custom binary curves
-rw-r--r--crypto/src/math/ec/custom/sec/SecT131Field.cs1
-rw-r--r--crypto/src/math/ec/custom/sec/SecT163Field.cs5
-rw-r--r--crypto/src/math/ec/custom/sec/SecT233Field.cs5
-rw-r--r--crypto/src/math/ec/custom/sec/SecT239Field.cs5
-rw-r--r--crypto/src/math/ec/custom/sec/SecT283Field.cs8
-rw-r--r--crypto/src/math/ec/custom/sec/SecT409Field.cs10
-rw-r--r--crypto/src/math/ec/custom/sec/SecT571Field.cs13
7 files changed, 22 insertions, 25 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecT131Field.cs b/crypto/src/math/ec/custom/sec/SecT131Field.cs
index b59b0181b..248b1969e 100644
--- a/crypto/src/math/ec/custom/sec/SecT131Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT131Field.cs
@@ -321,7 +321,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
         {
             Interleave.Expand64To128(x[0], zz, 0);
             Interleave.Expand64To128(x[1], zz, 2);
-
             zz[4] = Interleave.Expand8to16((uint)x[2]);
         }
     }
diff --git a/crypto/src/math/ec/custom/sec/SecT163Field.cs b/crypto/src/math/ec/custom/sec/SecT163Field.cs
index e76e57b43..bc35ae6e8 100644
--- a/crypto/src/math/ec/custom/sec/SecT163Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT163Field.cs
@@ -329,10 +329,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
         {
             Interleave.Expand64To128(x[0], zz, 0);
             Interleave.Expand64To128(x[1], zz, 2);
-
-            ulong x2 = x[2];
-            zz[4] = Interleave.Expand32to64((uint)x2);
-            zz[5] = Interleave.Expand8to16((uint)(x2 >> 32));
+            Interleave.Expand64To128(x[2], zz, 4);
         }
     }
 }
diff --git a/crypto/src/math/ec/custom/sec/SecT233Field.cs b/crypto/src/math/ec/custom/sec/SecT233Field.cs
index bd493c586..013e6b8f9 100644
--- a/crypto/src/math/ec/custom/sec/SecT233Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT233Field.cs
@@ -306,10 +306,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             Interleave.Expand64To128(x[0], zz, 0);
             Interleave.Expand64To128(x[1], zz, 2);
             Interleave.Expand64To128(x[2], zz, 4);
-
-            ulong x3 = x[3];
-            zz[6] = Interleave.Expand32to64((uint)x3);
-            zz[7] = Interleave.Expand16to32((uint)(x3 >> 32));
+            Interleave.Expand64To128(x[3], zz, 6);
         }
     }
 }
diff --git a/crypto/src/math/ec/custom/sec/SecT239Field.cs b/crypto/src/math/ec/custom/sec/SecT239Field.cs
index 61b2ed6b7..b0c033fe2 100644
--- a/crypto/src/math/ec/custom/sec/SecT239Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT239Field.cs
@@ -317,10 +317,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             Interleave.Expand64To128(x[0], zz, 0);
             Interleave.Expand64To128(x[1], zz, 2);
             Interleave.Expand64To128(x[2], zz, 4);
-
-            ulong x3 = x[3];
-            zz[6] = Interleave.Expand32to64((uint)x3);
-            zz[7] = Interleave.Expand16to32((uint)(x3 >> 32));
+            Interleave.Expand64To128(x[3], zz, 6);
         }
     }
 }
diff --git a/crypto/src/math/ec/custom/sec/SecT283Field.cs b/crypto/src/math/ec/custom/sec/SecT283Field.cs
index 64fbc966d..ec2ba2cc1 100644
--- a/crypto/src/math/ec/custom/sec/SecT283Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT283Field.cs
@@ -390,10 +390,10 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         protected static void ImplSquare(ulong[] x, ulong[] zz)
         {
-            for (int i = 0; i < 4; ++i)
-            {
-                Interleave.Expand64To128(x[i], zz, i << 1);
-            }
+            Interleave.Expand64To128(x[0], zz, 0);
+            Interleave.Expand64To128(x[1], zz, 2);
+            Interleave.Expand64To128(x[2], zz, 4);
+            Interleave.Expand64To128(x[3], zz, 6);
             zz[8] = Interleave.Expand32to64((uint)x[4]);
         }
     }
diff --git a/crypto/src/math/ec/custom/sec/SecT409Field.cs b/crypto/src/math/ec/custom/sec/SecT409Field.cs
index f9962de5b..7cb9d4529 100644
--- a/crypto/src/math/ec/custom/sec/SecT409Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT409Field.cs
@@ -319,10 +319,12 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         protected static void ImplSquare(ulong[] x, ulong[] zz)
         {
-            for (int i = 0; i < 6; ++i)
-            {
-                Interleave.Expand64To128(x[i], zz, i << 1);
-            }
+            Interleave.Expand64To128(x[0], zz, 0);
+            Interleave.Expand64To128(x[1], zz, 2);
+            Interleave.Expand64To128(x[2], zz, 4);
+            Interleave.Expand64To128(x[3], zz, 6);
+            Interleave.Expand64To128(x[4], zz, 8);
+            Interleave.Expand64To128(x[5], zz, 10);
             zz[12] = Interleave.Expand32to64((uint)x[6]);
         }
     }
diff --git a/crypto/src/math/ec/custom/sec/SecT571Field.cs b/crypto/src/math/ec/custom/sec/SecT571Field.cs
index 9596aa5af..5a91985bc 100644
--- a/crypto/src/math/ec/custom/sec/SecT571Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT571Field.cs
@@ -322,10 +322,15 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         protected static void ImplSquare(ulong[] x, ulong[] zz)
         {
-            for (int i = 0; i < 9; ++i)
-            {
-                Interleave.Expand64To128(x[i], zz, i << 1);
-            }
+            Interleave.Expand64To128(x[0], zz, 0);
+            Interleave.Expand64To128(x[1], zz, 2);
+            Interleave.Expand64To128(x[2], zz, 4);
+            Interleave.Expand64To128(x[3], zz, 6);
+            Interleave.Expand64To128(x[4], zz, 8);
+            Interleave.Expand64To128(x[5], zz, 10);
+            Interleave.Expand64To128(x[6], zz, 12);
+            Interleave.Expand64To128(x[7], zz, 14);
+            Interleave.Expand64To128(x[8], zz, 16);
         }
     }
 }