summary refs log tree commit diff
path: root/crypto/src/math/ec/custom/sec/Nat192.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/math/ec/custom/sec/Nat192.cs')
-rw-r--r--crypto/src/math/ec/custom/sec/Nat192.cs100
1 files changed, 70 insertions, 30 deletions
diff --git a/crypto/src/math/ec/custom/sec/Nat192.cs b/crypto/src/math/ec/custom/sec/Nat192.cs
index 87dbcec84..94d7ed17c 100644
--- a/crypto/src/math/ec/custom/sec/Nat192.cs
+++ b/crypto/src/math/ec/custom/sec/Nat192.cs
@@ -588,8 +588,8 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             ulong x_0 = x[0];
             ulong zz_1;
 
+            uint c = 0, w;
             {
-                uint c = 0;
                 int i = 5, j = 12;
                 do
                 {
@@ -604,7 +604,8 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
                 {
                     ulong p = x_0 * x_0;
                     zz_1 = (ulong)(c << 31) | (p >> 33);
-                    zz[0] = (uint)(p >> 1);
+                    zz[0] = (uint)p;
+                    c = (uint)(p >> 32) & 1;
                 }
             }
 
@@ -613,7 +614,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
             {
                 zz_1 += x_1 * x_0;
-                zz[1] = (uint)zz_1;
+                w = (uint)zz_1;
+                zz[1] = (w << 1) | c;
+                c = w >> 31;
                 zz_2 += zz_1 >> 32;
             }
 
@@ -622,7 +625,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             ulong zz_4 = zz[4];
             {
                 zz_2 += x_2 * x_0;
-                zz[2] = (uint)zz_2;
+                w = (uint)zz_2;
+                zz[2] = (w << 1) | c;
+                c = w >> 31;
                 zz_3 += (zz_2 >> 32) + x_2 * x_1;
                 zz_4 += zz_3 >> 32;
                 zz_3 &= M;
@@ -633,7 +638,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             ulong zz_6 = zz[6];
             {
                 zz_3 += x_3 * x_0;
-                zz[3] = (uint)zz_3;
+                w = (uint)zz_3;
+                zz[3] = (w << 1) | c;
+                c = w >> 31;
                 zz_4 += (zz_3 >> 32) + x_3 * x_1;
                 zz_5 += (zz_4 >> 32) + x_3 * x_2;
                 zz_4 &= M;
@@ -646,7 +653,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             ulong zz_8 = zz[8];
             {
                 zz_4 += x_4 * x_0;
-                zz[4] = (uint)zz_4;
+                w = (uint)zz_4;
+                zz[4] = (w << 1) | c;
+                c = w >> 31;
                 zz_5 += (zz_4 >> 32) + x_4 * x_1;
                 zz_6 += (zz_5 >> 32) + x_4 * x_2;
                 zz_5 &= M;
@@ -661,7 +670,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             ulong zz_10 = zz[10];
             {
                 zz_5 += x_5 * x_0;
-                zz[5] = (uint)zz_5;
+                w = (uint)zz_5;
+                zz[5] = (w << 1) | c;
+                c = w >> 31;
                 zz_6 += (zz_5 >> 32) + x_5 * x_1;
                 zz_7 += (zz_6 >> 32) + x_5 * x_2;
                 zz_8 += (zz_7 >> 32) + x_5 * x_3;
@@ -669,14 +680,23 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
                 zz_10 += zz_9 >> 32;
             }
 
-            zz[6] = (uint)zz_6;
-            zz[7] = (uint)zz_7;
-            zz[8] = (uint)zz_8;
-            zz[9] = (uint)zz_9;
-            zz[10] = (uint)zz_10;
-            zz[11] += (uint)(zz_10 >> 32);
-
-            Nat.ShiftUpBit(12, zz, (uint)x_0 << 31);
+            w = (uint)zz_6;
+            zz[6] = (w << 1) | c;
+            c = w >> 31;
+            w = (uint)zz_7;
+            zz[7] = (w << 1) | c;
+            c = w >> 31;
+            w = (uint)zz_8;
+            zz[8] = (w << 1) | c;
+            c = w >> 31;
+            w = (uint)zz_9;
+            zz[9] = (w << 1) | c;
+            c = w >> 31;
+            w = (uint)zz_10;
+            zz[10] = (w << 1) | c;
+            c = w >> 31;
+            w = zz[11] + (uint)(zz_10 >> 32);
+            zz[11] = (w << 1) | c;
         }
 
         public static void Square(uint[] x, int xOff, uint[] zz, int zzOff)
@@ -684,8 +704,8 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             ulong x_0 = x[xOff + 0];
             ulong zz_1;
 
+            uint c = 0, w;
             {
-                uint c = 0;
                 int i = 5, j = 12;
                 do
                 {
@@ -700,7 +720,8 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
                 {
                     ulong p = x_0 * x_0;
                     zz_1 = (ulong)(c << 31) | (p >> 33);
-                    zz[zzOff + 0] = (uint)(p >> 1);
+                    zz[zzOff + 0] = (uint)p;
+                    c = (uint)(p >> 32) & 1;
                 }
             }
 
@@ -709,7 +730,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
             {
                 zz_1 += x_1 * x_0;
-                zz[zzOff + 1] = (uint)zz_1;
+                w = (uint)zz_1;
+                zz[zzOff + 1] = (w << 1) | c;
+                c = w >> 31;
                 zz_2 += zz_1 >> 32;
             }
 
@@ -718,7 +741,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             ulong zz_4 = zz[zzOff + 4];
             {
                 zz_2 += x_2 * x_0;
-                zz[zzOff + 2] = (uint)zz_2;
+                w = (uint)zz_2;
+                zz[zzOff + 2] = (w << 1) | c;
+                c = w >> 31;
                 zz_3 += (zz_2 >> 32) + x_2 * x_1;
                 zz_4 += zz_3 >> 32;
                 zz_3 &= M;
@@ -729,7 +754,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             ulong zz_6 = zz[zzOff + 6];
             {
                 zz_3 += x_3 * x_0;
-                zz[zzOff + 3] = (uint)zz_3;
+                w = (uint)zz_3;
+                zz[zzOff + 3] = (w << 1) | c;
+                c = w >> 31;
                 zz_4 += (zz_3 >> 32) + x_3 * x_1;
                 zz_5 += (zz_4 >> 32) + x_3 * x_2;
                 zz_4 &= M;
@@ -742,7 +769,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             ulong zz_8 = zz[zzOff + 8];
             {
                 zz_4 += x_4 * x_0;
-                zz[zzOff + 4] = (uint)zz_4;
+                w = (uint)zz_4;
+                zz[zzOff + 4] = (w << 1) | c;
+                c = w >> 31;
                 zz_5 += (zz_4 >> 32) + x_4 * x_1;
                 zz_6 += (zz_5 >> 32) + x_4 * x_2;
                 zz_5 &= M;
@@ -757,7 +786,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             ulong zz_10 = zz[zzOff + 10];
             {
                 zz_5 += x_5 * x_0;
-                zz[zzOff + 5] = (uint)zz_5;
+                w = (uint)zz_5;
+                zz[zzOff + 5] = (w << 1) | c;
+                c = w >> 31;
                 zz_6 += (zz_5 >> 32) + x_5 * x_1;
                 zz_7 += (zz_6 >> 32) + x_5 * x_2;
                 zz_8 += (zz_7 >> 32) + x_5 * x_3;
@@ -765,14 +796,23 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
                 zz_10 += zz_9 >> 32;
             }
 
-            zz[zzOff + 6] = (uint)zz_6;
-            zz[zzOff + 7] = (uint)zz_7;
-            zz[zzOff + 8] = (uint)zz_8;
-            zz[zzOff + 9] = (uint)zz_9;
-            zz[zzOff + 10] = (uint)zz_10;
-            zz[zzOff + 11] += (uint)(zz_10 >> 32);
-
-            Nat.ShiftUpBit(12, zz, zzOff, (uint)x_0 << 31);
+            w = (uint)zz_6;
+            zz[zzOff + 6] = (w << 1) | c;
+            c = w >> 31;
+            w = (uint)zz_7;
+            zz[zzOff + 7] = (w << 1) | c;
+            c = w >> 31;
+            w = (uint)zz_8;
+            zz[zzOff + 8] = (w << 1) | c;
+            c = w >> 31;
+            w = (uint)zz_9;
+            zz[zzOff + 9] = (w << 1) | c;
+            c = w >> 31;
+            w = (uint)zz_10;
+            zz[zzOff + 10] = (w << 1) | c;
+            c = w >> 31;
+            w = zz[zzOff + 11] + (uint)(zz_10 >> 32);
+            zz[zzOff + 11] = (w << 1) | c;
         }
 
         public static int Sub(uint[] x, uint[] y, uint[] z)