summary refs log tree commit diff
path: root/crypto/src/math/ec/custom/sec/SecT131Field.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-08-14 18:39:29 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-08-14 18:39:29 +0700
commit56f23bcdee9c54b6fa3222a759d8df3780e8ac68 (patch)
treee5fca176186ea692606506d78da2d57462abe43c /crypto/src/math/ec/custom/sec/SecT131Field.cs
parentAdd locking to lazy factory property (diff)
parentRefactor NextPacketTag() (diff)
downloadBouncyCastle.NET-ed25519-56f23bcdee9c54b6fa3222a759d8df3780e8ac68.tar.xz
Merge branch 'master' of git.bouncycastle.org:bc-csharp
Conflicts:
	crypto/src/asn1/x9/X9ECParametersHolder.cs
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecT131Field.cs')
-rw-r--r--crypto/src/math/ec/custom/sec/SecT131Field.cs33
1 files changed, 31 insertions, 2 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecT131Field.cs b/crypto/src/math/ec/custom/sec/SecT131Field.cs
index df75dfcd7..47f97078c 100644
--- a/crypto/src/math/ec/custom/sec/SecT131Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT131Field.cs
@@ -40,6 +40,35 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return z;
         }
 
+        public static void Invert(ulong[] x, ulong[] z)
+        {
+            if (Nat192.IsZero64(x))
+                throw new InvalidOperationException();
+
+            // Itoh-Tsujii inversion
+
+            ulong[] t0 = Nat192.Create64();
+            ulong[] t1 = Nat192.Create64();
+
+            Square(x, t0);
+            Multiply(t0, x, t0);
+            SquareN(t0, 2, t1);
+            Multiply(t1, t0, t1);
+            SquareN(t1, 4, t0);
+            Multiply(t0, t1, t0);
+            SquareN(t0, 8, t1);
+            Multiply(t1, t0, t1);
+            SquareN(t1, 16, t0);
+            Multiply(t0, t1, t0);
+            SquareN(t0, 32, t1);
+            Multiply(t1, t0, t1);
+            Square(t1, t1);
+            Multiply(t1, x, t1);
+            SquareN(t1, 65, t0);
+            Multiply(t0, t1, t0);
+            Square(t0, z);
+        }
+
         public static void Multiply(ulong[] x, ulong[] y, ulong[] z)
         {
             ulong[] tt = Nat192.CreateExt64();
@@ -231,7 +260,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             Debug.Assert(y >> 45 == 0);
 
             ulong[] u = new ulong[8];
-    //      u[0] = 0;
+            //u[0] = 0;
             u[1] = y;
             u[2] = u[1] << 1;
             u[3] = u[2] ^  y;
@@ -247,7 +276,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             int k = 33;
             do
             {
-                j = (uint)(x >> k);
+                j  = (uint)(x >> k);
                 g  = u[j & 7]
                    ^ u[(j >> 3) & 7] << 3
                    ^ u[(j >> 6) & 7] << 6