summary refs log tree commit diff
path: root/crypto/src/math/ec/custom
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-30 15:13:55 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-30 15:13:55 +0700
commitd4a07a9a76b92e32e32463fbb908a2c531360163 (patch)
treeab28bf317d3d01ff41c4a38d5fa7077a40b0beec /crypto/src/math/ec/custom
parentCleanup various warnings, and reformatting (diff)
downloadBouncyCastle.NET-ed25519-d4a07a9a76b92e32e32463fbb908a2c531360163.tar.xz
Add SquareN to perform repeated modular squaring
Diffstat (limited to 'crypto/src/math/ec/custom')
-rw-r--r--crypto/src/math/ec/custom/sec/SecP256K1Field.cs15
-rw-r--r--crypto/src/math/ec/custom/sec/SecP256R1Field.cs15
2 files changed, 30 insertions, 0 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecP256K1Field.cs b/crypto/src/math/ec/custom/sec/SecP256K1Field.cs
index ec2c36e9f..527360cf6 100644
--- a/crypto/src/math/ec/custom/sec/SecP256K1Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecP256K1Field.cs
@@ -112,6 +112,21 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             Reduce(tt, z);
         }
 
+        public static void SquareN(uint[] x, int n, uint[] z)
+        {
+            Debug.Assert(n > 0);
+
+            uint[] tt = Nat256.CreateExt();
+            Nat256.Square(x, tt);
+            Reduce(tt, z);
+
+            while (--n > 0)
+            {
+                Nat256.Square(z, tt);
+                Reduce(tt, z);
+            }
+        }
+
         public static void Subtract(uint[] x, uint[] y, uint[] z)
         {
             int c = Nat256.Sub(x, y, z);
diff --git a/crypto/src/math/ec/custom/sec/SecP256R1Field.cs b/crypto/src/math/ec/custom/sec/SecP256R1Field.cs
index baea02dd0..cb9874bfd 100644
--- a/crypto/src/math/ec/custom/sec/SecP256R1Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecP256R1Field.cs
@@ -145,6 +145,21 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             Reduce(tt, z);
         }
 
+        public static void SquareN(uint[] x, int n, uint[] z)
+        {
+            Debug.Assert(n > 0);
+
+            uint[] tt = Nat256.CreateExt();
+            Nat256.Square(x, tt);
+            Reduce(tt, z);
+
+            while (--n > 0)
+            {
+                Nat256.Square(z, tt);
+                Reduce(tt, z);
+            }
+        }
+
         public static void Subtract(uint[] x, uint[] y, uint[] z)
         {
             int c = Nat256.Sub(x, y, z);