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-02-26 20:13:27 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-02-26 20:13:27 +0400
commit2c7db5b33dbd68a503684d66949e1d236150b3f5 (patch)
tree579e2f583aeee40eb51246c03d7c7acd43185bc0 /core/src/main/java/org/bouncycastle
parent9ebd198f1f9cf0274330475a50c249c03abc84a6 (diff)
Add extra arg to addWord() and add variant of copy()
Diffstat (limited to 'core/src/main/java/org/bouncycastle')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/Nat.java16
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP521R1Field.java4
2 files changed, 13 insertions, 7 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 40b6ebb3..2cf00c59 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/Nat.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/Nat.java
@@ -70,18 +70,19 @@ public abstract class Nat
return (int)c;
}
- public static int addWord(int len, int x, int[] z)
+ public static int addWord(int len, int x, int[] z, int zOff)
{
- long c = (x & M) + (z[0] & M);
- z[0] = (int)c;
+ // assert zOff < len;
+ long c = (x & M) + (z[zOff + 0] & M);
+ z[zOff + 0] = (int)c;
c >>>= 32;
- return c == 0 ? 0 : inc(len, z, 1);
+ return c == 0 ? 0 : inc(len, z, zOff + 1);
}
public static int addWordExt(int len, int x, int[] zz, int zzOff)
{
int extLen = len << 1;
- // assert zzOff <= (extLen - 1);
+ // assert zzOff < extLen;
long c = (x & M) + (zz[zzOff + 0] & M);
zz[zzOff + 0] = (int)c;
c >>>= 32;
@@ -95,6 +96,11 @@ public abstract class Nat
return z;
}
+ public static void copy(int len, int[] x, int[] z)
+ {
+ System.arraycopy(x, 0, z, 0, len);
+ }
+
public static int[] create(int len)
{
return new int[len];
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP521R1Field.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP521R1Field.java
index 5d0a0fd7..1608d406 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP521R1Field.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP521R1Field.java
@@ -24,7 +24,7 @@ public class SecP521R1Field
public static void addOne(int[] x, int[] z)
{
- System.arraycopy(x, 0, z, 0, 16);
+ Nat.copy(16, x, z);
int c = Nat.inc(16, z, 0) + x[16];
if (c > P16 || (c == P16 && Nat.eq(16, z, P)))
{
@@ -89,7 +89,7 @@ public class SecP521R1Field
public static void reduce23(int[] z)
{
int z16 = z[16];
- int c = Nat.addWord(16, z16 >>> 9, z) + (z16 & P16);
+ int c = Nat.addWord(16, z16 >>> 9, z, 0) + (z16 & P16);
if (c > P16 || (c == P16 && Nat.eq(16, z, P)))
{
c += Nat.inc(16, z, 0);