summary refs log tree commit diff
path: root/crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs')
-rw-r--r--crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs58
1 files changed, 30 insertions, 28 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs b/crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs
index d2ff05cb7..2bb83d5e9 100644
--- a/crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs
+++ b/crypto/src/math/ec/custom/sec/SecP256K1FieldElement.cs
@@ -141,49 +141,51 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             if (Nat256.IsZero(x1) || Nat256.IsOne(x1))
                 return this;
 
+            uint[] tt0 = Nat256.CreateExt();
+
             uint[] x2 = Nat256.Create();
-            SecP256K1Field.Square(x1, x2);
-            SecP256K1Field.Multiply(x2, x1, x2);
+            SecP256K1Field.Square(x1, x2, tt0);
+            SecP256K1Field.Multiply(x2, x1, x2, tt0);
             uint[] x3 = Nat256.Create();
-            SecP256K1Field.Square(x2, x3);
-            SecP256K1Field.Multiply(x3, x1, x3);
+            SecP256K1Field.Square(x2, x3, tt0);
+            SecP256K1Field.Multiply(x3, x1, x3, tt0);
             uint[] x6 = Nat256.Create();
-            SecP256K1Field.SquareN(x3, 3, x6);
-            SecP256K1Field.Multiply(x6, x3, x6);
+            SecP256K1Field.SquareN(x3, 3, x6, tt0);
+            SecP256K1Field.Multiply(x6, x3, x6, tt0);
             uint[] x9 = x6;
-            SecP256K1Field.SquareN(x6, 3, x9);
-            SecP256K1Field.Multiply(x9, x3, x9);
+            SecP256K1Field.SquareN(x6, 3, x9, tt0);
+            SecP256K1Field.Multiply(x9, x3, x9, tt0);
             uint[] x11 = x9;
-            SecP256K1Field.SquareN(x9, 2, x11);
-            SecP256K1Field.Multiply(x11, x2, x11);
+            SecP256K1Field.SquareN(x9, 2, x11, tt0);
+            SecP256K1Field.Multiply(x11, x2, x11, tt0);
             uint[] x22 = Nat256.Create();
-            SecP256K1Field.SquareN(x11, 11, x22);
-            SecP256K1Field.Multiply(x22, x11, x22);
+            SecP256K1Field.SquareN(x11, 11, x22, tt0);
+            SecP256K1Field.Multiply(x22, x11, x22, tt0);
             uint[] x44 = x11;
-            SecP256K1Field.SquareN(x22, 22, x44);
-            SecP256K1Field.Multiply(x44, x22, x44);
+            SecP256K1Field.SquareN(x22, 22, x44, tt0);
+            SecP256K1Field.Multiply(x44, x22, x44, tt0);
             uint[] x88 = Nat256.Create();
-            SecP256K1Field.SquareN(x44, 44, x88);
-            SecP256K1Field.Multiply(x88, x44, x88);
+            SecP256K1Field.SquareN(x44, 44, x88, tt0);
+            SecP256K1Field.Multiply(x88, x44, x88, tt0);
             uint[] x176 = Nat256.Create();
-            SecP256K1Field.SquareN(x88, 88, x176);
-            SecP256K1Field.Multiply(x176, x88, x176);
+            SecP256K1Field.SquareN(x88, 88, x176, tt0);
+            SecP256K1Field.Multiply(x176, x88, x176, tt0);
             uint[] x220 = x88;
-            SecP256K1Field.SquareN(x176, 44, x220);
-            SecP256K1Field.Multiply(x220, x44, x220);
+            SecP256K1Field.SquareN(x176, 44, x220, tt0);
+            SecP256K1Field.Multiply(x220, x44, x220, tt0);
             uint[] x223 = x44;
-            SecP256K1Field.SquareN(x220, 3, x223);
-            SecP256K1Field.Multiply(x223, x3, x223);
+            SecP256K1Field.SquareN(x220, 3, x223, tt0);
+            SecP256K1Field.Multiply(x223, x3, x223, tt0);
 
             uint[] t1 = x223;
-            SecP256K1Field.SquareN(t1, 23, t1);
-            SecP256K1Field.Multiply(t1, x22, t1);
-            SecP256K1Field.SquareN(t1, 6, t1);
-            SecP256K1Field.Multiply(t1, x2, t1);
-            SecP256K1Field.SquareN(t1, 2, t1);
+            SecP256K1Field.SquareN(t1, 23, t1, tt0);
+            SecP256K1Field.Multiply(t1, x22, t1, tt0);
+            SecP256K1Field.SquareN(t1, 6, t1, tt0);
+            SecP256K1Field.Multiply(t1, x2, t1, tt0);
+            SecP256K1Field.SquareN(t1, 2, t1, tt0);
 
             uint[] t2 = x2;
-            SecP256K1Field.Square(t1, t2);
+            SecP256K1Field.Square(t1, t2, tt0);
 
             return Nat256.Eq(x1, t2) ? new SecP256K1FieldElement(t1) : null;
         }