summary refs log tree commit diff
path: root/crypto/src/math/ec/custom/sec/Nat256.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-03-04 15:10:33 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-03-04 15:10:33 +0700
commitc2fe9bb1d2b4d3b8e01642068714c824a3c74581 (patch)
treee5a4712684f092946f6439e1e0e0938817313041 /crypto/src/math/ec/custom/sec/Nat256.cs
parentJust use shift methods from Nat class evverywhere (diff)
downloadBouncyCastle.NET-ed25519-c2fe9bb1d2b4d3b8e01642068714c824a3c74581.tar.xz
Remove some length-specific methods in favour of the Nat class
Add more method variations to Nat
Use customized reductions in various fields
Diffstat (limited to 'crypto/src/math/ec/custom/sec/Nat256.cs')
-rw-r--r--crypto/src/math/ec/custom/sec/Nat256.cs164
1 files changed, 3 insertions, 161 deletions
diff --git a/crypto/src/math/ec/custom/sec/Nat256.cs b/crypto/src/math/ec/custom/sec/Nat256.cs
index f4599b988..9c19f41ba 100644
--- a/crypto/src/math/ec/custom/sec/Nat256.cs
+++ b/crypto/src/math/ec/custom/sec/Nat256.cs
@@ -69,17 +69,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return (uint)c;
         }
 
-        public static uint Add33To(uint x, uint[] z)
-        {
-            ulong c = (ulong)z[0] + x;
-            z[0] = (uint)c;
-            c >>= 32;
-            c += (ulong)z[1] + 1;
-            z[1] = (uint)c;
-            c >>= 32;
-            return c == 0 ? 0 : Inc(z, 2);
-        }
-
         public static uint AddBothTo(uint[] x, uint[] y, uint[] z)
         {
             ulong c = 0;
@@ -140,30 +129,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return (uint)c;
         }
 
-        public static uint AddDWordAt(ulong x, uint[] z, int zPos)
-        {
-            Debug.Assert(zPos <= 6);
-            ulong c = (ulong)z[zPos + 0] + (x & M);
-            z[zPos + 0] = (uint)c;
-            c >>= 32;
-            c += (ulong)z[zPos + 1] + (x >> 32);
-            z[zPos + 1] = (uint)c;
-            c >>= 32;
-            return c == 0 ? 0 : Inc(z, zPos + 2);
-        }
-
-        public static uint AddExt(uint[] xx, uint[] yy, uint[] zz)
-        {
-            ulong c = 0;
-            for (int i = 0; i < 16; ++i)
-            {
-                c += (ulong)xx[i] + yy[i];
-                zz[i] = (uint)c;
-                c >>= 32;
-            }
-            return (uint)c;
-        }
-
         public static uint AddTo(uint[] x, uint[] z)
         {
             ulong c = 0;
@@ -262,24 +227,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return (uint)c;
         }
 
-        public static uint AddWord(uint x, uint[] z, int zOff)
-        {
-            Debug.Assert(zOff <= 7);
-            ulong c = (ulong)x + z[zOff + 0];
-            z[zOff + 0] = (uint)c;
-            c >>= 32;
-            return c == 0 ? 0 : Inc(z, zOff + 1);
-        }
-
-        public static uint AddWordExt(uint x, uint[] zz, int zzOff)
-        {
-            Debug.Assert(zzOff <= 15);
-            ulong c = (ulong)x + zz[zzOff + 0];
-            zz[zzOff + 0] = (uint)c;
-            c >>= 32;
-            return c == 0 ? 0 : IncExt(zz, zzOff + 1);
-        }
-
         public static void Copy(uint[] x, uint[] z)
         {
             z[0] = x[0];
@@ -302,32 +249,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return new uint[16];
         }
 
-        public static int Dec(uint[] z, int zOff)
-        {
-            Debug.Assert(zOff <= 8);
-            for (int i = zOff; i < 8; ++i)
-            {
-                if (--z[i] != uint.MaxValue)
-                {
-                    return 0;
-                }
-            }
-            return -1;
-        }
-
-        public static int DecExt(uint[] zz, int zzOff)
-        {
-            Debug.Assert(zzOff <= 16);
-            for (int i = zzOff; i < 16; ++i)
-            {
-                if (--zz[i] != uint.MaxValue)
-                {
-                    return 0;
-                }
-            }
-            return -1;
-        }
-
         public static bool Diff(uint[] x, int xOff, uint[] y, int yOff, uint[] z, int zOff)
         {
             bool pos = Gte(x, xOff, y, yOff);
@@ -421,32 +342,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return true;
         }
 
-        public static uint Inc(uint[] z, int zOff)
-        {
-            Debug.Assert(zOff <= 8);
-            for (int i = zOff; i < 8; ++i)
-            {
-                if (++z[i] != uint.MinValue)
-                {
-                    return 0;
-                }
-            }
-            return 1;
-        }
-
-        public static uint IncExt(uint[] zz, int zzOff)
-        {
-            Debug.Assert(zzOff <= 16);
-            for (int i = zzOff; i < 16; ++i)
-            {
-                if (++zz[i] != uint.MinValue)
-                {
-                    return 0;
-                }
-            }
-            return 1;
-        }
-
         public static bool IsOne(uint[] x)
         {
             if (x[0] != 1)
@@ -873,7 +768,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             c += z[zOff + 3];
             z[zOff + 3] = (uint)c;
             c >>= 32;
-            return c == 0 ? 0 : Inc(z, zOff + 4);
+            return c == 0 ? 0 : Nat.IncAt(8, z, zOff, 4);
         }
 
         public static uint Mul33WordAdd(uint x, uint y, uint[] z, int zOff)
@@ -890,7 +785,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             c += z[zOff + 2];
             z[zOff + 2] = (uint)c;
             c >>= 32;
-            return c == 0 ? 0 : Inc(z, zOff + 3);
+            return c == 0 ? 0 : Nat.IncAt(8, z, zOff, 3);
         }
 
         public static uint MulWordDwordAdd(uint x, ulong y, uint[] z, int zOff)
@@ -906,7 +801,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             c += z[zOff + 2];
             z[zOff + 2] = (uint)c;
             c >>= 32;
-            return c == 0 ? 0 : Inc(z, zOff + 3);
+            return c == 0 ? 0 : Nat.IncAt(8, z, zOff, 3);
         }
 
         public static uint MulWord(uint x, uint[] y, uint[] z, int zOff)
@@ -1255,17 +1150,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return (int)c;
         }
 
-        public static int Sub33From(uint x, uint[] z)
-        {
-            long c = (long)z[0] - x;
-            z[0] = (uint)c;
-            c >>= 32;
-            c += (long)z[1] - 1;
-            z[1] = (uint)c;
-            c >>= 32;
-            return c == 0 ? 0 : Dec(z, 2);
-        }
-
         public static int SubBothFrom(uint[] x, uint[] y, uint[] z)
         {
             long c = 0;
@@ -1296,30 +1180,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return (int)c;
         }
 
-        public static int SubDWordAt(ulong x, uint[] z, int zPos)
-        {
-            Debug.Assert(zPos <= 6);
-            long c = (long)z[zPos + 0] - (long)(x & M);
-            z[zPos + 0] = (uint)c;
-            c >>= 32;
-            c += (long)z[zPos + 1] - (long)(x >> 32);
-            z[zPos + 1] = (uint)c;
-            c >>= 32;
-            return c == 0 ? 0 : Dec(z, zPos + 2);
-        }
-
-        public static int SubExt(uint[] xx, uint[] yy, uint[] zz)
-        {
-            long c = 0;
-            for (int i = 0; i < 16; ++i)
-            {
-                c += (long)xx[i] - yy[i];
-                zz[i] = (uint)c;
-                c >>= 32;
-            }
-            return (int)c;
-        }
-
         public static int SubFrom(uint[] x, uint[] z)
         {
             long c = 0;
@@ -1380,24 +1240,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             return (int)c;
         }
 
-        public static int SubWord(uint x, uint[] z, int zOff)
-        {
-            Debug.Assert(zOff <= 7);
-            long c = (long)z[zOff + 0] - x;
-            z[zOff + 0] = (uint)c;
-            c >>= 32;
-            return c == 0 ? 0 : Dec(z, zOff + 1);
-        }
-
-        public static int SubWordExt(uint x, uint[] zz, int zzOff)
-        {
-            Debug.Assert(zzOff <= 15);
-            long c = (long)zz[zzOff + 0] - x;
-            zz[zzOff + 0] = (uint)c;
-            c >>= 32;
-            return c == 0 ? 0 : DecExt(zz, zzOff + 1);
-        }
-
         public static BigInteger ToBigInteger(uint[] x)
         {
             byte[] bs = new byte[32];