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-03 10:01:09 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-02-03 10:01:09 +0400
commit6f981bb85f37c11de90a165933849ec98fc06ee8 (patch)
tree5140ff6bab532ed4691cec33e4a0e3d3f13633d3 /core/src/main/java/org/bouncycastle/math
parent417df32e8a9c6cbcea220f81a59d690100087961 (diff)
Fix addOne, refactoring
Diffstat (limited to 'core/src/main/java/org/bouncycastle/math')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/Nat.java4
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP521R1Field.java11
2 files changed, 7 insertions, 8 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 7675af08..5a816c86 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/Nat.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/Nat.java
@@ -318,13 +318,13 @@ public abstract class Nat
return c << -bits;
}
- public static int shiftDownBitsExt(int len, int[] xx, int xxOff, int bits, int c, int[] z)
+ public static int shiftDownBits(int len, int[] x, int xOff, int bits, int c, int[] z)
{
// assert bits > 0 && bits < 32;
int i = len;
while (--i >= 0)
{
- int next = xx[xxOff + i];
+ int next = x[xOff + i];
z[i] = (next >>> bits) | (c << -bits);
c = next;
}
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 ec224ab4..2d3c6ffa 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
@@ -25,7 +25,7 @@ public class SecP521R1Field
public static void addOne(int[] x, int[] z)
{
System.arraycopy(x, 0, z, 0, 16);
- int c = Nat.inc(16, z, 0) + z[16];
+ int c = Nat.inc(16, z, 0) + x[16];
if (c > P16 || (c == P16 && Nat.eq(16, z, P)))
{
c += Nat.inc(16, z, 0);
@@ -46,9 +46,9 @@ public class SecP521R1Field
public static void half(int[] x, int[] z)
{
- int c0 = x[0] & 1, x16 = x[16], c512 = x16 & 1;
- Nat.shiftDownBit(16, x, c512, z);
- z[16] = (x16 >>> 1) | (c0 << 8);
+ int x16 = x[16];
+ int c = Nat.shiftDownBit(16, x, x16, z);
+ z[16] = (x16 >>> 1) | (c >>> 23);
}
public static void multiply(int[] x, int[] y, int[] z)
@@ -72,11 +72,10 @@ public class SecP521R1Field
public static void reduce(int[] xx, int[] z)
{
-// assert xx[33] == 0;
// assert xx[32] >>> 18 == 0;
int xx32 = xx[32];
- int c = Nat.shiftDownBitsExt(16, xx, 16, 9, xx32, z) >>> 23;
+ int c = Nat.shiftDownBits(16, xx, 16, 9, xx32, z) >>> 23;
c += xx32 >>> 9;
c += Nat.add(16, z, xx, z);
if (c > P16 || (c == P16 && Nat.eq(16, z, P)))