summary refs log tree commit diff
path: root/crypto/src/math/ec/custom/sec/SecT233Field.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-08-13 18:20:55 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-08-13 18:20:55 +0700
commitdbbd073f7c5081b5e92b1ba685142ea9ff4faeab (patch)
treeecd528a9233212f6e074fe53def9ae58e0126a57 /crypto/src/math/ec/custom/sec/SecT233Field.cs
parentSwitch from lookup table to bit twiddling (diff)
downloadBouncyCastle.NET-ed25519-dbbd073f7c5081b5e92b1ba685142ea9ff4faeab.tar.xz
Use Itoh-Tsujii inversion (with extended bases for some cases)
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecT233Field.cs')
-rw-r--r--crypto/src/math/ec/custom/sec/SecT233Field.cs33
1 files changed, 33 insertions, 0 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecT233Field.cs b/crypto/src/math/ec/custom/sec/SecT233Field.cs
index b36ffba2e..a2f73fd5d 100644
--- a/crypto/src/math/ec/custom/sec/SecT233Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT233Field.cs
@@ -45,6 +45,39 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return z;
         }
 
+        public static void Invert(ulong[] x, ulong[] z)
+        {
+            if (Nat256.IsZero64(x))
+                throw new InvalidOperationException();
+
+            // Itoh-Tsujii inversion
+
+            ulong[] t0 = Nat256.Create64();
+            ulong[] t1 = Nat256.Create64();
+
+            Square(x, t0);
+            Multiply(t0, x, t0);
+            Square(t0, t0);
+            Multiply(t0, x, t0);
+            SquareN(t0, 3, t1);
+            Multiply(t1, t0, t1);
+            Square(t1, t1);
+            Multiply(t1, x, t1);
+            SquareN(t1, 7, t0);
+            Multiply(t0, t1, t0);
+            SquareN(t0, 14, t1);
+            Multiply(t1, t0, t1);
+            Square(t1, t1);
+            Multiply(t1, x, t1);
+            SquareN(t1, 29, t0);
+            Multiply(t0, t1, t0);
+            SquareN(t0, 58, t1);
+            Multiply(t1, t0, t1);
+            SquareN(t1, 116, t0);
+            Multiply(t0, t1, t0);
+            Square(t0, z);
+        }
+
         public static void Multiply(ulong[] x, ulong[] y, ulong[] z)
         {
             ulong[] tt = Nat256.CreateExt64();