summary refs log tree commit diff
path: root/crypto/src/math/ec/custom/sec
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-31 21:53:29 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-31 21:53:29 +0700
commitcce9d8ee72cbfbfb8097284cad4f1af58093c490 (patch)
treec721ed8b17fcfa5fb61b25f45b82ce68f2bcb3ae /crypto/src/math/ec/custom/sec
parentAvoid modifying the input to the Reduce() methods (diff)
downloadBouncyCastle.NET-ed25519-cce9d8ee72cbfbfb8097284cad4f1af58093c490.tar.xz
Make Dec/Inc/IncExt methods work at the full length and change assertions accordingly
Diffstat (limited to 'crypto/src/math/ec/custom/sec')
-rw-r--r--crypto/src/math/ec/custom/sec/Nat192.cs22
-rw-r--r--crypto/src/math/ec/custom/sec/Nat256.cs22
2 files changed, 20 insertions, 24 deletions
diff --git a/crypto/src/math/ec/custom/sec/Nat192.cs b/crypto/src/math/ec/custom/sec/Nat192.cs
index 29f6f28e6..22f79c9d3 100644
--- a/crypto/src/math/ec/custom/sec/Nat192.cs
+++ b/crypto/src/math/ec/custom/sec/Nat192.cs
@@ -60,7 +60,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
         // TODO Re-write to allow full range for x?
         public static uint AddDWord(ulong x, uint[] z, int zOff)
         {
-            Debug.Assert(zOff < 4);
+            Debug.Assert(zOff <= 4);
             ulong c = x;
             c += (ulong)z[zOff + 0];
             z[zOff + 0] = (uint)c;
@@ -110,7 +110,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static uint AddWordExt(uint x, uint[] zz, int zzOff)
         {
-            Debug.Assert(zzOff < 11);
+            Debug.Assert(zzOff <= 11);
             ulong c = (ulong)x + zz[zzOff + 0];
             zz[zzOff + 0] = (uint)c;
             c >>= 32;
@@ -129,16 +129,14 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static int Dec(uint[] z, int zOff)
         {
-            Debug.Assert(zOff < 6);
-            int i = zOff;
-            do
+            Debug.Assert(zOff <= 6);
+            for (int i = zOff; i < 6; ++i)
             {
                 if (--z[i] != uint.MaxValue)
                 {
                     return 0;
                 }
             }
-            while (++i < 6);
             return -1;
         }
 
@@ -200,10 +198,10 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static uint Inc(uint[] z, int zOff)
         {
-            Debug.Assert(zOff < 6);
+            Debug.Assert(zOff <= 6);
             for (int i = zOff; i < 6; ++i)
             {
-                if (++z[i] != 0)
+                if (++z[i] != uint.MinValue)
                 {
                     return 0;
                 }
@@ -213,10 +211,10 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static uint IncExt(uint[] zz, int zzOff)
         {
-            Debug.Assert(zzOff < 12);
+            Debug.Assert(zzOff <= 12);
             for (int i = zzOff; i < 12; ++i)
             {
-                if (++zz[i] != 0)
+                if (++zz[i] != uint.MinValue)
                 {
                     return 0;
                 }
@@ -385,7 +383,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
         public static uint Mul33DWordAdd(uint x, ulong y, uint[] z, int zOff)
         {
             Debug.Assert(x >> 31 == 0);
-            Debug.Assert(zOff < 2);
+            Debug.Assert(zOff <= 2);
             ulong c = 0, xVal = x;
             ulong y00 = y & M;
             c += xVal * y00 + z[zOff + 0];
@@ -406,7 +404,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static uint MulWordDwordAdd(uint x, ulong y, uint[] z, int zOff)
         {
-            Debug.Assert(zOff < 4);
+            Debug.Assert(zOff <= 3);
             ulong c = 0, xVal = x;
             c += xVal * y + z[zOff + 0];
             z[zOff + 0] = (uint)c;
diff --git a/crypto/src/math/ec/custom/sec/Nat256.cs b/crypto/src/math/ec/custom/sec/Nat256.cs
index 5837a8820..b0326716a 100644
--- a/crypto/src/math/ec/custom/sec/Nat256.cs
+++ b/crypto/src/math/ec/custom/sec/Nat256.cs
@@ -72,7 +72,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
         // TODO Re-write to allow full range for x?
         public static uint AddDWord(ulong x, uint[] z, int zOff)
         {
-            Debug.Assert(zOff < 6);
+            Debug.Assert(zOff <= 6);
             ulong c = x;
             c += (ulong)z[zOff + 0];
             z[zOff + 0] = (uint)c;
@@ -128,7 +128,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static uint AddWordExt(uint x, uint[] zz, int zzOff)
         {
-            Debug.Assert(zzOff < 15);
+            Debug.Assert(zzOff <= 15);
             ulong c = (ulong)x + zz[zzOff + 0];
             zz[zzOff + 0] = (uint)c;
             c >>= 32;
@@ -147,16 +147,14 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static int Dec(uint[] z, int zOff)
         {
-            Debug.Assert(zOff < 8);
-            int i = zOff;
-            do
+            Debug.Assert(zOff <= 8);
+            for (int i = zOff; i < 8; ++i)
             {
                 if (--z[i] != uint.MaxValue)
                 {
                     return 0;
                 }
             }
-            while (++i < 8);
             return -1;
         }
 
@@ -218,10 +216,10 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static uint Inc(uint[] z, int zOff)
         {
-            Debug.Assert(zOff < 8);
+            Debug.Assert(zOff <= 8);
             for (int i = zOff; i < 8; ++i)
             {
-                if (++z[i] != 0)
+                if (++z[i] != uint.MinValue)
                 {
                     return 0;
                 }
@@ -231,10 +229,10 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static uint IncExt(uint[] zz, int zzOff)
         {
-            Debug.Assert(zzOff < 16);
+            Debug.Assert(zzOff <= 16);
             for (int i = zzOff; i < 16; ++i)
             {
-                if (++zz[i] != 0)
+                if (++zz[i] != uint.MinValue)
                 {
                     return 0;
                 }
@@ -431,7 +429,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
         public static uint Mul33DWordAdd(uint x, ulong y, uint[] z, int zOff)
         {
             Debug.Assert(x >> 31 == 0);
-            Debug.Assert(zOff < 4);
+            Debug.Assert(zOff <= 4);
             ulong c = 0, xVal = x;
             ulong y00 = y & M;
             c += xVal * y00 + z[zOff + 0];
@@ -452,7 +450,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static uint MulWordDwordAdd(uint x, ulong y, uint[] z, int zOff)
         {
-            Debug.Assert(zOff < 5);
+            Debug.Assert(zOff <= 5);
             ulong c = 0, xVal = x;
             c += xVal * y + z[zOff + 0];
             z[zOff + 0] = (uint)c;