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>2013-10-01 12:42:18 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2013-10-01 12:42:18 +0400
commita6a7b91076da38d9f08dd94804416b02eab3bd2c (patch)
tree75faf793b77bff631c15c92a3d6e75bee9a0586d /core/src/main/java
parentd018a8d36dce6e5d2921b4a7e2c4fb0479d196f0 (diff)
Don't store t
Check BigInteger in IntArray
Diffstat (limited to 'core/src/main/java')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/ECFieldElement.java19
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/IntArray.java34
2 files changed, 12 insertions, 41 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/ECFieldElement.java b/core/src/main/java/org/bouncycastle/math/ec/ECFieldElement.java
index 3716e47e..8d91070a 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/ECFieldElement.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/ECFieldElement.java
@@ -1016,11 +1016,6 @@ public abstract class ECFieldElement
private int[] ks;
/**
- * The number of <code>int</code>s required to hold <code>m</code> bits.
- */
- private int t;
-
- /**
* The <code>IntArray</code> holding the bits.
*/
private IntArray x;
@@ -1048,11 +1043,6 @@ public abstract class ECFieldElement
int k3,
BigInteger x)
{
- if (x == null || x.signum() < 0)
- {
- throw new IllegalArgumentException("x value invalid in F2m field element");
- }
-
if ((k2 == 0) && (k3 == 0))
{
this.representation = TPB;
@@ -1075,9 +1065,7 @@ public abstract class ECFieldElement
}
this.m = m;
- // t = m / 32 rounded up to the next integer
- this.t = (m + 31) >> 5;
- this.x = new IntArray(x, t);
+ this.x = new IntArray(x);
}
/**
@@ -1098,11 +1086,10 @@ public abstract class ECFieldElement
private F2m(int m, int[] ks, IntArray x)
{
- this.t = (m + 31) >> 5;
- this.x = x;
this.m = m;
this.representation = (ks.length == 1) ? TPB : PPB;
this.ks = ks;
+ this.x = x;
}
public int bitLength()
@@ -1239,6 +1226,8 @@ public abstract class ECFieldElement
// u(z) := a(z)
IntArray uz = (IntArray)this.x.clone();
+ int t = (m + 31) >>> 5;
+
// v(z) := f(z)
IntArray vz = new IntArray(t);
vz.setBit(m);
diff --git a/core/src/main/java/org/bouncycastle/math/ec/IntArray.java b/core/src/main/java/org/bouncycastle/math/ec/IntArray.java
index 294f1e46..1cd7149a 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/IntArray.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/IntArray.java
@@ -69,15 +69,11 @@ class IntArray
public IntArray(BigInteger bigInt)
{
- this(bigInt, 0);
- }
-
- public IntArray(BigInteger bigInt, int minIntLen)
- {
- if (bigInt.signum() == -1)
+ if (bigInt == null || bigInt.signum() < 0)
{
- throw new IllegalArgumentException("Only positive Integers allowed");
+ throw new IllegalArgumentException("invalid F2m field value");
}
+
if (bigInt.equals(ECConstants.ZERO))
{
m_ints = new int[] { 0 };
@@ -95,14 +91,7 @@ class IntArray
barrStart = 1;
}
int intLen = (barrLen + 3) / 4;
- if (intLen < minIntLen)
- {
- m_ints = new int[minIntLen];
- }
- else
- {
- m_ints = new int[intLen];
- }
+ m_ints = new int[intLen];
int iarrJ = intLen - 1;
int rem = barrLen % 4 + barrStart;
@@ -113,11 +102,7 @@ class IntArray
for (; barrI < rem; barrI++)
{
temp <<= 8;
- int barrBarrI = barr[barrI];
- if (barrBarrI < 0)
- {
- barrBarrI += 256;
- }
+ int barrBarrI = barr[barrI] & 0xFF;
temp |= barrBarrI;
}
m_ints[iarrJ--] = temp;
@@ -129,11 +114,7 @@ class IntArray
for (int i = 0; i < 4; i++)
{
temp <<= 8;
- int barrBarrI = barr[barrI++];
- if (barrBarrI < 0)
- {
- barrBarrI += 256;
- }
+ int barrBarrI = barr[barrI++] & 0xFF;
temp |= barrBarrI;
}
m_ints[iarrJ] = temp;
@@ -714,7 +695,8 @@ class IntArray
int hash = 1;
for (int i = 0; i < usedLen; i++)
{
- hash = hash * 31 + m_ints[i];
+ hash *= 31;
+ hash ^= m_ints[i];
}
return hash;
}