Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-31 18:51:24 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-31 18:51:24 +0400
commit47fbc35135b5df8362e33f86798cd02752cf15d3 (patch)
tree524d10718fd8fa9e0892e8506ba5b72b13031904 /core/src/main/java/org/bouncycastle/math
parent295ab25768e57e223aa1981d1dabb68a505ff6ce (diff)
Make dec/inc/incExt methods work at the full length and change
assertions accordingly
Diffstat (limited to 'core/src/main/java/org/bouncycastle/math')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/Nat.java64
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat192.java18
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat256.java18
3 files changed, 49 insertions, 51 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/Nat.java b/core/src/main/java/org/bouncycastle/math/ec/Nat.java
index 5f9d753d..a7fafee0 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/Nat.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/Nat.java
@@ -32,18 +32,19 @@ public abstract class Nat
return (int)c;
}
-// public static int addDWord(int len, long x, int[] z, int zOff)
-// {
-// // assert zOff < (len - 2);
-// long c = x;
-// c += (z[zOff + 0] & M);
-// z[zOff + 0] = (int)c;
-// c >>>= 32;
-// c += (z[zOff + 1] & M);
-// z[zOff + 1] = (int)c;
-// c >>>= 32;
-// return c == 0 ? 0 : inc(len, z, zOff + 2);
-// }
+ // TODO Re-write to allow full range for x?
+ public static int addDWord(int len, long x, int[] z, int zOff)
+ {
+ // assert zOff <= (len - 2);
+ long c = x;
+ c += (z[zOff + 0] & M);
+ z[zOff + 0] = (int)c;
+ c >>>= 32;
+ c += (z[zOff + 1] & M);
+ z[zOff + 1] = (int)c;
+ c >>>= 32;
+ return c == 0 ? 0 : inc(len, z, zOff + 2);
+ }
public static int addExt(int len, int[] xx, int[] yy, int[] zz)
{
@@ -73,7 +74,8 @@ public abstract class Nat
public static int addWordExt(int len, int x, int[] zz, int zzOff)
{
- // assert zzOff < ((len << 1) - 1);
+ // int extLen = len << 1;
+ // assert zzOff <= (extLen - 1);
long c = (x & M) + (zz[zzOff + 0] & M);
zz[zzOff + 0] = (int)c;
c >>>= 32;
@@ -93,16 +95,14 @@ public abstract class Nat
public static int dec(int len, int[] z, int zOff)
{
- // assert zOff < len;
- int i = zOff;
- do
+ // assert zOff <= len;
+ for (int i = zOff; i < len; ++i)
{
if (--z[i] != -1)
{
return 0;
}
}
- while (++i < len);
return -1;
}
@@ -169,7 +169,7 @@ public abstract class Nat
public static int inc(int len, int[] z, int zOff)
{
- // assert zOff < len;
+ // assert zOff <= len;
for (int i = zOff; i < len; ++i)
{
if (++z[i] != 0)
@@ -183,7 +183,7 @@ public abstract class Nat
public static int incExt(int len, int[] zz, int zzOff)
{
int extLen = len;
- // assert zzOff < extLen;
+ // assert zzOff <= extLen;
for (int i = zzOff; i < extLen; ++i)
{
if (++zz[i] != 0)
@@ -263,7 +263,7 @@ public abstract class Nat
public static int mulWordDwordAdd(int len, int x, long y, int[] z, int zOff)
{
- // assert zOff < (len - 3);
+ // assert zOff <= (len - 3);
long c = 0, xVal = x & M;
c += xVal * (y & M) + (z[zOff + 0] & M);
z[zOff + 0] = (int)c;
@@ -426,17 +426,19 @@ public abstract class Nat
return (int)c;
}
-// public static int subDWord(int len, long x, int[] z)
-// {
-// long c = -x;
-// c += (z[0] & M);
-// z[0] = (int)c;
-// c >>= 32;
-// c += (z[1] & M);
-// z[1] = (int)c;
-// c >>= 32;
-// return c == 0 ? 0 : dec(len, z, 2);
-// }
+ // TODO Re-write to allow full range for x?
+ public static int subDWord(int len, long x, int[] z)
+ {
+ // assert 0 <= (len - 2);
+ long c = -x;
+ c += (z[0] & M);
+ z[0] = (int)c;
+ c >>= 32;
+ c += (z[1] & M);
+ z[1] = (int)c;
+ c >>= 32;
+ return c == 0 ? 0 : dec(len, z, 2);
+ }
public static int subExt(int len, int[] xx, int[] yy, int[] zz)
{
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat192.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat192.java
index 9e42d230..625954a6 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat192.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat192.java
@@ -59,7 +59,7 @@ public abstract class Nat192
// TODO Re-write to allow full range for x?
public static int addDWord(long x, int[] z, int zOff)
{
- // assert zOff < 4;
+ // assert zOff <= 4;
long c = x;
c += (z[zOff + 0] & M);
z[zOff + 0] = (int)c;
@@ -109,7 +109,7 @@ public abstract class Nat192
public static int addWordExt(int x, int[] zz, int zzOff)
{
- // assert zzOff < 11;
+ // assert zzOff <= 11;
long c = (x & M) + (zz[zzOff + 0] & M);
zz[zzOff + 0] = (int)c;
c >>>= 32;
@@ -128,16 +128,14 @@ public abstract class Nat192
public static int dec(int[] z, int zOff)
{
- // assert zOff < 6;
- int i = zOff;
- do
+ // assert zOff <= 6;
+ for (int i = zOff; i < 6; ++i)
{
if (--z[i] != -1)
{
return 0;
}
}
- while (++i < 6);
return -1;
}
@@ -203,7 +201,7 @@ public abstract class Nat192
public static int inc(int[] z, int zOff)
{
- // assert zOff < 6;
+ // assert zOff <= 6;
for (int i = zOff; i < 6; ++i)
{
if (++z[i] != 0)
@@ -216,7 +214,7 @@ public abstract class Nat192
public static int incExt(int[] zz, int zzOff)
{
- // assert zzOff < 12;
+ // assert zzOff <= 12;
for (int i = zzOff; i < 12; ++i)
{
if (++zz[i] != 0)
@@ -389,7 +387,7 @@ public abstract class Nat192
public static int mul33DWordAdd(int x, long y, int[] z, int zOff)
{
// assert x >>> 31 == 0;
- // assert zOff < 2;
+ // assert zOff <= 2;
long c = 0, xVal = x & M;
long y00 = y & M;
@@ -411,7 +409,7 @@ public abstract class Nat192
public static int mulWordDwordAdd(int x, long y, int[] z, int zOff)
{
- // assert zOff < 3;
+ // assert zOff <= 3;
long c = 0, xVal = x & M;
c += xVal * (y & M) + (z[zOff + 0] & M);
z[zOff + 0] = (int)c;
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat256.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat256.java
index 3e52d3be..0ffc6d35 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat256.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat256.java
@@ -71,7 +71,7 @@ public abstract class Nat256
// TODO Re-write to allow full range for x?
public static int addDWord(long x, int[] z, int zOff)
{
- // assert zOff < 6;
+ // assert zOff <= 6;
long c = x;
c += (z[zOff + 0] & M);
z[zOff + 0] = (int)c;
@@ -127,7 +127,7 @@ public abstract class Nat256
public static int addWordExt(int x, int[] zz, int zzOff)
{
- // assert zzOff < 15;
+ // assert zzOff <= 15;
long c = (x & M) + (zz[zzOff + 0] & M);
zz[zzOff + 0] = (int)c;
c >>>= 32;
@@ -146,16 +146,14 @@ public abstract class Nat256
public static int dec(int[] z, int zOff)
{
- // assert zOff < 8;
- int i = zOff;
- do
+ // assert zOff <= 8;
+ for (int i = zOff; i < 8; ++i)
{
if (--z[i] != -1)
{
return 0;
}
}
- while (++i < 8);
return -1;
}
@@ -221,7 +219,7 @@ public abstract class Nat256
public static int inc(int[] z, int zOff)
{
- // assert zOff < 8;
+ // assert zOff <= 8;
for (int i = zOff; i < 8; ++i)
{
if (++z[i] != 0)
@@ -234,7 +232,7 @@ public abstract class Nat256
public static int incExt(int[] zz, int zzOff)
{
- // assert zzOff < 16;
+ // assert zzOff <= 16;
for (int i = zzOff; i < 16; ++i)
{
if (++zz[i] != 0)
@@ -435,7 +433,7 @@ public abstract class Nat256
public static int mul33DWordAdd(int x, long y, int[] z, int zOff)
{
// assert x >>> 31 == 0;
- // assert zOff < 4;
+ // assert zOff <= 4;
long c = 0, xVal = x & M;
long y00 = y & M;
@@ -457,7 +455,7 @@ public abstract class Nat256
public static int mulWordDwordAdd(int x, long y, int[] z, int zOff)
{
- // assert zOff < 5;
+ // assert zOff <= 5;
long c = 0, xVal = x & M;
c += xVal * (y & M) + (z[zOff + 0] & M);
z[zOff + 0] = (int)c;